明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2034|回复: 5

[VBA]为什么文本框没有右键功能?

[复制链接]
发表于 2003-12-3 13:22:00 | 显示全部楼层 |阅读模式
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2003-12-4 21:07:00 | 显示全部楼层
可能是没有,没有CLICK事件
发表于 2003-12-8 09:25:00 | 显示全部楼层
VBA只能看作VB的一个子集,这种功能可以通过截获控件的相关消息来实现。(使用相关的API函数)
发表于 2003-12-8 09:59:00 | 显示全部楼层
简单点的方法是使用VB编写的DLL.
 楼主| 发表于 2003-12-8 16:09:00 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2013-7-13 11:29:54 | 显示全部楼层
添加一个模块

Option Explicit
Public hwnd As Long
Type RECT
     Left As Long
     Top As Long
     Right As Long
     Bottom As Long
End Type
Type POINTAPI
     x As Long
     Y As Long
End Type
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function CreatePopupMenu Lib "user32" () As Long
Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long
Declare Function TrackPopupMenu& Lib "user32" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal x As Long, ByVal Y As Long, ByVal nReserved As Long, ByVal hwnd As Long, lprc As RECT)
Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long




Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Declare Function DestroyMenu Lib "user32" (ByVal hMenu As Long) As Long
Declare Function GetMenuCheckMarkDimensions Lib "user32" () As Long
Declare Function SetMenuItemBitmaps Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal hBitmapUnchecked As Long, ByVal hBitmapChecked As Long) As Long
Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Declare Function EmptyClipboard Lib "user32" () As Long
Declare Function CloseClipboard Lib "user32" () As Long




在窗体中增加以下语句
Private Sub 工作目录TextBox_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
If Button = 2 Then      '右击显示弹出式菜单
      Dim CurrentPoint As POINTAPI
      GetCursorPos CurrentPoint
      Call ShowPopMenu_Txt(工作目录TextBox, CurrentPoint.x, CurrentPoint.Y)
   End If
End Sub
Sub ShowPopMenu_Txt(ctr As MSForms.TextBox, ByVal x As Single, ByVal Y As Single)  ' 定义并显示弹出式菜单
    Dim hMenu As Long, lOption As Long
    Dim rct As RECT, iAns As Integer
    hMenu = CreatePopupMenu '建立一级弹出菜单
    AppendMenu hMenu, 0 Or lOption, 1, "复制"  '增加菜单条目
    AppendMenu hMenu, 0 Or lOption, 2, "剪切"  '增加菜单条目
    AppendMenu hMenu, 0 Or lOption, 3, "贴贴"  '增加菜单条目
    iAns = TrackPopupMenu(hMenu, 256, x, Y, 0, hwnd, rct)
    '显示弹出式菜单并返回选取条目命令
       Call PopMenuAction_Txt(ctr, ByVal iAns) '执行条目代码
        DestroyMenu hMenu '销毁弹出菜单
End Sub

Sub PopMenuAction_Txt(ctr As MSForms.TextBox, ByVal CommandID As Integer) '执行菜单条目代码
    Select Case CommandID
        Case 1
            ctr.Copy
        Case 2
            ctr.Cut
        Case 3
            ctr.Paste
    End Select
End Sub
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 12:24 , Processed in 0.171160 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表