1. List<string> strColor = new List<string>();
  2. strColor.Add("#e67817");
  3. strColor.Add("#449284");
  4. strColor.Add("#974478");
  5. strColor.Add("#996666");
  6. strColor.Add("#ffcccc");
  7. strColor.Add("#999999");
  8. strColor.Add("#669966");
  9. strColor.Add("#cccc99");
  10. strColor.Add("#669999");
  11. strColor.Add("#cc3366");

if (list.Count >0)
                     {

  1. Button[] btn= new Button[list.Count];
  2. btn[] = new Button();
  3.  
  4. for (int i = ; i < list.Count; i++)
  5. {
  6. btn[i] = new Button();
  7. btn[i].Size = new Size(, );
  8. //btn[i].Text = list[i].Text; 设置按钮的text
  9. btn[i].ForeColor = Color.White;
  10. btn[i].Font = new Font("Tahoma", , FontStyle.Bold);
  11.  
  12. btn[i].BackColor = ColorTranslator.FromHtml(strColor[i]);
  13.  
  14. if (i >= )
  15. {
  16. if (i % == )
  17. {
  18. btn[i].Top = btn[i - ].Top + btn[i - ].Height + ;
  19. btn[i].Left = btn[].Left;
  20. }
  21. else {
  22. btn[i].Top = btn[i - ].Top;
  23. btn[i].Left = btn[i - ].Left+ btn[i - ].Width+; }
  24. }
  25. else {
  26. btn[i].Top = ;
  27. btn[i].Left = ;
  28. }
  29. btn[i].Visible = true;
  30. btn[i].Click += new EventHandler(BtnClick);//点击按钮触发事件
  31. this.Controls.Add(btn[i]);
  32. }

效果图:

winfrom_动态添加按钮button(设置颜色,大小,按钮字体大小、颜色,位置,事件)的更多相关文章

  1. 后台动态添加的button,如何触发button_click事件?

    后台动态添加的button,需要在Page_Load或者Page_Init重新动态生成才能执行button_click public Panel GetContrlType() { Panel pan ...

  2. iOS NSString 文本不同的颜色 标题+文本字体大小 行间距/删除不需要的字符 /以及自适应高度

    #import <Foundation/Foundation.h> @interface TextsForRow : NSObject @property(nonatomic,copy)N ...

  3. 【纯代码】Swift-自定义PickerView单选(可修改分割线颜色、修改字体大小、修改字体颜色。)(可根据需要自己扩展)

    typealias PopPickerViewCallBackClosure = (_ resultStr:NSString?) -> () class PopPickerView : UIVi ...

  4. IDEA设置Ctrl+滚轮调整字体大小

    IDEA设置Ctrl+滚轮调整字体大小(转载)   按Ctrl+Shift+A,出现搜索框 输入mouse: 点击打开这个设置:勾选 点击ok,之后就可以通过Ctrl+滚轮 调整字体大小了.

  5. iOS开发-- 设置UIButton的文字显示位置、字体的大小、字体的颜色

    btn.frame = CGRectMake(x, y, width, height); [btn setTitle: @"search" forState: UIControlS ...

  6. 设置UIButton的文字显示位置、字体的大小、字体的颜色

    btn.frame = CGRectMake(x, y, width, height); [btn setTitle: @"search" forState: UIControlS ...

  7. Eclipse设置:背景与字体大小和xml文件中字体大小调整

    Eclipse中代码编辑背景颜色修改:代码编辑界面默认颜色为白色.对于长期使用电脑编程的人来说,白色很刺激我们的眼睛,所以改变workspace的背景色,可以使眼睛舒服一些.设置方法如下:1.打开wi ...

  8. Eclipse设置:背景与字体大小、xml文件中字体大小调整和自动提示 SVN插件安装

    Eclipse中代码编辑背景颜色修改: 代码编辑界面默认颜色为白色.对于长期使用电脑编程的人来说,白色很刺激我们的眼睛,所以改变workspace的背景色,可以使眼睛舒服一些.设置方法如下: 1.打开 ...

  9. (备忘)Eclipse设置:背景与字体大小和xml文件中字体大小调整

    Eclipse中代码编辑背景颜色修改: 1.打开window / Preference,弹出Preference面板  2.展开General标签,选中Editors选项,展开.  3.选中 Text ...

  10. WebStorm设置编辑器中的字体大小

    启动webStorm之后,点击“FIle"菜单,选择其下的”Settings" 2.在左侧的菜单中选择“Editor/Colors & Fonts/Font 在右侧Sche ...

随机推荐

  1. 背包DP 方案数

    题目 1 P1832 A+B Problem(再升级) 题面描述 给定一个正整数n,求将其分解成若干个素数之和的方案总数. 题解 我们可以考虑背包DP实现 背包DP方案数板子题 f[ i ] = f[ ...

  2. css3实现jQuery的slideUp和slideDown效果

    最近打算做一些交互优化方面的轮子.虽然轮子别人都弄过,但是自己没弄过.重复造轮子对知识理解还是有好处的.本次轮子如题目.直接代码. <!DOCTYPE html> <html lan ...

  3. 慎用array_filter函数

    array_filter (PHP 4 >= 4.0.6, PHP 5, PHP 7) array_filter - 用回调函数过滤数组中的单元 说明 array array_filter (  ...

  4. linux下的什么工具能将DVI文件转换成PostScript文件?

    答: dvips,此工具能将由Latex或Tex生成的DVI文件转换成PostScript文件,官网在此

  5. Dart 语法中文在线学习网址收藏

    为了学习flutter UI框架,必须先学好dart语言,故收藏了有关 Dart 语法中文在线学习网址 http://dart.goodev.org/guides/language/language- ...

  6. seaweedfs文件存储服务器搭建

    官方网站: https://github.com/chrislusf/seaweedfs/wiki/Getting-Started 概述 seaweedfs是一个非常优秀的由 golang 开发的分布 ...

  7. pip install staty

    ERROR: Complete output from command python setup.py egg_info:ERROR: Traceback (most recent call last ...

  8. PostgreSQL 之 CREATE FUNCTION

    官方文档 语法: CREATE [ OR REPLACE ] FUNCTION name ( [ [ argmode ] [ argname ] argtype [ { DEFAULT | = } d ...

  9. [Python[Anaconda & PyTorch]] -- 使用conda 安装 Torch 出现错误 --Windows

    ... (⊙o⊙)… ... 当时具体的错误我没有截图, 用这个命令时 , conda 会报无法在源中找到PyTorch, 还是什么的错误 有很大的一个可能是, 安装的Anaconda 是32 位的, ...

  10. django 之(二) --- 源码分析

    CBV类视图继承 CBV:继承自View:注册的时候使用的as_view() 入口 不能使用请求方法的名字作为参数的名字 只能接受已经存在的属性对应的参数 定义了一个view 创建了一个类视图对象 保 ...