Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21856

Tip: How to disable the Right-Click Context Menu for a Textbox control array

$
0
0
After looking at a half dozen possible solutions I came up with a simple answer.

In a MouseDown event when the right-button is clicked disable the textbox, then do what you want instead of the pop-up menu, then save the textbox properties to temporary local variables, unload the textbox, reload the textbox and restore the properties.

In the code below F.TB(Index) is the textbox, and InitializeRCRightContextMenu is my custom right-click context menu. F.Window is the frame where the textbox is supposed to appear and elsewhere in the program F.TB(Index).Tag is set with the index for F.Window.

Only one slight problem. When the textbox is disabled you can briefly see the focus change to a different textbox. I will look for a solution to this, but if I can't find it it won't bother me much.

Cheers, Brent

Sub View_RC_TB_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim Top As Long, Left As Long, Width As Long, Height As Long, Tag As Long, Text As String
If Button = vbRightButton Then
F.TB(Index).Enabled = False
Call InitializeRCRightContextMenu(CLng(Index))

Top = F.TB(Index).Top
Left = F.TB(Index).Left
Width = F.TB(Index).Width
Height = F.TB(Index).Height
Text = F.TB(Index).Text
Tag = F.TB(Index).Tag
Unload F.TB(Index)
Load F.TB(Index)
F.TB(Index).Top = Top
F.TB(Index).Left = Left
F.TB(Index).Width = Width
F.TB(Index).Height = Height
F.TB(Index).Text = Text
F.TB(Index).Tag = Tag
Set F.TB(Index).Container = F.Window(Tag)
F.TB(Index).Visible = True
End If

End Sub

Viewing all articles
Browse latest Browse all 21856

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>