如何实现快捷菜单

fiftystep 2000-07-04 06:43:00
在编程时,当我们敲完 form. 后面会弹出一个菜单,提示我们所有窗体的属性。
这样,只需选择一个,不用再输入字符。请问vb编程时,如何实现。
...全文
108 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
bluewater 2000-07-09
  • 打赏
  • 举报
回复
以下是我用VB写的一段程序,与你的要求类似,你考虑一下吧!
本程序有一个文本框控件!
可以对字符"."前的字符进行敏感
而你可以重新定义字符".",将其改为"!"等等其它的字符!
我在这里用了一个list控件显示可以选取的信息!

Private Declare Function GetCaretPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private startsave As Boolean
Private str As String
Private newline As Boolean
Private oldposi As Long

Private Sub Form_Load()
Dim ret As Long
Dim point As POINTAPI
Form1.Text1.Text = ""
startsave = False
str = ""
SendKeys Space(2)
ret = GetCaretPos(point)
List1.Visible = False
End Sub

Private Sub List1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Or KeyAscii = Asc(Space(1)) Then
List1.Visible = False
SendKeys List1.List(List1.ListIndex)
ElseIf KeyAscii = vbKeyBack Or KeyAscii = vbKeyEscape Then
List1.Visible = False
Text1.SetFocus
End If
End Sub

Private Sub Text1_Change()
Dim midchar As String

If Text1.SelStart >= 1 Then
midchar = Mid(Text1.Text, Text1.SelStart, 1)
End If
If midchar = Space(1) Then
startsave = True
str = ""
End If

If Text1.SelStart > 1 Then

If Mid(Text1.Text, Text1.SelStart - 1, 1) = Chr(10) Then
startsave = True
str = ""
End If

End If

If midchar = "." Then
judgeit (str)
End If



If startsave And midchar <> Space(1) Then

If oldposi < Text1.SelStart Then
str = str & midchar
Else
If Len(str) > 1 Then
str = Left(str, Len(str) - 1)
End If
End If
End If

oldposi = Text1.SelStart
End Sub

Function judgeit(ByVal strtemp As String)
Dim point As POINTAPI
Dim ret As Long
Select Case strtemp

Case "word1": '对word1敏感
ret = GetCaretPos(point)
List1.Visible = True
For i = 0 To 10
List1.AddItem i
Next
List1.Left = Text1.Left + point.x + 5
List1.Top = Text1.Top + point.y + 3
List1.SetFocus
List1.ListIndex = 0

Case "word2": '对word2敏感
ret = GetCaretPos(point)
List1.Visible = True
For i = 10 To 20
List1.AddItem i
Next
List1.Left = Text1.Left + point.x + 5
List1.Top = Text1.Top + point.y + 3
List1.SetFocus
List1.ListIndex = 0
Case Else: 在这里你可以定义别的单词敏感
End Select
End Function
Janven 2000-07-06
  • 打赏
  • 举报
回复
最近一期的(2000年第五期)《电脑编程技巧与维护》上专门有一篇文章介绍,是作成控件的办法,可惜不是电子文档,不能发给你。你自己找一下吧。
TopHead 2000-07-06
  • 打赏
  • 举报
回复
是不是说做控件啊?
remywang 2000-07-06
  • 打赏
  • 举报
回复
不懂什么意思?
TopHead 2000-07-04
  • 打赏
  • 举报
回复
不懂什么意思?能详细点吗?
linfeng 2000-07-04
  • 打赏
  • 举报
回复
不是菜单,而是一个下拉框。先作一个表单,必要时显示出来就行了,用GetCursorPos得到鼠标坐标。如果是菜单的话,用PopupMenu弹出。

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧