{Solved} Allow a user to move a control and right click

Post

Posted
Rating:
#1 (In Topic #1153)
Avatar
Enthusiast
sadams54 is in the usergroup ‘Enthusiast’
 I have 2 questions…

1.. is it possible to allow a user to drag a control around my program screen and allow the control to be moved there?

2.. If I put a right click or context menu on a group of controls how can I tell which control spawned the right click menu?
Online now: No Back to the top

Post

Posted
Rating:
#2
Regular
vuott is in the usergroup ‘Regular’

sadams54 said

1.. is it possible to allow a user to drag a control around my program screen and allow the control to be moved there?
If by "screen" you mean the Container, where the Control is located, you can simply use the "Drag&Drop":

Code (gambas)

  1. Public Sub Form_Open()
  2.  
  3.   Label1.Background = Color.Red
  4.  
  5.   Me.Drop = True
  6.    
  7.  
  8. Public Sub Label1_MouseDrag()
  9.  
  10.   Label1.Drag("")
  11.  
  12.  
  13. Public Sub Form_DragMove()
  14.  
  15. ' When moving the "Label", the mouse pointer remains at the point in the "Label" where you clicked:
  16.   With Label1
  17.     .X = Drag.X - Mouse.StartX
  18.     .Y = Drag.Y - Mouse.StartY
  19.    
Actually, you could drag a Control without the Drag&Drop…

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
Application.ActiveControl should do the job for detecting what control was last right-clicked to get a menu…

Code (gambas)

  1. Public Sub ContextMenu_Click()
  2.  
  3.   Select Application.ActiveControl.Name
  4.   Case "Button1"
  5.    Print "Button 1 clicked context menu"
  6.  
  7.  


To move controls…  (alternative)

Code (gambas)

  1. Public Sub MoveableControl_MouseMove()
  2.  
  3.   ' Last.X is controls current X pos , (Mouse.X - Mouse.StartX) gives the distance to move it keeping pointer at the controls click position.
  4.   Last.Move(Last.X + (Mouse.X - Mouse.StartX), Last.Y + (Mouse.Y - Mouse.StartY))
  5.  
  6.  
Note: you can only move controls if the parent container has Container.Arrangement = Arrange.None ,
If the container has Arrangement set it will try to place the controls itself and not let you do it.
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Guru
cogier is in the usergroup ‘Guru’
1.. is it possible to allow a user to drag a control around my program screen and allow the control to be moved there?

Here is some example code you can run in a Graphical Program that will show you how to do this.

2.. If I put a right click or context menu on a group of controls how can I tell which control spawned the right click menu?

I have added a menu so you can test this. The Last command will tell you what the control was. Look at the program Title as you click on each control.

Code (gambas)

  1. hPictureBox As PictureBox
  2. hMenu As Menu
  3.  
  4. Public Sub Form_Open()
  5.  
  6.   SetUpMenu
  7.   With Me
  8.     .W = 800
  9.     .H = 500
  10.     .Arrangement = Arrange.None
  11.     .Background = Color.Red
  12.  
  13.   For iLoop As Integer = 0 To 2
  14.     With hPictureBox = New PictureBox(Me) As "PictureBoxes"
  15.       .h = 128
  16.       .w = 128
  17.       .x = 20 + (iLoop * 150)
  18.       .y = 20 + (iLoop * 150)
  19.       .Name = "PictureBox" & Str(iLoop + 1)
  20.       .Picture = Picture["icon:/128/access"]
  21.       .mode = PictureBox.Contain
  22.       .PopupMenu = "hMenu"
  23.     End With
  24.   Next
  25.  
  26.  
  27. Public Sub SetUpMenu()
  28.  
  29.   Dim hMenuItem As Menu
  30.   Dim sTemp As String
  31.   Dim sMenuName As String[] = ["One", "Two"]
  32.  
  33.   hMenu = New Menu(Me) As "hMenu"
  34.   hMenu.Hide
  35.  
  36.   For Each sTemp In sMenuName
  37.     hMenuItem = New Menu(hMenu) As "MyMenu"
  38.     hMenuItem.text = sTemp
  39.   Next
  40.  
  41.  
  42. Public Sub PictureBoxes_MouseMove()
  43.  
  44.   Last.X += Mouse.ScreenX - Last.ScreenX - (Last.W / 2)
  45.   Last.Y += Mouse.ScreenY - Last.ScreenY - (Last.H / 2)
  46.  
  47.  
  48. Public Sub PictureBoxes_MouseDown()
  49.  
  50.   Me.Title = Last.Name
  51.  
  52.  
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Enthusiast
sadams54 is in the usergroup ‘Enthusiast’
thank you. I do not need the context menu since the drag option worked so perfectly. But everything was perfect and as always you guys are awesome.
Online now: No Back to the top

Post

Posted
Rating:
#6
Regular
vuott is in the usergroup ‘Regular’

vuott said

Actually, you could drag a Control without the Drag&Drop…
…infact cogier showed another way to move the Controls.

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Enthusiast
sadams54 is in the usergroup ‘Enthusiast’
yep, I used that alternate as it worked exactly as I wanted.
Online now: No Back to the top
1 guest and 0 members have just viewed this.