如何在嵌套按钮上方的TabPage中绘制图像 [英] How to draw an image in TabPage above nested Buttons

查看:99
本文介绍了如何在嵌套按钮上方的TabPage中绘制图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在tabPage重叠按钮上绘制图像



黑圈(在tabPage8_Paint上绘制图像)应位于按钮的上方





一些类级变量:

  Point iLoc = Point.Empty; 
图片img = null;
List< Button> overlaidButtons =新的List< Button>();

准备图像,图像的位置和可能覆盖的按钮列表:

  public Form1()
{
InitializeComponent();

字符串imgN = @ d:\scrape\gears\gear_12x4hand.png;
img = Image.FromFile(imgN);
iLoc = new Point(100,100);
overlaidButtons.AddRange(new [] {button10,button11,button12,button13});
//每个按钮调用相同的绘制事件
foreach(overlaidButtons中的按钮btn)btn.Paint + = btn_Paint;
}

常见的绘画事件。我们计算图像的相对位置。

  void btn_Paint(object sender,PaintEventArgs e)
{
Button btn =发送者为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);
}


How to draw image on tabPage overlapping buttons

Black circles(DrawImage on tabPage8_Paint) should be above the buttons:

http://rghost.ru/6sVBl8mkh/image.png

It must be so: http://rghost.ru/6BgDM77pq/image.png

My code

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);
}

解决方案

You can't draw above nested controls, so you need to draw parts of the image onto those Buttons.

So combine drawing onto the tabpage and drawing onto the buttons you need to adorn!

Here is a simple example using only one image:

A few class level variables:

Point iLoc = Point.Empty;
Image img = null;
List<Button> overlaidButtons = new List<Button>();

Prepare the image, its position and a list of possibly overlaid buttons:

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;
}

The common Paint event. We calculate the relative position of the image..

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));
}

Note that if the Buttons are nested deeper you need to adapt the calculation to include all levels of nesting!

The TabPage Paint event:

private void tabPage5_Paint(object sender, PaintEventArgs e)
{
    e.Graphics.DrawImage(img, iLoc);
}

这篇关于如何在嵌套按钮上方的TabPage中绘制图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆