如何在嵌套按钮上方的 TabPage 中绘制图像
How to draw an image in TabPage above nested Buttons
如何在 tabPage 重叠按钮上绘制图像
黑色圆圈(tabPage8_Paint 上的 DrawImage)应该 在 按钮上方:
http://rghost.ru/6sVBl8mkh/image.png
一定是这样:
http://rghost.ru/6BgDM77pq/image.png
我的代码
public SibModem() {
InitializeComponent();
tabPage8.Paint += new PaintEventHandler(tabPage8_Paint);
gettime();
this.SizeChanged += new EventHandler(this.SibModem_Resize);
}
protected void tabPage8_Paint(object sender, PaintEventArgs e) {
GraphicsUnit units = GraphicsUnit.Pixel;
base.OnPaint(e);
Graphics g = e.Graphics;
g.DrawImage(bg, 0, 0);
Rectangle srcRect = new Rectangle(offsetant, 0, w, h);
g.DrawImage(anten, x, y, srcRect, units);
Rectangle ussdwaitRect = new Rectangle(offsetussd, 0, 64, 64);
g.DrawImage(ussdwait, usx, usy, ussdwaitRect, units);
}
试试 BringToFront 方法,它将控件带到 z 顺序的前面。
请参阅 MSDN 上的参考资料:https://msdn.microsoft.com/en-us/library/system.windows.forms.control.bringtofront(v=vs.110).aspx
您无法在上方 嵌套控件上绘制,因此您需要将图像的一部分绘制到 那些按钮上。
所以结合绘图到标签页和绘图到按钮你需要装饰!
这是一个仅使用一张图片的简单示例:
几个class级变量:
Point iLoc = Point.Empty;
Image img = null;
List<Button> overlaidButtons = new List<Button>();
准备图像、图像的位置和可能重叠的按钮列表:
public Form1()
{
InitializeComponent();
string imgN = @"d:\scrape\gears\gear_12x4hand.png";
img = Image.FromFile(imgN);
iLoc = new Point(100, 100);
overlaidButtons.AddRange(new []{button10,button11,button12,button13 });
// each button calls the same paint event
foreach (Button btn in overlaidButtons) btn.Paint += btn_Paint;
}
常见的 Paint
事件。我们计算图片的相对位置..
void btn_Paint(object sender, PaintEventArgs e)
{
Button btn = sender as Button;
e.Graphics.DrawImage(img, new Point(iLoc.X - btn.Left, iLoc.Y - btn.Top));
}
请注意,如果 Buttons
嵌套得更深,您需要调整计算以包括所有级别的嵌套!
TabPage Paint
事件:
private void tabPage5_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawImage(img, iLoc);
}
如何在 tabPage 重叠按钮上绘制图像
黑色圆圈(tabPage8_Paint 上的 DrawImage)应该 在 按钮上方:
http://rghost.ru/6sVBl8mkh/image.png
一定是这样: http://rghost.ru/6BgDM77pq/image.png
我的代码
public SibModem() {
InitializeComponent();
tabPage8.Paint += new PaintEventHandler(tabPage8_Paint);
gettime();
this.SizeChanged += new EventHandler(this.SibModem_Resize);
}
protected void tabPage8_Paint(object sender, PaintEventArgs e) {
GraphicsUnit units = GraphicsUnit.Pixel;
base.OnPaint(e);
Graphics g = e.Graphics;
g.DrawImage(bg, 0, 0);
Rectangle srcRect = new Rectangle(offsetant, 0, w, h);
g.DrawImage(anten, x, y, srcRect, units);
Rectangle ussdwaitRect = new Rectangle(offsetussd, 0, 64, 64);
g.DrawImage(ussdwait, usx, usy, ussdwaitRect, units);
}
试试 BringToFront 方法,它将控件带到 z 顺序的前面。
请参阅 MSDN 上的参考资料:https://msdn.microsoft.com/en-us/library/system.windows.forms.control.bringtofront(v=vs.110).aspx
您无法在上方 嵌套控件上绘制,因此您需要将图像的一部分绘制到 那些按钮上。
所以结合绘图到标签页和绘图到按钮你需要装饰!
这是一个仅使用一张图片的简单示例:
几个class级变量:
Point iLoc = Point.Empty;
Image img = null;
List<Button> overlaidButtons = new List<Button>();
准备图像、图像的位置和可能重叠的按钮列表:
public Form1()
{
InitializeComponent();
string imgN = @"d:\scrape\gears\gear_12x4hand.png";
img = Image.FromFile(imgN);
iLoc = new Point(100, 100);
overlaidButtons.AddRange(new []{button10,button11,button12,button13 });
// each button calls the same paint event
foreach (Button btn in overlaidButtons) btn.Paint += btn_Paint;
}
常见的 Paint
事件。我们计算图片的相对位置..
void btn_Paint(object sender, PaintEventArgs e)
{
Button btn = sender as Button;
e.Graphics.DrawImage(img, new Point(iLoc.X - btn.Left, iLoc.Y - btn.Top));
}
请注意,如果 Buttons
嵌套得更深,您需要调整计算以包括所有级别的嵌套!
TabPage Paint
事件:
private void tabPage5_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawImage(img, iLoc);
}