How do you paint a DrawImage on tabPage, blocking the buttons?



  • How do you paint the image (DrawImage) on tabPage, closing the buttons?

    Black circles (DrawImage on tabPage8_Paint) should close the buttons

    I mean, I need you to do that.

    My code.

    Image ussdwait =
            global::SibModem.Properties.Resources.waitpl;
    

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

    }

    button4.SendToBack(); - with that button, they still close the image.



  • Method DrawImage draws directly on the control of the context Graphics♪ After the event is processed Paintthe rest of the controllers will be painted on the top, and you can't change the call order.

    You can imagine a painting in the context of sex paint and buttons are furniture. How many furniture down the top, no moving, it won't fall below the floor.

    You could add a transparent control over the button, but... We're approaching the second problem: WinForms is very abhorrently supporting transparency. In fact, transparency only exists for shapes (i.e. top-level windows), and with the counter-offers, it is sad. There's a WS_EX_TRANSPARENT style, but it's just making a control over the paint of all its rectangle, and the real transparency is not happening. I mean, if you add a transparent control over the top, one of them will come up with all the transparency, but neither move nor animate it will be okay. There's a hack, redefining control in every chikh.

    Like this. https://stackoverflow.com/a/434706/293099 :

    public class TransparentControl : Control
    {
        private readonly Timer _refresher;
        private Image _image;
    
    public TransparentControl ()
    {
        SetStyle(ControlStyles.SupportsTransparentBackColor, true);
        BackColor = Color.Transparent;
        _refresher = new Timer();
        _refresher.Tick += TimerOnTick;
        _refresher.Interval = 50;
        _refresher.Enabled = true;
        _refresher.Start();
    }
    
    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams cp = base.CreateParams;
            cp.ExStyle |= 0x20; // WS_EX_TRANSPARENT
            return cp;
        }
    }
    
    protected override void OnMove (EventArgs e)
    {
        RecreateHandle();
    }
    
    protected override void OnPaint (PaintEventArgs e)
    {
        if (_image != null) {
            e.Graphics.DrawImage(_image, (Width / 2) - (_image.Width / 2), (Height / 2) - (_image.Height / 2));
        }
    }
    
    protected override void OnPaintBackground (PaintEventArgs e)
    {
        //Do not paint background
    }
    
    //Hack
    public void Redraw ()
    {
        RecreateHandle();
    }
    
    private void TimerOnTick (object source, EventArgs e)
    {
        RecreateHandle();
        _refresher.Stop();
    }
    
    public Image Image
    {
        get
        {
            return _image;
        }
        set
        {
            _image = value;
            RecreateHandle();
        }
    }
    

    }

    In fact, you're supposed to be able to dance.

    There's still a full alpha-blanding for the daughter counters, but it only works from Windows 8 or so (I don't remember for sure), so the opportunity is useless for the moment.


    If you need a well-written interface with your own styles, look towards WPF. There's also transparency, and recycling works out of boxes, and there's no need for booths.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2