最近想做一个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);
}
觉得应该不会那么复杂.能不能用图形编辑软件做一些图片直接加进去.请高手指点.
...全文
255 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
弘毅致远 2006-08-12
  • 打赏
  • 举报
回复
都要重画呀。那就是说我编辑好图片导进去后还得重载OnPaint函数才能显示么?
marvelstack 2006-08-12
  • 打赏
  • 举报
回复
一般都是要重新画的,
你在www.codeproject.com上找到例子。
skywolfma 2006-08-12
  • 打赏
  • 举报
回复
重写控件一般都是那么改的,你想不重写来用?控件不一定有那功能呢

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧