Office中国论坛/Access中国论坛

标题: 请教老和尚如何批量给每个文本框写同样的事件代码。 [打印本页]

作者: memphis240    时间: 2015-4-20 22:18
标题: 请教老和尚如何批量给每个文本框写同样的事件代码。
比如文本框的鼠标键按下,事件过程全部是
If Button = 2 Then
   CommandBars("myCom").Controls(6).Enabled = False
   CommandBars("myCom").Controls(7).Enabled = False
   CommandBars("myCom").ShowPopup
End If

请教如何用最简单的方法给10几个文本框写上这几行代码。
有没有方法如
dim ctl as control
  for each ctl in me.controls
    if typeof ctl is textbox then
    ……写起上面的代码,让每个文本框鼠标右键按下后弹出菜单。
    end if
  next ctl

作者: roych    时间: 2015-4-21 09:01
本帖最后由 roych 于 2015-4-21 09:03 编辑

dim ctl as control
  for each ctl in me.controls
    if typeof ctl is textbox then
            textbox.onclick="=函数名()"
    end if
  next ctl
把它放在窗体的加载事件中。具体可以参考以下帖子:
http://www.office-cn.net/thread-112360-1-1.html
作者: memphis240    时间: 2015-4-21 19:17
roych 发表于 2015-4-21 09:01
dim ctl as control
  for each ctl in me.controls
    if typeof ctl is textbox then

老和尚,这招不灵啊,关键是onmousedown要判断鼠标右键的,就是那个if button=2不好搞,还有其它高招吗?
作者: roych    时间: 2015-4-22 13:54
memphis240 发表于 2015-4-21 19:17
老和尚,这招不灵啊,关键是onmousedown要判断鼠标右键的,就是那个if button=2不好搞,还有其它高招吗?

试试用右键菜单吧。
http://jingyan.baidu.com/article/f25ef2540a83c8482c1b828a.html
顺便说一下,我不是老和尚,也不是喇嘛,我是有头发的,而且很茂密。
作者: zpy2    时间: 2015-4-23 05:13
用类 应可以的吧
作者: memphis240    时间: 2015-4-30 10:27
roych 发表于 2015-4-22 13:54
试试用右键菜单吧。
http://jingyan.baidu.com/article/f25ef2540a83c8482c1b828a.html
顺便说一下,我 ...

好刀法。




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3