Page 2 of 2 FirstFirst 12
Results 41 to 60 of 60

Thread: [RESOLVED] [2005] Stamped. ToolTip and MoveIt.

  1. #41
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [RESOLVED] [2005] Stamped. ToolTip and MoveIt.

    You need to handle the drag-and-drop-related events of the controls on the Panel too.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  2. #42

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: [RESOLVED] [2005] Stamped. ToolTip and MoveIt.

    Yes Indeed but how?
    I add the panels dynamically. They are not there static like the form.

  3. #43

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: [RESOLVED] [2005] Stamped. ToolTip and MoveIt.

    I have tried the code below but It doesnt do it.
    Neither do i think it carries some logic.
    VB Code:
    1. Friend WithEvents pnl As System.Windows.Forms.Panel
    2.  
    3.     Private Sub Addlabel()
    4.         lbl = New Label
    5.         pnl.Controls.Add(lbl)
    6.         AddHandler lbl.MouseDown, AddressOf lableEventHandler
    7.         lbl.Location = New Point(24, 21)
    8.         lbl.Size = New Size(111, 98)
    9.         pnl.AllowDrop = True
    10.         lbl.Text = Me.RichTextBox1.Text
    11.  
    12.     End Sub
    13.  
    14.     Private Sub lblDragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles pnl.DragDrop
    15.         If e.Data.GetDataPresent(GetType(Label)) Then
    16.             lbl = DirectCast(e.Data.GetData(GetType(Label)), Label)
    17.         End If
    18.     End Sub
    19.  
    20.     Private Sub lblDragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles pnl.DragEnter
    21.         If e.Data.GetDataPresent(GetType(Label)) Then
    22.             e.Effect = DragDropEffects.Move
    23.         Else
    24.             e.Effect = DragDropEffects.None
    25.         End If
    26.     End Sub
    27.  
    28.     Private Sub lableEventHandler(ByVal sender As Object, ByVal eMap As System.Windows.Forms.MouseEventArgs)
    29.         lbl = CType(sender, Label)
    30.         lbl.DoDragDrop(lbl, DragDropEffects.Move)
    31.     End Sub
    Last edited by maps; Sep 21st, 2006 at 06:59 AM.

  4. #44

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: [RESOLVED] [2005] Stamped. ToolTip and MoveIt.

    My problem here is that, if we handle the drag-and-drop-related events of the controls on the Panel, we will be like we are dragging the controls over the panel and not in relation to the mainform.

    I was thinking that instead of using a panel, i would simply use a label it-self, but the main constraint i see is that i cant easily set the margins for the text.

    What do you think!

  5. #45
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [RESOLVED] [2005] Stamped. ToolTip and MoveIt.

    I think it doesn't matter what object you are over when the MouseDown event is raised. If you pass the Panel to the first argument of DoDragDrop then it's the Panel that you'll be dragging and it's the Panel that will be returned to you from e.Data when the DragDrop event is raised. At that point what control you originally moused down on is immaterial and forgotten.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #46

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: [RESOLVED] [2005] Stamped. ToolTip and MoveIt.

    What am i getting wrong with this?
    VB Code:
    1. Private Sub Addlabel()
    2.         lbl = New Label
    3.         pnl.Controls.Add(lbl)
    4.         AddHandler lbl.MouseDown, AddressOf lableEventHandler
    5.         lbl.Location = New Point(24, 21)
    6.         lbl.Size = New Size(111, 98)
    7.         'pnl.AllowDrop = True
    8.         lbl.Text = Me.RichTextBox1.Text
    9.  
    10.     End Sub
    11.     'DragDrop event for the control where the drop will occur, use the GetData method to retrieve the data being dragged
    12.     Private Sub lblDragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop
    13.         If e.Data.GetDataPresent(GetType(Panel)) Then
    14.             pnl = DirectCast(e.Data.GetData(GetType(Panel)), Panel)
    15.         End If
    16.     End Sub
    17.  
    18.     Private Sub lblDragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragEnter
    19.         'Ensure that the data being dragged is of an acceptable type (in this case, Panel).
    20.         If e.Data.GetDataPresent(GetType(Panel)) Then
    21.             e.Effect = DragDropEffects.Move
    22.         Else
    23.             e.Effect = DragDropEffects.None
    24.         End If
    25.     End Sub
    26.  
    27.     Private Sub lableEventHandler(ByVal sender As Object, ByVal eMap As System.Windows.Forms.MouseEventArgs)
    28.         lbl = CType(sender, Label)
    29.         'Begin drag operation,data to be dragged is the lbl
    30.         lbl.DoDragDrop(lbl, DragDropEffects.Move)
    31.     End Sub

  7. #47
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [RESOLVED] [2005] Stamped. ToolTip and MoveIt.

    Again, you need to pass the Panel to the first argument of DoDragDrop. You're passing the Label.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #48

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: [RESOLVED] [2005] Stamped. ToolTip and MoveIt.

    so i have remained with this below and the form's DragDrop and DragEnter Events, but when the mouse move is on the label, the panel moves far away to the right past the point of drop and past the screen area.

    VB Code:
    1. Private Sub Addlabel()
    2.         lbl = New Label
    3.         pnl.Controls.Add(lbl)
    4.         AddHandler lbl.MouseDown, AddressOf lableEventHandler
    5.         lbl.Location = New Point(24, 21)
    6.         lbl.Size = New Size(111, 98)
    7.         'pnl.AllowDrop = True
    8.         lbl.Text = Me.RichTextBox1.Text
    9.  
    10.     End Sub
    11.  
    12.     Private Sub lableEventHandler(ByVal sender As Object, ByVal eMap As System.Windows.Forms.MouseEventArgs)
    13.         lbl = CType(sender, Label)
    14.         'Begin drag operation,data to be dragged is the lbl
    15.         pnl.DoDragDrop(pnl, DragDropEffects.Move)
    16.     End Sub
    Last edited by maps; Sep 22nd, 2006 at 03:03 AM.

  9. #49

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: [RESOLVED] [2005] Stamped. ToolTip and MoveIt.

    Its Okay. I got it. I needed to set the drag start point in that eventhandler for the label.
    All i can say is thanks JMC. You will always be in the comments of my code.

  10. #50
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [RESOLVED] [2005] Stamped. ToolTip and MoveIt.

    Make good use of the PointToClient and PointToScreen methods to convert coordinates from one controls coordinate system to amother.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #51

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: [RESOLVED] [2005] Stamped. ToolTip and MoveIt.

    Thanks JMC, and its time to give the project back to the forum.
    Although it still has one more issue:
    -->When You have one panel on the screen, every thing works fine and its ok.
    But when you have more than one,say two(panel1 and panel2) and you move one panel
    (say panel1) with the mouse over the label, it will move fine, but if the mouse is
    shifted to Panel2 and at the point where the the label is on panel2, then a drag is
    made, it will move panel1 to the point of drop instead of panel2.
    Any Idea To Fix that will be highly appreciated.

    I will look into PointToClient and PointToScreen and see how i can go about it.
    Attached Files Attached Files

  12. #52

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: [RESOLVED] [2005] Stamped. ToolTip and MoveIt.

    JMC. Lets finish this. I have used PointScreen and it has helped me and now i can even be able to resize the panel but i have failed to solve the above problem.
    Any Idea how i can solve it?

  13. #53
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [RESOLVED] [2005] Stamped. ToolTip and MoveIt.

    As I've said numerous times, whatever you pass to the first argument of DoDragDrop is what you get back from the e.Data property in the DragDrop event. If your code is moving the wrong Panel then it must be getting the wrong Panel from the e.Data property, which means that you must be passing the wrong Panel to DoDragDrop in the first place. Pass the correct Panel to the DoDragDrop method and you'll get the right Panel back at the end, thus you'll move the correct Panel. The Panels are parented by the form and the Labels are parented by the Panels. You can use a single MouseDown event handler for every Panel and every Label and use that general relationship like so:
    VB Code:
    1. Dim ctl As Control = DirectCast(sender, Control)
    2.  
    3. While ctl IsNot Me
    4.     ctl = ctl.Parent
    5. End While
    Now you've got a reference to the Panel that was either clicked itself, or contains the control that was clicked, so you simply pass 'ctl' to DoDragDrop and you'll get the correct Panel back when it coms time to actually move it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  14. #54

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: [RESOLVED] [2005] Stamped. ToolTip and MoveIt.

    Still not coming.
    This is what i have.
    VB Code:
    1. Private ctrl As Control
    2.  
    3. Private Sub MyEventHandler(ByVal sender As Object, ByVal eMap As System.Windows.Forms.MouseEventArgs)
    4.         Dim m_pt As New Point()
    5.         'cast object into a panel
    6.         pnl = CType(sender, Panel)
    7.         'get the location point of the Panel(sender) we are copying
    8.         'get the point of click on the panel
    9.         m_pt.X = pnl.PointToScreen(New Point(eMap.X, eMap.Y)).X
    10.         m_pt.Y = pnl.PointToScreen(New Point(eMap.X, eMap.Y)).Y - 20
    11.         If eMap.Button = System.Windows.Forms.MouseButtons.Right Then
    12.             cmnuDrawPanel.Enabled = False
    13.             cmnuRemovePanel.Enabled = True
    14.             'Locate/Show the context menu, just below that label point
    15.             Me.ContextMenuStrip1.Show(Me, m_pt)
    16.         End If
    17.  
    18.         'get the start point of the label we are tryinng to drag, then start dragging the label
    19.         Me.dragStartPoint = pnl.PointToScreen(New Point(eMap.X, eMap.Y))
    20.         'You Only Want To Drag The Panel If The User Clicks The Left Mouse Button
    21.         If eMap.Button = Windows.Forms.MouseButtons.Left Then
    22.             'Begin drag operation,sets the drag object to be the pnl
    23.             ctrl.DoDragDrop(pnl, DragDropEffects.Move)
    24.         End If
    25.  
    26.     End Sub
    27.     Private Sub lableEventHandler(ByVal lblSender As Object, ByVal eMap2 As System.Windows.Forms.MouseEventArgs)
    28.         lbl = CType(lblSender, Label)
    29.         Dim lbl_pt As New Point
    30.         'get that point on the label
    31.         lbl_pt.X = New Point(eMap2.X, eMap2.Y).X + 25
    32.         lbl_pt.Y = New Point(eMap2.X, eMap2.Y).Y + 20
    33.  
    34.         If eMap2.Button = System.Windows.Forms.MouseButtons.Right Then
    35.             cmnuDrawPanel.Enabled = False
    36.             cmnuRemovePanel.Enabled = True
    37.             'Locate/Show the context menu, just below that label point
    38.             Me.ContextMenuStrip1.Show(pnl, lbl_pt)
    39.         End If
    40.  
    41.         Me.dragStartPoint = pnl.PointToScreen(New Point(eMap2.X, eMap2.Y))
    42.  
    43.         'You Only Want To Drag The Panel If The User Clicks The Left Mouse Button
    44.         If eMap2.Button = Windows.Forms.MouseButtons.Left Then
    45.             'Begin drag operation,sets the drag object to be the pnl
    46.             ctrl.DoDragDrop(pnl, DragDropEffects.Move)
    47.         End If
    48.  
    49.     End Sub
    50.  
    51. Private Sub pnl_Lbl_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles pnl.MouseDown, lbl.MouseDown
    52.         ctrl = DirectCast(sender, Control)
    53.  
    54.         While ctrl IsNot Me
    55.             ctrl = ctrl.Parent
    56.         End While
    57.     End Sub

  15. #55
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [RESOLVED] [2005] Stamped. ToolTip and MoveIt.

    Oops, I left out a little bit in that last code example that you should have picked up on. Also, you're making that more complex than is necessary. The following is not a complete solution as it omits the middle parts of the drag and drop operation, thus I haven't tested it but it is a simple way to start and end the operation. It may need some tweaking because, as I said, I haven't actually tested it.
    VB Code:
    1. Public Class Form1
    2.  
    3.     Private Structure DragData
    4.  
    5.         ''' <summary>
    6.         ''' The control being dragged.
    7.         ''' </summary>
    8.         Public DraggedControl As Control
    9.         ''' <summary>
    10.         ''' The point from which the control was dragged in screen coordinates.
    11.         ''' </summary>
    12.         Public DragOrigin As Point
    13.  
    14.     End Structure
    15.  
    16.     'This method should handle the MouseDown event for every Panel and every Label.
    17.     Private Sub DragableControl_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
    18.         'Get a reference to the control that the mouse button was depressed over.
    19.         Dim ctl As Control = DirectCast(sender, Control)
    20.  
    21.         'Get a reference to the Panel that the mouse button was depressed over.
    22.         While ctl.Parent IsNot Me
    23.             ctl = ctl.Parent
    24.         End While
    25.  
    26.         Dim data As DragData
    27.  
    28.         data.DraggedControl = ctl
    29.         data.DragOrigin = Windows.Forms.Cursor.Position
    30.  
    31.         ctl.DoDragDrop(data, DragDropEffects.Move)
    32.     End Sub
    33.  
    34.     'This method should handle the DragDrop event for every control that can be dropped on, which basically means everything.
    35.     Private Sub DropTarget_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
    36.         Dim data As DragData = DirectCast(e.Data.GetData(GetType(DragData)), DragData)
    37.  
    38.         Dim draggedControl As Control = data.DraggedControl
    39.         Dim dragOrigin As Point = data.DragOrigin
    40.         Dim currentMouseLocation As Point = Windows.Forms.Cursor.Position
    41.  
    42.         'Calculate the distance in each direction the control has been dragged.
    43.         Dim deltaX As Integer = currentMouseLocation.X - dragOrigin.X
    44.         Dim deltaY As Integer = currentMouseLocation.Y - dragOrigin.Y
    45.  
    46.         'Move the control that distance.
    47.         Dim newLocation As Point = New Point(draggedControl.Left + deltaX, draggedControl.Top + deltaY)
    48.  
    49.         draggedControl.Location = newLocation
    50.     End Sub
    51.  
    52. End Class
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  16. #56

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: [RESOLVED] [2005] Stamped. ToolTip and MoveIt.

    Phew....Urrgh!!! I have tried it and its like breaking the house 3/4 way to rebuild it again!.
    JMC,Thanks for your response but i cant get to do the above in the attached project! i am getting everything screwed up....and getting more confused. i know this is simpler than how it seems to be complex.
    If you would spend some time, Please look through the attached project and see how i can fit this in and repost it. I will be more than glad.

  17. #57

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: [RESOLVED] [2005] Stamped. ToolTip and MoveIt.

    JMC, according to what you have told me to do, this is what i have....With a single MouseDown event handler for every Panel and every Label.

    Check out my new features while dragging and resizing too.
    Attached Files Attached Files
    Last edited by maps; Sep 25th, 2006 at 04:01 AM.

  18. #58

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: [RESOLVED] [2005] Stamped. ToolTip and MoveIt.

    JMC, I followed up your method and it works. Ive posted the newUpdate in the above Post. Except that it disorganises my custom movecursor and my resizer.

    For The Custom Cursor:
    When More Than One Panel Is On The Form And I shift the Mouse from one Panel To Another for a mouse drag. My SizeAll Cursor Does Not Show Immediately Not Until Click To Drag The Panel Again
    For The Resizer:
    If i have more than one Panel,the Reiser doesnt See Which Panel Is it Belongs To Even When You Click On The Panel.It only works the newly added panel.

    ***EDIT***
    Toview the resizer, click on the panel. But this will only happen when you click on the newly added panel on the form.
    Last edited by maps; Sep 25th, 2006 at 04:13 AM.

  19. #59

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: [RESOLVED] [2005] Stamped. ToolTip and MoveIt.

    Got It. Just needed to leave "ctrl" as a class variable, i had redefined it somewhere else. But the Resizer problem is still on.

  20. #60

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: [RESOLVED] [2005] Stamped. ToolTip and MoveIt.

    JMC,back again.
    On the form that i create/draw the panels. I have labels on it pre-added from another form. I can be able to draw my "Stationery ToolTip" only when the mouse is not pointed on the a label there. How can i get it to show up even when the mouse is pointed on the label.
    The main point here is that i want to use the text in the label to be the criteria for the information to show on the tooltip. If the pointer is pointed just on the mere part of the form, no information should show up in the Panel.

    I thought it would take the same scenario of the labels added on the panel and i just call the event handler...but alas. No Luck.

    ***EDITS***
    Another thing is that when i move my panel and it moves over the label on the form, the Panel and the triangle region always fall below the label, so the label is always on top if the panel or trangle sa-passes through it.
    I tried to use SendToBack and BringTofront when adding both the panel and the labels and am i had ZERO luck! Any Idea how i can do away with this?
    Last edited by maps; Oct 4th, 2006 at 05:41 AM.

Page 2 of 2 FirstFirst 12

Posting Permissions

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



Click Here to Expand Forum to Full Width