Moving toolbox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nime

    #1

    Moving toolbox

    Hello

    I made a toolbox like thing by using a panel with a label docked on top.
    I can move the toolbox by dragging on the label. I've coded it, VB6 style
    and got no problem. Then I tried to use new VB.NET way and now I'm stuck.
    If you examine Label1_MouseMov e event you'll see both methods.
    Can anybody fix it?

    To execute the code:
    1-) Add a panel: Panel1
    2-) Add a label into panel (Label1)
    Then run...

    ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' '''''''''
    Public Class Form1

    Private Structure MoveStructure
    Public MouseOffset As Point
    Public MouseDown As Boolean
    End Structure
    Private Move As MoveStructure

    Private Sub Label1_MouseDow n(ByVal sender As Object, ByVal e As System.Windows. Forms.MouseEven tArgs) Handles Label1.MouseDow n
    Move.MouseDown = True
    Move.MouseOffse t = New Point(e.X, e.Y)
    End Sub

    Private Sub Label1_MouseMov e(ByVal sender As Object, ByVal e As System.Windows. Forms.MouseEven tArgs) Handles Label1.MouseMov e


    If e.Button = Windows.Forms.M ouseButtons.Lef t Then
    If Not Move.MouseDown Then Exit Sub

    ''New way
    'Dim Dif As Point = New Point(e.X, e.Y)
    'Dif.Offset(Mov e.MouseOffset)
    'Panel1.Locatio n = Dif
    'Move.MouseOffs et = Dif
    'Exit Sub


    'Old way
    Dim DifX As Integer = Move.MouseOffse t.X - e.X
    Dim DifY As Integer = Move.MouseOffse t.Y - e.Y

    With Panel1
    .Top = .Top - DifY
    .Left = .Left - DifX
    End With


    End If
    End Sub

    Private Sub Form1_Load(ByVa l sender As Object, ByVal e As System.EventArg s) Handles Me.Load
    With Label1
    .AutoSize = False
    .BorderStyle = BorderStyle.Fix edSingle
    .BackColor = System.Drawing. SystemColors.Ac tiveCaption
    .ForeColor = System.Drawing. SystemColors.Ac tiveCaptionText
    .Dock = DockStyle.Top
    End With
    Panel1.BorderSt yle = BorderStyle.Fix edSingle
    End Sub
    End Class
    ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' '''''''''



  • gene kelley

    #2
    Re: Moving toolbox

    On Tue, 18 Jul 2006 19:14:15 +0300, "nime" <ea2005@planev. comwrote:
    >Hello
    >
    >I made a toolbox like thing by using a panel with a label docked on top.
    >I can move the toolbox by dragging on the label. I've coded it, VB6 style
    >and got no problem. Then I tried to use new VB.NET way and now I'm stuck.
    >If you examine Label1_MouseMov e event you'll see both methods.
    >Can anybody fix it?
    >
    >To execute the code:
    >1-) Add a panel: Panel1
    >2-) Add a label into panel (Label1)
    >Then run...
    >
    >'''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
    >Public Class Form1
    >
    Private Structure MoveStructure
    Public MouseOffset As Point
    Public MouseDown As Boolean
    End Structure
    Private Move As MoveStructure
    >
    Private Sub Label1_MouseDow n(ByVal sender As Object, ByVal e As System.Windows. Forms.MouseEven tArgs) Handles Label1.MouseDow n
    Move.MouseDown = True
    Move.MouseOffse t = New Point(e.X, e.Y)
    End Sub
    >
    Private Sub Label1_MouseMov e(ByVal sender As Object, ByVal e As System.Windows. Forms.MouseEven tArgs) Handles Label1.MouseMov e
    >
    >
    If e.Button = Windows.Forms.M ouseButtons.Lef t Then
    If Not Move.MouseDown Then Exit Sub
    >
    ''New way
    'Dim Dif As Point = New Point(e.X, e.Y)
    'Dif.Offset(Mov e.MouseOffset)
    'Panel1.Locatio n = Dif
    'Move.MouseOffs et = Dif
    'Exit Sub
    >
    >
    'Old way
    Dim DifX As Integer = Move.MouseOffse t.X - e.X
    Dim DifY As Integer = Move.MouseOffse t.Y - e.Y
    >
    With Panel1
    .Top = .Top - DifY
    .Left = .Left - DifX
    End With
    >
    >
    End If
    End Sub
    >
    Private Sub Form1_Load(ByVa l sender As Object, ByVal e As System.EventArg s) Handles Me.Load
    With Label1
    .AutoSize = False
    .BorderStyle = BorderStyle.Fix edSingle
    .BackColor = System.Drawing. SystemColors.Ac tiveCaption
    .ForeColor = System.Drawing. SystemColors.Ac tiveCaptionText
    .Dock = DockStyle.Top
    End With
    Panel1.BorderSt yle = BorderStyle.Fix edSingle
    End Sub
    >End Class
    >'''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''
    >
    >
    To simply move a panel via a top-docked label:

    Private StartPoint as Point


    Private Sub Label1_MouseDow n(ByVal sender As Object, ByVal e _
    As System.Windows. Forms.MouseEven tArgs) Handles Label1.MouseDow n
    StartPoint = New Point(e.X, e.Y)

    End Sub

    Private Sub Label1_MouseMov e(ByVal sender As Object, ByVal e _
    As System.Windows. Forms.MouseEven tArgs) Handles Label1.MouseMov e
    If e.Button = Windows.Forms.M ouseButtons.Lef t Then
    Dim mousePos As Point = New Point(e.X, e.Y)
    Panel1.Location = New Point(Panel1.Le ft + (mousePos.X - StartPoint.X), _
    Panel1.Top + (mousePos.Y - StartPoint.Y))

    End If

    End Sub


    You may want to expand the example to restrict Panel1 to the forms ClientRectangle .

    Gene

    Comment

    • nime

      #3
      Re: Moving toolbox

      That's what I did succesfully : )
      I just tried to use .Offset method instead of calculating a few things...




      Comment

      Working...