How to create a floating/resizable/movable dialog/form withoutflickering?

P

Polaris431

I want to create a floating dialog/window that when moved resembles
the way a MessageBox is moved. When you bring up a MessageBox and
click on the title and drag the MessageBox to a different location, a
frame (also known as border or rectangle) appears over the dimensions
of the MessageBox and while you drag the MessageBox, only this frame
moves while the content area of the frame is transparent.

I have looked up solutions for creating transparent controls but I
believe that this is the wrong solution. For starters, when a
MessageBox is moved, there is no flickering at all. This tells me that
the frame is probably not a control of any sorts, because if it were
it would require that the background be updated very quickly and this
does not appear possible using anything that inherits from a base
control.

I believe that the frame is being drawn as a rectangle on top of a
bitmap of the entire form (or entire screen) and that double buffering
must be used to eliminate flickering. In fact, I wouldn't be surprised
that only the grahic areas behind the actual frame lines are being
updated and nothing within the frame. This allows for the fastest
updating possible while the frame is being moved around.

So, it's possible that when a mouse down even is detected by the
MessageBox control on the title area, a snapshot of the entire form or
screen is taken and then a rectangle is drawn at the same location
where the MessageBox is located. When the user moves the mouse while
it is down, the code is effectively redrawing the frame on a different
location of the snapshot. Then again, maybe I am wrong. Perhaps the
drawing of this MessageBox is an internal piece of code that access
the drawing buffer of the device and simply just draws on it. If this
is so, I am not aware of whether there is an API that would allow me
to do the same. In other words, some API that simply says,
"DrawFrame".

Finally, I also want to be able to resize the dialog/form. A
MessageBox cannot be resized so I would obviously need to come up with
a radically new solution. And while resizing, it cannot flicker.

So my assumption here is that I will probably need to take a snapshot
myself and handle the the moving/resizing. Has anyone done this before
or at least know of an API that lets me take a snapshot of the entire
screen (or just the form) ?

Thank you
Johann
 
C

Christopher Fairbairn

Hi Johann,

Polaris431 said:
I want to create a floating dialog/window that when moved resembles
the way a MessageBox is moved.

You might be interested in a blog entry I made titled "Creating non full
screen forms and custom MessageBoxes". This is available at
http://www.christec.co.nz/blog/archives/134.

If you create a normal Form but set the FormBorderStyle property to None you
should be able to resize it to be non full screen in size.

The code sample available for download from my blog demonstrates a
MessageBox style replacement that uses this technique. It's not perfect but
it might give you a point in the right direction.

Hope this helps,
Christopher Fairbairn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top