I'm working on a project where I need the ability to load images into the program and drag them around, which means that they will have to be able to overlap. The program needs to be able to work with different image formats, such as jpg and png.
I started out using pictureboxes, which worked fine until I loaded a png with an alpha channel and for some, to me at least,Visual Studio's seems to handle transparency in a very odd way.
In this picture, the black and white flags are a png image, which from what I understand appears to have a white background, as it uses its parent backcolor, which in this case is Form1.
So what I can do is change its parent to the picture on the right and it will do this.
But this is where the issue occurs, as the flags are cut off by picturebox 2.
So as an alternative I used Graphics, drawimage to draw them on Form1 which allows me to drag them around the screen as well, by hooking them up to some small pictureboxes.
Now the flags can overlap all images using the correct alpha.
The issue with this is that when I drag them around I have to redraw them at the new position and use Me.Refresh() to clear the screen, but this causes them to flicker a lot.
Which is obviously really annoying. What can I do to fix it? Or am I approaching this all wrong, to begin with?
I'm quite new to VB so I have browsed the internet for answers, trying stuff that people have suggested, but from what I can see they are not really trying to achieve what I need, as they draw their stuff in fixed controls like panels etc. or they are trying to make drawing programs, where you have a canvas. But I need to be able to drag images around freely and place them on top of each other.
I have added these lines to Form1, which did nothing from what I can see:
Me.SetStyle(ControlStyles.UserPaint, True) Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True) Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True) Me.DoubleBuffered = True
I have tried to see if I could just refresh the region around the graphics being moved but again doesn't seem to really do anything.
I have tried moving the drawimage to the form1 paint event.
I have tried using panels, pictureboxes, labels and any other control that would allow me to add an image :D
Tried looking into the translate, but that leaves "ghosts" behind, which forces me to use the Me.refresh()