|
-
Oct 5th, 2011, 04:53 PM
#1
Re: Could someone help me correct my code trying to resize a panel?
Panels are going to cause you trouble, but trouble that you can readily fix. You will need to subclass it to get at the DoubleBuffered property and set it to true. Here's code that I use. Put this on the form, then go into the .designer.vb file for that form and find the references to the Panel and change them to FlickerPanel.
Code:
Private Class FlickerPanel
Inherits Windows.Forms.Panel
Public Sub New()
Me.DoubleBuffered = True
End Sub
End Class
I was having the same flickering problem, and this was the solution. A pretty simple class, though tinkering with the .designer.vb file may be something new for you.
After that comes the bit about the picturebox not keeping up with the cursor. There could be two problems here based on that description, but I think what you are describing is a problem with your coordinate system. All those events that have a location, such as the mouse events, give you that location in some coordinate system. I keep forgetting which coordinate system you get, but I suspect that e.x and e.y are relative to the picturebox, and you are using them in the panel. Put a breakpoint in one of those event handlers and take a look at the x and y. By putting the mouse near one corner, it should be readily apparent whether you are getting picturebox coordinates, panel coordinates, screen coordinates, or form coordinates (though a couple of those alternatives are absurd). Most likely, you will have to convert the coordinates to the proper system before you use them in your calculations. That could be awkward, as you might have to use the PictureBox.PointToScreen conversion to convert the coordinates from picturebox to screen coordinates, then the panel.PointToClient to convert the coordinates from screen to panel client coordinates.
My usual boring signature: Nothing
 
-
Oct 6th, 2011, 01:41 AM
#2
Re: Could someone help me correct my code trying to resize a panel?
 Originally Posted by Shaggy Hiker
Panels are going to cause you trouble, but trouble that you can readily fix. You will need to subclass it to get at the DoubleBuffered property and set it to true. Here's code that I use. Put this on the form, then go into the .designer.vb file for that form and find the references to the Panel and change them to FlickerPanel.
@RadXPictures: I agree with SH, but I would call it a NonFlickerPanel . An alternative to editing the designer.vb file is:
1. Delete the panel.
2. Build the solution. The new [Non]FlickerPanel tool appears in the Toolbox with a cogwheel icon.
3. Drag it onto the form the same way as a Panel or any other tool.
After that comes the bit about the picturebox not keeping up with the cursor. There could be two problems here based on that description, but I think what you are describing is a problem with your coordinate system. All those events that have a location, such as the mouse events, give you that location in some coordinate system. I keep forgetting which coordinate system you get, but I suspect that e.x and e.y are relative to the picturebox, and you are using them in the panel. Put a breakpoint in one of those event handlers and take a look at the x and y. By putting the mouse near one corner, it should be readily apparent whether you are getting picturebox coordinates, panel coordinates, screen coordinates, or form coordinates (though a couple of those alternatives are absurd). Most likely, you will have to convert the coordinates to the proper system before you use them in your calculations. That could be awkward, as you might have to use the PictureBox.PointToScreen conversion to convert the coordinates from picturebox to screen coordinates, then the panel.PointToClient to convert the coordinates from screen to panel client coordinates.
It can be easier than that. Just use MousePosition.X and MousePosition.Y everywhere instead of e.X and e.Y. That applies both to the MouseDown sub and the MouseMove sub. Explanation: MousePosition is relative to the screen, so it doesn't depend on which control fires the MouseMove event. Also, add some extra handlers to the handles clause of the MouseMove and MouseUp subs (but not MouseDown):
Code:
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles PictureBox1.MouseMove, Panel1.MouseMove, Me.MouseMove
That will make sure the MouseMove event still fires when the cursor slips out of picture box.
BB
Last edited by boops boops; Oct 6th, 2011 at 02:01 AM.
-
Oct 6th, 2011, 09:38 AM
#3
Re: Could someone help me correct my code trying to resize a panel?
 Originally Posted by boops boops
@RadXPictures: I agree with SH, but I would call it a NonFlickerPanel  .
That's a good point. My name is 180 degrees wrong.
Frankly, I prefer the designer.vb means of changing over the panel, but only because it is quicker if you know what you are doing, and well worth learning if you don't.
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|