【发布时间】:2016-11-29 20:25:00
【问题描述】:
所以我制作了这个函数,它使用图片框和图像作为参数绘制一个“按钮”。该按钮应该在活动时为蓝色,在不活动时为灰色,但不知何故,当按钮应该处于非活动状态时,该功能会在按钮上绘制一条蓝线
如何去掉那条蓝线?
void DrawButton(PictureBox PIC, Image IMG)
{
using (Font myFont = new Font("Century Gothic", 11))
{
Bitmap bitmap = new Bitmap(IMG, PIC.Width, PIC.Height);
bitmap.MakeTransparent();
Graphics graph = Graphics.FromImage(bitmap);
// PIC.Tag is "Next"
graph.DrawString(PIC.Tag.ToString(), myFont, Brushes.White, new Point(42, 0));
PIC.Image = bitmap;
graph.Dispose();
}
}
以及我的函数的调用:
private void picNext_MouseLeave(object sender, EventArgs e)
{
if (_CURRENT_PAGE * 12 < DB.GetOnlinePlayers())
DrawButton(picNext, Properties.Resources.play_no_hover);
else DrawButton(picNext, Properties.Resources.play_no_active);
}
private void picNext_MouseUp(object sender, MouseEventArgs e)
{
if (_CURRENT_PAGE * 12 < DB.GetOnlinePlayers())
DrawButton(picNext, Properties.Resources.play_hover);
else DrawButton(picNext, Properties.Resources.play_no_active);
}
private void picNext_MouseDown(object sender, MouseEventArgs e)
{
if (_CURRENT_PAGE * 12 < DB.GetOnlinePlayers())
DrawButton(picNext, Properties.Resources.play_take);
else DrawButton(picNext, Properties.Resources.play_no_active);
}
private void picNext_MouseEnter(object sender, EventArgs e)
{
if (_CURRENT_PAGE * 12 < DB.GetOnlinePlayers())
DrawButton(picNext, Properties.Resources.play_hover);
else DrawButton(picNext, Properties.Resources.play_no_active);
}
【问题讨论】:
-
这就是所有的代码吗?如果是,您的
Properties.Resources.play_*资源如何? -
您的目标是什么:Winforms、WPF、ASP..? 始终正确标记您的问题!
-
@DirkVollmar 我添加了一张图片。
-
@TaW 我正在使用 Winforms
-
Pbox 的 BackgroundColor 是蓝色的吗?不要使用MakeTransparent!您可能只使用默认颜色 (LightGray) 透明制作了一条线。使用 graph.Clear(Color.Transparent) 创建一个空位图!
标签: c# image winforms button draw