首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

关于C#中ListView控件Item图标大小的有关问题

2013-09-28 
求教:关于C#中ListView控件Item图标大小的问题是最近的一个项目,需要做一些修改,其中就是ListView中Item的

求教:关于C#中ListView控件Item图标大小的问题
是最近的一个项目,需要做一些修改,其中就是ListView中Item的图表需要改大一点。其实图表本身的大小是32×32的,图中的图标远小于其实际尺寸,不知为何,而且图标也没有显示完全。这点感觉没有MFC中的ListCtrl好用。

下面附上代码,希望有人能够给点指导,怎样才能让图标显示其正常尺寸。

关于C#中ListView控件Item图标大小的有关问题

//设置ListView中Item的间距,引入相关的动态链接库
        [DllImport("User32.dll")]
        //声明需要用到的消息发送函数
        private static extern int SendMessage(int Handle, int wMsg, int wParam, int lParam);
        //需要用到的相关参数
        const int LVM_FIRST = 0x1000;
        const int LVM_SETICONSPACING = LVM_FIRST + 53;
        //动态库中的系统函数,用来设置ListView控件中Item的间距
        public static void SetListViewItemSpacing(ListView lst, int x, int y)
        {
            SendMessage(lst.Handle.ToInt32(), LVM_SETICONSPACING, 0, y * 65536 + x);
        }

        //窗体构造函数
        public FormOperate()
        {
            InitializeComponent();
        }

        //串口初始化函数
        private int InitComm()
        {
            serialPort1.PortName = "COM9";
            serialPort1.BaudRate = 38400;
            serialPort1.DataBits = 8;
            serialPort1.StopBits = StopBits.One;
            serialPort1.Parity = Parity.None;
            serialPort1.Handshake = Handshake.None;
            return 0;
        }

        //网络接收初始化函数
        private bool InitSocket()
        {
            IPEndPoint e = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 6000);
            UdpClient u = new UdpClient(e);
            m_udpState.u = u;
            u.BeginReceive(new AsyncCallback(ReceiveCallback), m_udpState);
            return true;
        }

        //异步接收的回调函数,网络数据的处理
        public void ReceiveCallback(IAsyncResult ar)
        {
            UdpClient u = (UdpClient)((UdpState)(ar.AsyncState)).u;

            Byte[] receiveBytes = u.EndReceive(ar, ref m_udpState.e);
            u.BeginReceive(new AsyncCallback(ReceiveCallback), ar.AsyncState);//重新开启异步接收
            //接收到的位置序列分列到AB各自的序列
            byte[] posListA = new byte[128];
            byte[] posListB = new byte[128];
            int posListCountA = 0, posListCountB = 0;
            m_recipelCountTotal = receiveBytes.Length;
            for (int i = 0; i < receiveBytes.Length; i++)
            {
                if (receiveBytes[i] >= 0)
                {
                    posListA[posListCountA++] = receiveBytes[i];
                }
                else
                {


                    posListB[posListCountB++] = (byte)(receiveBytes[i] - 128);
                }
            }

            //把AB位置序列发送出去
            serialPort1.ReceivedBytesThreshold = 1;
            serialPort1.Write(posListA, 0, posListCountA);
            System.Threading.Thread.Sleep(300);
            serialPort1.ReceivedBytesThreshold = 1;
            serialPort1.Write(posListB, 0, posListCountB);
        }

        //窗口载入时完成的工作
        private void FormOperate_Load(object sender, EventArgs e)
        {
            listView1.LargeImageList = imageList1;
            for (int i = 0; i < 128; i++)
            {
                SetListViewItemSpacing(listView1, 42, 64);
                listView1.Items.Add(i.ToString(), 1);
            }
            for (int i = 0; i < 24; i++)
            {
                listView1.Items.Add(i.ToString(), 1);
            }

            listView2.LargeImageList = imageList1;
            for (int i = 0; i < 128; i++)
            {
                SetListViewItemSpacing(listView2, 42, 64);
                listView2.Items.Add(i.ToString(), 1);
            }
            for (int i = 0; i < 24; i++)
            {
                listView2.Items.Add(i.ToString(), 1);
            }

            InitSocket();

            InitComm();

            serialPort1.Open();
            byte[] sendBuf = new byte[5];
            sendBuf[0] = 0xda;
            sendBuf[1] = 0xdd;
            sendBuf[2] = 0x02;
            sendBuf[3] = 0x01;
            sendBuf[4] = 0x00;
            serialPort1.Write(sendBuf, 0, 5);
            System.Threading.Thread.Sleep(500);
            sendBuf[3] = 0x02;
            serialPort1.Write(sendBuf, 0, 5);
        } 控件 listview c#
[解决办法]
imageList1里面的图标决定了显示在ListView上的图标的大小。
------解决方案--------------------


仔细找找应该有设置大小的属性。
[解决办法]

引用:
imageList1里面的图标决定了显示在ListView上的图标的大小。


说的没错, ImageList的属性,修改图片的宽和高.就可以了.

热点排行