zoukankan      html  css  js  c++  java
  • 控制listview大图标之间的间距

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    using System.Runtime.InteropServices;
    using System.Collections;

    namespace FormTest
    {
        public partial class FormListView : Form
        {
            #region  IMPORT DLL
            // <summary>
            /// 控制ListView项之间的距离
            
    /// </summary>
            
    /// <param name="Handle"></param>
            
    /// <param name="wMsg"></param>
            
    /// <param name="wParam">水平间距</param>
            
    /// <param name="lParam">垂直间距</param>
            
    /// <returns></returns>
            [DllImport("User32.dll")]
            private static extern int SendMessage(IntPtr Handle, int wMsg, int wParam, int lParam);

            const int LVM_FIRST = 0x1000;
            const int LVM_SETICONSPACING = LVM_FIRST + 53;

            public static void SetListViewSpacing(ListView lst, int x, int y)
            {
                SendMessage(lst.Handle, LVM_SETICONSPACING, 0, x * 65536 + y);
            }

            #endregion


            /// <summary>
            
    /// 当前屏幕大小
            
    /// </summary>
            private int[] screenResolution = new int[] { 00 };
            protected List<ArrayList> lal = new List<ArrayList>();
            private string elevenName = "智能销售", appName = "应用程序", syncName = "更新任务", processName = "任务列表", helpName = "系统工具", downloadName = "活动资料";
            
            public FormListView()
            {
                InitializeComponent();
                int add = 1;

                this.listViewApp.Size = new Size(listViewApp.Size.Width * add, listViewApp.Size.Height * add);
                this.Width = this.Width * add;
                this.Height = this.Height * add;
                if (add.Equals(1))
                {
                    listViewApp.BackgroundImage = Resource_App.M3;
                }
                else
                {
                    listViewApp.BackgroundImage = Resource_App.MC75A;
                }
            }

            
            private void FormListView_Load(object sender, EventArgs e)
            {
                screenResolution = new int[] { listViewApp.Size.Width, listViewApp.Size.Height };
                
                //其中80控制行距,75控制列距
                if (screenResolution[0].Equals(240))
                {
                    SetListViewSpacing(listViewApp, 8075);
                    //SetBackgroundImage(listViewApp, Resource_App.M3);
                }
                else
                {
                    SetListViewSpacing(listViewApp, 160150);
                    //SetBackgroundImage(listViewApp, Resource_App.MC75A);
                }

                InitListView(listViewApp);
            }

            private void InitListView(ListView listView)
            {
                ArrayList al = new ArrayList();
                if (screenResolution[0].Equals(240))
                {
                    al.Add(Resource_App.MCMS_M3);
                    al.Add(elevenName);
                    lal.Add(al);
                    al = new ArrayList();
                    al.Add(Resource_App.App_M3);
                    al.Add(appName);
                    lal.Add(al);
                    al = new ArrayList();
                    al.Add(Resource_App.Sync_M3);
                    al.Add(syncName);
                    lal.Add(al);
                    al = new ArrayList();
                    al.Add(Resource_App.Process_M3);
                    al.Add(processName);
                    lal.Add(al);
                    al = new ArrayList();
                    al.Add(Resource_App.Help_M3);
                    al.Add(helpName);
                    lal.Add(al);
                    al = new ArrayList();
                    al.Add(Resource_App.Download_M3);
                    al.Add(downloadName);
                    lal.Add(al);
                    this.GetAppConfig(4848);//获得应用程序
                }
                else
                {
                    al.Add(Resource_App.MCMS_MC75A);
                    al.Add(elevenName);
                    lal.Add(al);
                    al = new ArrayList();
                    al.Add(Resource_App.App_MC75A);
                    al.Add(appName);
                    lal.Add(al);
                    al = new ArrayList();
                    al.Add(Resource_App.Sync_MC75A);
                    al.Add(syncName);
                    lal.Add(al);
                    al = new ArrayList();
                    al.Add(Resource_App.Process_MC75A);
                    al.Add(processName);
                    lal.Add(al);
                    al = new ArrayList();
                    al.Add(Resource_App.Help_MC75A);
                    al.Add(helpName);
                    lal.Add(al);
                    al = new ArrayList();
                    al.Add(Resource_App.Download_MC75A);
                    al.Add(downloadName);
                    lal.Add(al);
                    this.GetAppConfig(9092);//获得应用程序
                }
            }

            private void GetAppConfig(int w, int h)  //获得应用程序
            {

                listViewApp.Items.Clear();
                ImageList imgDefautIcon = new ImageList();
                imgDefautIcon.ImageSize = new Size(w, h);

                //增加图片

                for (int i = 0; i < lal.Count; i++)
                {
                    ListViewItem listview = new ListViewItem();
                    listview.Text = lal[i][1].ToString();
                    Bitmap b = (Bitmap)lal[i][0];
                    imgDefautIcon.Images.Add(b);
                    listview.BackColor = Color.FromArgb(105105105);
                    listview.ForeColor = Color.Black;
                    listview.ImageIndex = i;
                    listViewApp.Items.Add(listview);
                }
                listViewApp.LargeImageList = imgDefautIcon;
            }


            private void listViewApp_SelectedIndexChanged(object sender, EventArgs e)
            {
                if (this.listViewApp.SelectedIndices.Count > 0)
                {
                    int AppIdx = listViewApp.SelectedIndices[0];
                    onClick(AppIdx);
                }
            }

            private void onClick(int index)
            {
                if (index.Equals(0))
                {
                    picboxEleven_Click();
                }
                else if (index.Equals(1))
                {
                    picApp_Click();
                }
                else if (index.Equals(2))
                {
                    picboxSync_Click();
                }
                else if (index.Equals(3))
                {
                    picboxProcess_Click();
                }
                else if (index.Equals(4))
                {
                    picboxHelp_Click();
                }
                else if (index.Equals(5))
                {
                    picboxDownload_Click();
                }
            }

            private void picboxEleven_Click()
            {
                MessageBox.Show(elevenName);
            }

            private void picApp_Click()
            {
                MessageBox.Show(appName);
            }

            private void picboxSync_Click()
            {
                MessageBox.Show(syncName);
            }

            private void picboxProcess_Click()
            {
                MessageBox.Show(processName);
            }

            private void picboxHelp_Click()
            {
                MessageBox.Show(helpName);
            }

            private void picboxDownload_Click()
            {
                MessageBox.Show(downloadName);
            }
        }
    }
  • 相关阅读:
    spring mvc给参数起别名
    聊聊分布式定时任务中间件架构及其实现--转
    Batch Normalization的算法本质是在网络每一层的输入前增加一层BN层(也即归一化层),对数据进行归一化处理,然后再进入网络下一层,但是BN并不是简单的对数据进行求归一化,而是引入了两个参数λ和β去进行数据重构
    终端安全工具 gartner 排名
    When Cyber Security Meets Machine Learning 机器学习 安全分析 对于安全领域的总结很有用 看未来演进方向
    DNS隧道之DNS2TCP实现——dns2tcpc必须带server IP才可以,此外ssh可以穿过墙的,设置代理上网
    DNS隧道之DNS2TCP使用心得教程——是可以用来穿透qiang的,ubuntu下直接apt install dns2tcp
    DNS隧道工具汇总——补充,还有IP over DNS的工具NSTX、Iodine、DNSCat
    Data Mining and Machine Learning in Cybersecurity PDF
    ES failed to notify ClusterStateListener java.lang.IllegalStateException: environment is not locked
  • 原文地址:https://www.cnblogs.com/xsmhero/p/2725845.html
Copyright © 2011-2022 走看看