继承自BUTTOM
public partial class MButton : Button
{
static Bitmap bitmapNormal = Resources.btn_normal;
static Bitmap bitmapHeighHight = Resources.btn_heightlight;
static Bitmap bitmapFocus = Resources.btn_focus;
static Bitmap bitmapPush = Resources.btn_focus; private Bitmap bitmapBackGround = bitmapNormal;
[Browsable(true), Category("Local"), Description("默认显示图像")]
public Bitmap ImgBackGround
{
get { return bitmapBackGround; }
set
{
bitmapBackGround = value;
this.Invalidate();
}
} public MButton()
{
InitializeComponent();
} private Bitmap _imgNormal = bitmapNormal;
[Browsable(true), Category("Local"), Description("正常显示图像")]
public Bitmap ImgNormal
{
get { return _imgNormal; }
set { _imgNormal = value; this.Invalidate(); }
} private Bitmap _imgHeighLight = bitmapHeighHight;
[Browsable(true), Category("Local"), Description("高亮图像")]
public Bitmap ImgHeighLight
{
get { return _imgHeighLight; }
set { _imgHeighLight = value; this.Invalidate(); }
} private Bitmap _imgFocus = bitmapFocus;
[Browsable(true), Category("Local"), Description("聚焦图像")]
public Bitmap ImgFocus
{
get { return _imgFocus; }
set { _imgFocus = value; this.Invalidate(); }
} private Bitmap _imgPush = bitmapPush;
[Browsable(true), Category("Local"), Description("鼠标按下图像")]
public Bitmap ImgMouseDown
{
get { return _imgPush; }
set { _imgPush = value; this.Invalidate(); }
} #region
private string _Text;
[Browsable(true), Category("Local"), Description("Text")]
public string BtnText
{
get { return _Text; }
set { _Text = value; }
} private Font _TextFont = new Font("宋体", 9f);
[Browsable(true), Category("Local"), Description("Font")]
public Font TextFont
{
get { return _TextFont; }
set { _TextFont = value; }
} private Color _TextColor = Color.Black;
[Browsable(true), Category("Local"), Description("FontColor")]
public Color FontColor
{
get { return _TextColor; }
set { _TextColor = value; }
}
#endregion bool mousedown = false;
bool mouseUpDown = false;
private void MButton_MouseDown(object sender, MouseEventArgs e)
{
this.bitmapBackGround = _imgPush;
this.Invalidate();
mousedown = true;
mouseUpDown = true;
} private void MButton_MouseEnter(object sender, EventArgs e)
{
this.bitmapBackGround = _imgHeighLight;
this.Invalidate();
} private void MButton_MouseLeave(object sender, EventArgs e)
{
if (mousedown == false)
{
this.bitmapBackGround = _imgNormal;
this.Invalidate();
}
else
{
this.bitmapBackGround = _imgFocus;
this.Invalidate();
}
} private void MButton_MouseUp(object sender, MouseEventArgs e)
{
this.bitmapBackGround = _imgHeighLight;
this.Invalidate();
mouseUpDown = false;
} private void MButton_Leave(object sender, EventArgs e)
{
this.bitmapBackGround = _imgNormal;
this.Invalidate();
mousedown = false; } private void MButton_Enter(object sender, EventArgs e)
{
this.bitmapBackGround = _imgFocus;
this.Invalidate();
mousedown = true;
} private void MButton_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Bitmap tmpBitmap = new Bitmap(bitmapBackGround, this.Size);
g.DrawImage(tmpBitmap, new PointF(0, 0));
SizeF size = g.MeasureString(_Text, this.TextFont);
if (mouseUpDown == false)
{
g.DrawString(_Text, this.TextFont, new SolidBrush(_TextColor), new PointF((this.Width - size.Width) / 2, (this.Height - size.Height) / 2));
}
else if (mouseUpDown == true)
{
g.DrawString(_Text, this.TextFont, new SolidBrush(_TextColor), new PointF((this.Width + 2 - size.Width) / 2, (this.Height + 2 - size.Height) / 2));
} }
}将此按钮组件拖放在PANEL或者其它容器中,显示不出按钮的背景。只能显示文字如:mButton1!如何解决?什么情况引起的.啊?原来都会显示出来的!
解决方案 »
- 新手关于ado.net的问题
- 请教个winform的问题
- Thread.sleep 问题???
- 求助~~实现字符串的竖排,英文和数字可以竖排,但是中文有格式问题,没有乱码。代码在里面
- 【重要】求教一个随机配对的算法问题,要求效率要高,能够很快地处理万条左右数据。
- 難者不會,會者不難,請教各位高手一個簡單的從文件中取字串的問題。
- Windows服务
- 请教:MDI程序启动时要做一些初始化工作,开始运行的时候比较慢,想做一个启动窗体显示程序启动的进度,哪位有一个例子,让我学习学习?
- 【求助】C#调用OCX的一些问题
- C#怎么做界面风格啊?
- c# winfrom treeview实时刷新
- c#中多线程访问网页出现竞技状态或者死锁的问题
static Bitmap bitmapHeighHight = Resources.btn_heightlight;
static Bitmap bitmapFocus = Resources.btn_focus;
static Bitmap bitmapPush = Resources.btn_focus; 这是申明的图片。后被赋值于背景。