为什么组件突然不能在VS2008里显示按钮图片了呢?求高手指点!
继承自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!如何解决?什么情况引起的.啊?原来都会显示出来的! --------------------编程问答-------------------- 你设置背景图片了吗 --------------------编程问答-------------------- 当然 设置了。看代码static Bitmap bitmapNormal = Resources.btn_normal;
static Bitmap bitmapHeighHight = Resources.btn_heightlight;
static Bitmap bitmapFocus = Resources.btn_focus;
static Bitmap bitmapPush = Resources.btn_focus; 这是申明的图片。后被赋值于背景。
补充:.NET技术 , C#