AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

Display button (transparent) on VideoSourcePlayer

Forum to discuss AForge.NET Framework, its features, API, how-tos, etc.

Display button (transparent) on VideoSourcePlayer

Postby dall » Fri Aug 09, 2019 4:23 pm

I want to display a button with transparent background (currently in a PictureBox) on the VideoSourcePlayer control like so:

screenshot.png
Screenshot of button on VideoSourcePlayer
screenshot.png (37.94 KiB) Viewed 121 times

I can't get the button to be shown as transparent. I set up the PictureBoxes BackgroundColor to Color.Transparent and added the box to the player's list of controls. Trying to set the player's back color to transparent failed with an exception (not supported). If the player was another PictureBox it would have worked.

Any more ideas on what to try?
Thanks!
dall
 
Posts: 2
Joined: Fri Aug 09, 2019 4:10 pm

Re: Display button (transparent) on VideoSourcePlayer

Postby andrew.kirillov » Fri Aug 09, 2019 9:10 pm

Just make a custom drawing control and do whatever you would like (writing your code for drawing).

Any AForge.NET specific question ?
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3427
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Display button (transparent) on VideoSourcePlayer

Postby dall » Mon Aug 12, 2019 10:43 am

Hi,
thanks, did some more googling about that, tried it and it worked. Thought it was a VideoSourcePlayer related problem. I find the way WinForms is handling transparency very confusing.

I used this approach:
https://social.msdn.microsoft.com/Forum ... m=winforms

My class:
Code: Select all
public class TransparentPictureBox : Control
{
    private Timer refresher;
    private Image _image = null;
    private Image resizedImage = null;


    public TransparentPictureBox()
    {
        this.Cursor = Cursors.Hand;

        refresher = new Timer();
        refresher.Tick += new EventHandler(this.TimerOnTick);
        refresher.Interval = 50;
        refresher.Start();
    }


    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams cp = base.CreateParams;
            cp.ExStyle |= 0x20;
            return cp;
        }
    }


    protected override void OnResize(EventArgs e)
    {
        base.OnResize(e);

        if (_image != null)
            SetResizedImage();
    }


    private void SetResizedImage()
    {
        if (this._image != null)
        {
            if (resizedImage != null)
                resizedImage.Dispose();
            int newHeight = Helper.CalculateHeightForTargetWidth(_image.Size, this.Width);
            resizedImage = new Bitmap(_image, this.Width, newHeight);
        }
    }


    protected override void OnMove(EventArgs e)
    {
        base.RecreateHandle();
    }


    protected override void OnPaint(PaintEventArgs e)
    {
        if (resizedImage != null)
            e.Graphics.DrawImage(resizedImage, new Point(0, 0));
    }

    protected override void OnPaintBackground(PaintEventArgs e)
    {
    }


    private void TimerOnTick(object source, EventArgs e)
    {
        base.RecreateHandle();
        refresher.Stop();
    }


    public Image Image
    {
        get
        {
            return _image;
        }
        set
        {
            _image = value;
            base.RecreateHandle();
        }
    }
}
dall
 
Posts: 2
Joined: Fri Aug 09, 2019 4:10 pm




Return to AForge.NET Framework