偶今天做了个程序啊,我想说一下,比如我有5个按钮啊,针对做不同的事啊,!这个就不说了我有个菜单啊,就是我鼠标如果在那个按钮那里右建点一下就出来一个菜单让人选择啊里面有个我想实现的功能是,“重命名啊”就是重命令这个按钮的名字啊,这个看起来并不糟糕,可是问题我做了一下,出来了,菜单不是说每个按钮都不同的,每个按钮都是调用同一个菜单的,所以,如果我现在比如选择了第二个按钮吧,那么我选择了“重命名“,那么怎么重命名后只针对我们点季的按钮起作用呢,而不对别的按钮有干扰,有什么的,我想不通,主要问题是菜单条只有一个,5个按钮都共用这个菜单,所以我不知道怎么让菜单来判断到底我是点级了那个按钮,然后重命名才不会互相干扰啊,这个就是不知道怎么判断了,谢谢各位帮忙一下好么?谢谢,不知道听懂了我的意思没,偶笨笨啦!!!
'参考一下.
'若干个COMMANDBUTTON,一个TEXT1,一个莱单(你要适当修改一下).
Option ExplicitDim WithEvents Ev_CommandButton As VB.CommandButtonPrivate Sub Ev_CommandButton_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
Me.PopupMenu MYPOPMNU '弹出莱单
End If
End SubPrivate Sub Form_Load()
Timer1.Interval = 50
Text1.Visible = False
End SubPrivate Sub Text1_Change()
If Not (Ev_CommandButton Is Nothing) Then
Ev_CommandButton.Caption = Text1.Text
End If
End SubPrivate Sub Text1_LostFocus()
Text1.Visible = False
End SubPrivate Sub Timer1_Timer()
If UCase$(TypeName(Me.ActiveControl)) = "COMMANDBUTTON" Then
Set Ev_CommandButton = Me.ActiveControl
End If
End SubPrivate Sub 修改_Click() '莱单中修改
Text1.Visible = True
End Sub
每次点击某个按钮,只需判断其它按钮的Tag中的之即可
focus = Index
Command1(Index).SetFocus
If Button = 2 Then PopupMenu a
End SubPrivate Sub rename_Click()
Command1(focus).Caption = InputBox("please enter the new name:", "rename", "新的名字")
End Sub
'********************************************
定义一个CommandButton的事件源.当设置好事件源的对象以后.可以对事件源操作.
例如:你可以将COMMAND1赋给Ev_CommandButton ,也可以将COMMAND2赋给Ev_CommandButton , 总之,只要源控件是COMMANDBUTTON,Ev_CommandButton 都可以处理.
注:这样定义不同于数组处理,比控件数组具有更大的灵活性.
focus = Index
Command1(Index).SetFocus
If Button = 2 Then PopupMenu a
End SubPrivate Sub rename_Click()
Command1(focus).Caption = InputBox("please enter the new name:", "rename", "新的名字")
End Sub你的方法错了吧,这样怎么能行呢,
你这样做,好像只对COMMAND1起作用,那么我现在有COMMAND1-COMMAND5这样啊,
那
Command1(focus).Caption =
这个又改怎么改变呢,我觉得你是误解了我的意思,或者你的方法错了吧
我将写个例子发给你.
[email protected]
注明:http://expert.csdn.net/Expert/topic/2951/2951512.xml?temp=6.283206E-02
focus = Index
Command1(Index).SetFocus
If Button = 2 Then PopupMenu a
End SubPrivate Sub rename_Click()
Command1(focus).Caption = InputBox("please enter the new name:", "rename", "新的名字")
End Sub没错,控件数组