码迷,mamicode.com
首页 > Windows程序 > 详细

winform 控件开发1——复合控件

时间:2014-09-29 20:59:01      阅读:339      评论:0      收藏:0      [点我收藏+]

标签:winform   style   blog   http   color   io   os   ar   for   

bubuko.com,布布扣bubuko.com,布布扣哈哈是不是丑死了?

做了一个不停变色的按钮,可以通过勾选checkbox停下来,代码如下:

复合控件果然简单呀,我都能学会~

 

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Diagnostics;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Threading.Tasks;
 9 using System.Windows.Forms;
10 namespace ComponentComposite
11 {
12     [ToolboxBitmap(typeof(Timer))]
13     public partial class Component1:UserControl
14     {
15         private Color _colFColor;
16         private Color _colBColor;
17         public Color colFColor { get { return _colFColor; } set { _colFColor = value; checkBox1.ForeColor = _colFColor; } }
18         public Color colBColor { get { return _colBColor; } set { _colBColor = value; checkBox1.BackColor = _colBColor; } }
19         public Component1()
20         {
21             InitializeComponent();
22         }
23 
24         public Component1(IContainer container)
25         {
26             container.Add(this);
27 
28             InitializeComponent();
29         }
30 
31         private void timer1_Tick(object sender, EventArgs e)
32         {   Random rdm=new Random();
33             int i1=rdm.Next(0,255);int i2=rdm.Next(0,255);int i3=rdm.Next(0,255);
34             button1.BackColor = System.Drawing.Color.FromArgb(i1, i2, i3);
35         }
36 
37         private void checkBox1_CheckedChanged(object sender, EventArgs e)
38         {
39             timer1.Enabled = (timer1.Enabled)?false:true;
40         }
41     }
42 }

上午跟人家学了一个渐变按钮,bubuko.com,布布扣

如图,现在试试可不可以组合。嗯可以组合,但是好像不是自动变化颜色的呀

 

winform 控件开发1——复合控件

标签:winform   style   blog   http   color   io   os   ar   for   

原文地址:http://www.cnblogs.com/jin-wen-xin/p/4000679.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!