我建议你自己写空间,继承自己带的控件. 给你个自己定义 的控件的代码,希望对你有帮助. public class MyButton : System.Windows.Forms.Button { private Color m_color1 = Color.LightGreen; //first color private Color m_color2 = Color.DarkBlue; //second color private int m_color1Transparent = 64; //transparency degree (applies to the 1st color) private int m_color2Transparent = 64; //transparency degree (applies to the 2nd color) public Color cuteColor1 { get { return m_color1; } set { m_color1 = value; Invalidate(); } } public Color cuteColor2 { get { return m_color2; } set { m_color2 = value; Invalidate(); } } public int cuteTransparent1 { get { return m_color1Transparent; } set { m_color1Transparent = value; Invalidate(); } } public int cuteTransparent2 { get { return m_color2Transparent; } set { m_color2Transparent = value; Invalidate(); } } public cuteButton() { } protected override void OnPaint(PaintEventArgs pe) { // Calling the base class OnPaint base.OnPaint(pe); // Create two semi-transparent colors Color c1 = Color.FromArgb (m_color1Transparent , m_color1); Color c2 = Color.FromArgb (m_color2Transparent , m_color2); Brush b = new System.Drawing.Drawing2D.LinearGradientBrush (ClientRectangle, c1, c2, 10); pe.Graphics.FillRectangle (b, ClientRectangle); b.Dispose(); }}
给你个自己定义 的控件的代码,希望对你有帮助.
public class MyButton : System.Windows.Forms.Button
{
private Color m_color1 = Color.LightGreen; //first color
private Color m_color2 = Color.DarkBlue; //second color
private int m_color1Transparent = 64; //transparency degree (applies to the 1st color)
private int m_color2Transparent = 64; //transparency degree (applies to the 2nd color) public Color cuteColor1
{
get { return m_color1; }
set { m_color1 = value; Invalidate(); }
} public Color cuteColor2
{
get { return m_color2; }
set { m_color2 = value; Invalidate(); }
} public int cuteTransparent1
{
get { return m_color1Transparent; }
set { m_color1Transparent = value; Invalidate(); }
} public int cuteTransparent2
{
get { return m_color2Transparent; }
set { m_color2Transparent = value; Invalidate(); }
}
public cuteButton()
{ } protected override void OnPaint(PaintEventArgs pe)
{
// Calling the base class OnPaint
base.OnPaint(pe);
// Create two semi-transparent colors
Color c1 = Color.FromArgb
(m_color1Transparent , m_color1);
Color c2 = Color.FromArgb
(m_color2Transparent , m_color2);
Brush b = new System.Drawing.Drawing2D.LinearGradientBrush
(ClientRectangle, c1, c2, 10);
pe.Graphics.FillRectangle (b, ClientRectangle);
b.Dispose();
}}
???
我的意思不是更改属性,
而是添加了这个控件后它的属性本来就不和原来的控件一样.
to:zhuohs(凌九霄) (
你好,我照你的方法写了一个,可是提示说不能运行啊,
怎么办?
这个只是一个类,怎么能运行呢?
我懂了,
调用dll文件..
谢谢