Results 1 to 6 of 6

Thread: Move custom controls

  1. #1
    obrien.james is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.0 (VS 2005/2008)
    Join Date
    Sep 2009
    Posts
    15
    Reputation
    47

    Move custom controls

    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

  2. #2
    newguy's Avatar
    newguy is offline VB.NET Forum Idol
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Jun 2008
    Location
    Denver Co, USA
    Posts
    611
    Reputation
    250
    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>).
    Close Counts for Horseshoes, Handgranades, and Nuclear Missiles!

  3. #3
    obrien.james is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.0 (VS 2005/2008)
    Join Date
    Sep 2009
    Posts
    15
    Reputation
    47
    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

  4. #4
    newguy's Avatar
    newguy is offline VB.NET Forum Idol
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Jun 2008
    Location
    Denver Co, USA
    Posts
    611
    Reputation
    250
    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?
    Close Counts for Horseshoes, Handgranades, and Nuclear Missiles!

  5. #5
    obrien.james is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.0 (VS 2005/2008)
    Join Date
    Sep 2009
    Posts
    15
    Reputation
    47
    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.FrameDimensi on.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

  6. #6
    newguy's Avatar
    newguy is offline VB.NET Forum Idol
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Jun 2008
    Location
    Denver Co, USA
    Posts
    611
    Reputation
    250
    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.
    Close Counts for Horseshoes, Handgranades, and Nuclear Missiles!

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking