哈哈是不是丑死了?
做了一个不停变色的按钮,可以通过勾选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 }
上午跟人家学了一个渐变按钮,
如图,现在试试可不可以组合。嗯可以组合,但是好像不是自动变化颜色的呀