teamdad Posted August 7, 2004 Posted August 7, 2004 Greetings.... This code lets me move "slide" a panel but it will let you pull it all the way off the forms edge or all the way back into itself and either case it just disapears. It needs to have a way to set a limit like a form has MaximumSize and MinimumSize type limits. Any thoughts on an easy way to get this to work on my panel? Maybe like if the panel is moved to a certian point that it stops moving or something. :-\ Dim _mouseDown As Boolean = False Private Sub Panel1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove If _mouseDown = True Then Panel1.Width = e.X Else If e.X >= Panel1.Width - 3 Then Panel1.Cursor = Cursors.VSplit Else Panel1.Cursor = Me.Cursor End If End If End Sub Private Sub Panel1_MouseDown(ByVal sender As Object, _ ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown _mouseDown = True Panel1.Cursor = Cursors.VSplit End Sub Private Sub Panel1_MouseUp(ByVal sender As Object, _ ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseUp _mouseDown = False Panel1.Cursor = Me.Cursor End Sub Quote
JABE Posted August 7, 2004 Posted August 7, 2004 Try this: Private _canDrag As Boolean, _oldX As Integer Private Const MIN_SIZE As Integer = 150 Private Const MAX_SIZE As Integer = 250 Private Sub Panel1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove If e.Button = MouseButtons.Left Then If _canDrag Then If Panel1.Width < MIN_SIZE AndAlso e.X < _oldX Then '-No op. ElseIf Panel1.Width > MAX_SIZE AndAlso e.X > _oldX Then '-No op. Else Panel1.Width = e.X End If End If Else If e.X >= Panel1.Width - 3 Then Panel1.Cursor = Cursors.VSplit _canDrag = True _oldX = e.X Else Panel1.Cursor = Me.Cursor _canDrag = False End If End If End Sub Of course, MIN_SIZE and MAX_SIZE can be dynamically computed. Note the absence of the MouseUp and MouseDown code; e.Button = MouseButtons.Left will suffice in MouseMove. Quote
Joe Mamma Posted August 7, 2004 Posted August 7, 2004 I think you might want to consider using the splitter and or a combination of splitters. . . you didnt have them in vb. poor, poor vb!!! to get started, try this New form Drop a Panel1 - Dock: Bottom Drop a TextBox1 on panel1 - MultiLine, Dock: Fill Drop a splitter1 on form - Dock: Bottom Drop a panel2 on form - Dock: left Drop a TextBox2 on panel2 - MultiLine, Dock: Fill Drop a Splitter2 on form - Dock: Left Drop a panel3 on form - Dock: Fill Drop a TextBox3 on panel3 - MultiLine, Dock: Fill You shouldn't have to worry about control extents, make the controls work for you Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.