winfrom_动态添加按钮button(设置颜色,大小,按钮字体大小、颜色,位置,事件)
2024-09-13 10:43:14
List<string> strColor = new List<string>();
strColor.Add("#e67817");
strColor.Add("#449284");
strColor.Add("#974478");
strColor.Add("#996666");
strColor.Add("#ffcccc");
strColor.Add("#999999");
strColor.Add("#669966");
strColor.Add("#cccc99");
strColor.Add("#669999");
strColor.Add("#cc3366");
if (list.Count >0)
{
Button[] btn= new Button[list.Count];
btn[] = new Button(); for (int i = ; i < list.Count; i++)
{
btn[i] = new Button();
btn[i].Size = new Size(, );
//btn[i].Text = list[i].Text; 设置按钮的text
btn[i].ForeColor = Color.White;
btn[i].Font = new Font("Tahoma", , FontStyle.Bold); btn[i].BackColor = ColorTranslator.FromHtml(strColor[i]); if (i >= )
{
if (i % == )
{
btn[i].Top = btn[i - ].Top + btn[i - ].Height + ;
btn[i].Left = btn[].Left;
}
else {
btn[i].Top = btn[i - ].Top;
btn[i].Left = btn[i - ].Left+ btn[i - ].Width+; }
}
else {
btn[i].Top = ;
btn[i].Left = ;
}
btn[i].Visible = true;
btn[i].Click += new EventHandler(BtnClick);//点击按钮触发事件
this.Controls.Add(btn[i]);
}
效果图:
最新文章
- MySQL每天自动增加分区
- C# 实现软件的重启
- 网络存储技术(3) based on zt
- [原创]推荐一款强大的.NET程序内存分析工具.NET Memory Profiler
- Objective-C 高级编程:iOS与OS X多线程和内存管理
- 1.6建造者模式(生成器模式) Builder
- Android_Dialog
- Linux系统编程(35)—— socket编程之TCP服务器的并发处理
- Ecstore的微信账号绑定会员免登录
- bzoj1336: [Balkan2002]Alien最小圆覆盖
- python模块 ---logging模块
- docker工作流程
- Mybatis if test 中int判断非空的坑
- 瞎捣鼓的code highlight
- CentOS7.2重置root密码的处理方法
- 2019CVTE技术支持软件编程2
- webpack学习笔记(五)
- Android:layout属性大全
- 【python】pip安装报错UnicodeDecodeError: &#39;ascii&#39; codec can&#39;t decode byte 0xc4 in position 7: ordinal not in range(128)
- ECLIPSE 导入外部文件或源码包
热门文章
- 感知机算法及BP神经网络
- 【SVN】彻底 svn 服务器上的 删除某一个文件或文件夹
- web开发的三层架构
- VBA 格式化excel数据表 (数据分列)
- protobuf ubuntu 18.04环境下安装
- 阶段5 3.微服务项目【学成在线】_day04 页面静态化_18-页面静态化-模板管理-GridFS研究-取文件
- Oracle关联删除的几种方式
- Python实现按照指定要求逆序输出一个数字的方法
- 【ARTS】01_28_左耳听风-201900520~201900526
- dlopen, dlsym今天才刚知道干什么用的,羞死人了