最近想做一个MP3播放功能的小程序.想给控件加上图标不知道是怎么做的....请大虾指点
弘毅致远 2006-08-12 02:04:30 看到很多程序的外观都是很漂亮的.不是IDE提供的默认控件界面.于是我也想给控件加上些图标,看起来爽点.首先直接做了一些PNG格式的小图标加上去,在IDE中看得出图标,但编译后就看不见了....只见光光的按钮.后来我就用系统自带的画图软件编辑过后再保存为BMP格式,(因为怕是格式方面不支持)再导入,结果还是一样.在网上找了一下,有关资料是重载ONPAINT方法来做的..
protected override void OnPaint(PaintEventArgs e)
{
if(this.pressed && this.pressedImage != null)
e.Graphics.DrawImage(this.pressedImage, 0, 0);
else
e.Graphics.DrawImage(this.backgroundImage, 0, 0);
// Draw the text if there is any.
if(this.Text.Length > 0)
{
SizeF size = e.Graphics.MeasureString(this.Text, this.Font);
// Center the text inside the client area of the PictureButton.
e.Graphics.DrawString(this.Text,
this.Font,
new SolidBrush(this.ForeColor),
(this.ClientSize.Width - size.Width) / 2,
(this.ClientSize.Height - size.Height) / 2);
}
// Draw a border around the outside of the control to look like regular
// PPC buttons.
e.Graphics.DrawRectangle(new Pen(Color.Black), 0, 0,
this.ClientSize.Width - 1, this.ClientSize.Height - 1);
base.OnPaint(e);
}
觉得应该不会那么复杂.能不能用图形编辑软件做一些图片直接加进去.请高手指点.