How do you use true transparency in .Net (VB)?

Zac Mckraken 25 Reputation points
2023-05-08T10:53:45.71+00:00

I have been trying to make a program in VB where several images need to be overlapped and dragged around the screen, I have tried using a PictureBox and a panel. However, when using a PNG with transparency, it does not seem to work correctly.

Pic_1

It simply shows the background rather than being transparent and showing the pictures below.

I can make the "flag" a child of one of the pictures which will result in this:

pic_2

But this cuts off the flags, so that won't work.

Alternatively, I tried using Graphics to draw the images. This solves the problem of transparency so it looks as it should.

Drawimage

But this requires me to redraw the images every time they are dragged, which causes a lot of flickering.

I don't need to manipulate the images or anything, simply to be able to load them and drag them around. Is there really no easy way to do that in Visual Studio? or am I forced to use DirectX or some other means of doing this, because it kind of feels like shooting flies with cannons?

It seems like a very strange way Visual Studio handles transparency in general and have a difficult time understanding why anyone would ever choose to use a transparent image and then not want it to be truly transparent.

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,568 questions
{count} votes

Accepted answer
  1. Castorix31 81,636 Reputation points
    2023-05-10T21:46:28.87+00:00

    I just uploaded a simple class from UserControl, to be improved : https://github.com/castorix/VB_TransparentControl

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful