网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

C#中怎么使用Winform动态生成控件

C#中怎么使用Winform动态生成控件,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

十载的博山网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整博山建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联公司从事“博山网站设计”,“博山网站推广”以来,每个客户项目都认真落实执行。

实现方式

1、加载数据,往panel添加Label 控件。

private void LoadRoomType()         {             DataTable dtRoomType = _roomTypeBLL.GetModelList("", "Code");             pnlRoomType.Controls.Clear();             int padding = 5;             int x = padding, y = padding;             pnlRoom.Controls.Clear();             foreach (DataRow item in dtRoomType.Rows)             {                 Label lbl = new Label();                 lbl.Text = string.Format("{0}", item["Names"]);                 lbl.Image = btnRoomType.Image;                 lbl.Cursor = Cursors.IBeam;                 lbl.TextAlign = btnRoomType.TextAlign;                 lbl.Font = btnRoomType.Font;                 lbl.ForeColor = btnRoomType.ForeColor;                 lbl.Size = btnRoomType.Size;                 lbl.Location = new Point(x, y);                 lbl.Tag = item;                 lbl.Click += new EventHandler(lbl_Click);                 lbl.MouseEnter += new EventHandler(lbl_MouseEnter);                 lbl.MouseLeave += new EventHandler(lbl_MouseLeave);                 x += lbl.Width + padding;                 if (x + lbl.Width > pnlRoomType.Width)                 {                     x = padding;                     y += lbl.Height + padding;                 }                 pnlRoomType.Controls.Add(lbl);             }             int height = y + (x != padding ? pnlRoomType.Height : 0) + padding;             int addHeight = height - pnlRoomType.Height;             pnlRoom.Top = pnlRoom.Top + addHeight;             pnlRoom.Height = pnlRoom.Height - addHeight;             pnlRoomType.Height = pnlRoomType.Height + addHeight;             if (dtRoomType.Rows.Count > 0)                 LoadRoomByTypeID(dtRoomType.Rows[0], 0);         }

2、定义Label 的点击事件。

void lbl_Click(object sender, EventArgs e)         {             try             {                 Label lbl = sender as Label;                 DataRow row = lbl.Tag as DataRow;                 LoadRoomByTypeID(row, 0);                             }             catch (Exception ex)             {                 ;             }          }

3、定义Label 的鼠标事件。

#region lbl_MouseLeave         void lbl_MouseLeave(object sender, EventArgs e)         {             Label lbl = sender as Label;             lbl.Font = new Font(lbl.Font, FontStyle.Regular);             lbl.Cursor = Cursors.Default;             lbl.ForeColor = btnRoomType.ForeColor;         }         #endregion         #region lbl_MouseEnter         void lbl_MouseEnter(object sender, EventArgs e)         {             Label lbl = sender as Label;             lbl.Font = new  Font(lbl.Font, FontStyle.Bold);             lbl.Cursor = Cursors.IBeam;         }         #endregion

看完上述内容,你们掌握C#中怎么使用Winform动态生成控件的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!


文章题目:C#中怎么使用Winform动态生成控件
浏览路径:http://bjjierui.cn/article/jpoigd.html

其他资讯