Move custom controls

obrien.james

Member
Joined
Sep 11, 2009
Messages
15
Programming Experience
Beginner
Hi,

I have a win form that has a panel control.

I load a tiff file and set it as the panel controls background image, and the measure the images size so that I can set the sroll bar parameters.

I the have button, which activate the drawing of a custom control, which issue the mousedown event to get the start location (top left) and the the mouse up event to get the end location (bottom right).

Using these variables I add a custom control to the panel which has had it's onpaint method overridden so that it's back color has an argb value of (125,255,255,0).

I'm the custom controls onouse move it make the control move it's top left settings by e.x and e.y etc...

When there is no background image in the panel the yellow box moves smoothly, but once I have a tiff file set to the panels background image the the is a terrible flicker as the custom control moves -- in the sense that the control cannot render as quick as I move the mouse. Thisis a problem as I want to useful e able to move the custom control smoothly - like when there is no image set for the panel background.

I have tried setting the forms double buffer to true and that does not help, neither do setting the customs control double buffer to true.

Any help will e greatly appreciated


James
 
Have you tried to invalidate just the usercontrol's region? In the mousemove you would make a new rectangle - that of the usercontrol's region, then inflate by 1, then call Invalidate(<thisNewRectangle>).
 
Hi newguy,

Thanks for the suggestion, and I will try that out. When I call the Invalidate(<the new rectange>) to i put that in the custom controls mouse move method?

thanks

james
 
When I set my panel's background image I don't get the flickering, but if I draw the image I do. Can we see more of your code?
 
Hi Newguy,

Sorry about the delay in the reply, below is the code that im using to load the image:


'open image file --> from opentwain
Dim imgFile As New IO.FileInfo(file)

If Not imgFile.Exists Then Return



Dim ImageFS As New System.IO.FileStream(file, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)
BaseImg = Image.FromStream(ImageFS)
CurrentPage = 1
NumberPages = BaseImg.GetFrameCount(Drawing.Imaging.FrameDimension.Page)

'Make image a bitmap
Dim sourcebitmap As New Bitmap(BaseImg)
Dim destbitmap As New Bitmap(sourcebitmap.Width, sourcebitmap.Height)
Dim destGraphic As Graphics = Graphics.FromImage(destbitmap)

destGraphic.DrawImage(sourcebitmap, 0, 0, destbitmap.Width + 1, destbitmap.Height + 1)

'set image as background

Panel1.AutoScrollMinSize = New Size(destbitmap.Width, destbitmap.Height)
Panel1.BackgroundImage = destbitmap


CurrentImg = destbitmap

I know that im drawing the image to a bitmap, but i edit the bitmap to zoom in and out. If there is a better more efficient way i would really appreciate your advice

James
 
When I draw a lot of graphics on controls I get the flickering effect, but if I draw these to a picturebox I do not. I am also not setting any graphics object to it's backgroundImage, just drawing them.
 
Back
Top