MetroTilePanel自动生成metroTileItem

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/lishk314/article/details/36625573

using DevComponents.DotNetBar.Metro;
using DevComponents.DotNetBar;
using System.Drawing;

public void ItemContainerBinding(ItemContainer ic, string sql, string strColumnName, string strColumnValue)
        {
            ic.Refresh();
            ic.SubItems.Clear();

            DataTable dt = new SQLHelper().DBDataTable(sql);//将查询出来的先放在DataTable
            if (dt.Rows.Count <= 0)
                return;

            MetroTileItem[] metroItem = new MetroTileItem[dt.Rows.Count];
            for (int i = 0; i < dt.Rows.Count; i++)//自动生成
            {
                metroItem[i] = new MetroTileItem();
                metroItem[i].Text = dt.Rows[i][strColumnName].ToString();
                if (strColumnValue != string.Empty)
                {
                    metroItem[i].Tag = dt.Rows[i][strColumnValue].ToString();
                }
                metroItem[i].TileStyle.TextAlignment = eStyleTextAlignment.Center;
                metroItem[i].TileStyle.TextAlignment = eStyleTextAlignment.Center;
                metroItem[i].TileStyle.BackColor2 = Color.Silver;
                metroItem[i].TileStyle.BackColor = Color.Silver;
                metroItem[i].Click += metroTileItem_Click;
                metroItem[i].TileSize = new System.Drawing.Size(100, 50);
            }
            ic.SubItems.AddRange(metroItem);
            ic.Refresh();
        }

        private void metroTileItem_Click(object sender, EventArgs e)
        {
            if (((MetroTileItem)sender).TileStyle.BackColor == Color.SkyBlue)
            {
                ((MetroTileItem)sender).TileStyle.BackColor = Color.Silver;
                ((MetroTileItem)sender).TileStyle.BackColor2 = Color.Silver;
            }
            else
            {
                ((MetroTileItem)sender).TileStyle.BackColor = Color.SkyBlue;
                ((MetroTileItem)sender).TileStyle.BackColor2 = Color.SkyBlue;
            }
        }





展开阅读全文

没有更多推荐了,返回首页