Koeneok 06-24-2002, 03:31 AM Hello,
I have a menu created like this:
rightmouse -- index = 0 -- visible = false
....test1 -- index = 0 -- visible = true
....test2 -- index = 0 -- visible = true
now i have made a loop where i load labels so something like:
for i 1 to 10
load lblName(i)
lblName.caption = "oke" & i
lblName.visible = true
lblName.top = i * 200
next
This will give me 10 labels. Now i want to make a popupmenu for this labels..... so something like this
for i 1 to 10
load rightmouse(i)
rightmouse.visible = false
load test1(i)
test1.visible = true
load test2(i)
test2.visible = true
next
Now i want to be able to click a item in the popupmenu and get the index.... (this index will be the same index as the label so i can do something like msgbox lblName(index).caption)....
When i use this code and right click i get:
Popup menu must have at least one submenu........
How do i fix this ?????
Koeneok 06-24-2002, 04:11 AM By the way... the form i working in is a MDI child...
Flyguy 06-24-2002, 04:34 AM Just to check whether I understand your question.
You start with this:
RightMouse(0)
SubItem(0)
And you want to create this:
' Menu structure to be created
RightMouse1
SubItem 1
SubItem 2
RightMouse 2
SubItem 1
SubItem 2
SubItem 3
RightMouse X
SubItem 1
SubItem 2
Koeneok 06-24-2002, 04:44 AM No... sorry.... i explane...
i have a dynamic list of labels.... lblName(0) lblName(1) lblName(2) etc.
now i want to make a right mouseclick menu (popupmenu) with 2 options so in design time it look like:
menu (visible = false)
.... del (visible = true)
.... edit (visible = true)
This has to be for all the labels like that, but when i click on a item i want to know which item in the menu (easy like del_onclick or edit_onclick) AND on which label ?? Index ?????
so like
private sub del_onclick()
????? how can i found out on which label i have right clicked ???
end sub
Banjo 06-24-2002, 05:01 AM You need to store x and y co-ords from the MouseDown event. Then from the menu click events you need to call a function to determine the label from the x,y values. Here is some code for the label finding function
Public Function FindLabelFromXY(ByVal x As Long, ByVal y As Long) As Label
Dim lbl As Label
For Each lbl In lblName
If x >= lbl.Left And x <= lbl.Left + lbl.Width And _
y >= lbl.Top And y <= lbl.Top + lbl.Height Then
Set FindLabelFromXY = lbl
End If
Next lbl
End Function
Koeneok 06-24-2002, 05:06 AM Sorry for asking....
but is that the only way ??
Flyguy 06-24-2002, 05:11 AM If you use the same index for the menu items and the label control array you could use the Index argument in mnuSubItem_Click() to be used as the index for the label array too.
Koeneok 06-24-2002, 05:11 AM Also a problem:...
when i create a popupmenu in my MDI child form, the menubar in the MDI form will hide.....??
How can i create a popupmenu in a MDI child without losing the menu in the MDI form..??
Banjo 06-24-2002, 05:12 AM As far as I can see. If you were using Textboxes you could use the Form.ActiveControl property but labels can not get focus and so can not be the active control.
Koeneok 06-24-2002, 05:14 AM for ArnoutV:
i don't understand ?? Maybe dutch is possible ??
Koeneok 06-24-2002, 05:18 AM When i try the example of Banjo like
Public Function FindLabelFromXY(ByVal x As Long, ByVal y As Long) As Label
i can't get the x and y from a popupmenu. ??
Banjo 06-24-2002, 06:17 AM You have to store them in the MouseDown event using a pair of form level variables.
Eg: Just below Option Explicit
Dim mouseX As Integer, mouseY As Integer
Then in the MouseDown event:
mouseX = x
mouseY = y
Squirm 06-24-2002, 06:40 AM Why not do this?
Dim lblCurrent As Label
Private Sub Label1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
'Store which label was clicked on
Set lblCurrent = Label1(Index)
'Popup the menu
PopupMenu MyMenu
End If
End Sub
Private Sub MySubMenu_Click()
'Do something with lblCurrent
MsgBox "You clicked on " & lblCurrent.Caption
End Sub
Koeneok 06-24-2002, 06:45 AM Well Thnx Squirm
i found it out myself, and when i want to post the answer here, i saw you have already post it. so....
the aswer is as Squirm posted it...
Thnx to you all for making time....
Koeneok 06-24-2002, 06:47 AM but now the other problem... (if you still got time)
why is my menu of the MDI form hidden when i open my MDI child form ??
Banjo 06-24-2002, 07:03 AM That's the way MDI works in VB. Sorry.
Koeneok 06-24-2002, 07:16 AM To Banjo:
i really don't understand??
I mean....
i have a MDI form with a menu created with the menu editor in design time.
i have a MDI child form with a menu (popupmenu) created with the menu editor in design time.
i want to have the menu in the MDI form to stay visible when i open the MDI child ??
Banjo 06-24-2002, 07:27 AM You can't. The child menu replaces the parent when it is selected. what you can do is duplicate the parent menu structure on the child. You will need to make the menu click events in the parent form public and then just call them from the child menu's click events.
Koeneok 06-24-2002, 08:12 AM Oke... i have got it all working now..
Thnx a lot
|