473,804 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ContextMenu

Hi,
I am trying to show the shortcut menu on a richtextbox control by
adding the contextmenu component onto the form. The richtextbox
property is assigned to the contextmenu. I created my shorcuts, copy,
paste, etc. However, on the form I have a datagrid
which is also assigned to the same contextmenu and contextmenupopu p
event as follows:
....
If ContextMenu1.So urceControl Is richtextbox1The n
' Add MenuItems to display for the TextBox.
ContextMenu1.Me nuItems.Add(men uItem1)
ContextMenu1.Me nuItems.Add(men uItem2)
ElseIf ContextMenu1.So urceControl Is datagrid1 Then
' Add the MenuItem
ContextMenu1.Me nuItems.Add(men uItem3)
End If
....
when I right-click on the richtext control I get the sourcecontrol =
Nothing, but r-click on grid
i get the control name. I droped the richtext control and added another
one and set the
cmenu property and still nothing. Any idea?

Thanks in advance

Aug 16 '06 #1
7 2234
Need some more code, like the event handler sub declaration and what it
handles.
--
Dennis in Houston
"wandii" wrote:
Hi,
I am trying to show the shortcut menu on a richtextbox control by
adding the contextmenu component onto the form. The richtextbox
property is assigned to the contextmenu. I created my shorcuts, copy,
paste, etc. However, on the form I have a datagrid
which is also assigned to the same contextmenu and contextmenupopu p
event as follows:
....
If ContextMenu1.So urceControl Is richtextbox1The n
' Add MenuItems to display for the TextBox.
ContextMenu1.Me nuItems.Add(men uItem1)
ContextMenu1.Me nuItems.Add(men uItem2)
ElseIf ContextMenu1.So urceControl Is datagrid1 Then
' Add the MenuItem
ContextMenu1.Me nuItems.Add(men uItem3)
End If
....
when I right-click on the richtext control I get the sourcecontrol =
Nothing, but r-click on grid
i get the control name. I droped the richtext control and added another
one and set the
cmenu property and still nothing. Any idea?

Thanks in advance

Aug 16 '06 #2

Dennis wrote:
Need some more code, like the event handler sub declaration and what it
handles.
--
Dennis in Houston
"wandii" wrote:
Hi,
I am trying to show the shortcut menu on a richtextbox control by
adding the contextmenu component onto the form. The richtextbox
property is assigned to the contextmenu. I created my shorcuts, copy,
paste, etc. However, on the form I have a datagrid
which is also assigned to the same contextmenu and contextmenupopu p
event as follows:
....
If ContextMenu1.So urceControl Is richtextbox1The n
' Add MenuItems to display for the TextBox.
ContextMenu1.Me nuItems.Add(men uItem1)
ContextMenu1.Me nuItems.Add(men uItem2)
ElseIf ContextMenu1.So urceControl Is datagrid1 Then
' Add the MenuItem
ContextMenu1.Me nuItems.Add(men uItem3)
End If
....
when I right-click on the richtext control I get the sourcecontrol =
Nothing, but r-click on grid
i get the control name. I droped the richtext control and added another
one and set the
cmenu property and still nothing. Any idea?

Thanks in advance
Thanks for your time Dennis. Here you go... I have the property of
datagrid and richtext
are assigned to contextmenu. Works fine for the datagrid and I get
nothing for the rtext. Thanks

Public Sub ContextMenu1_Po pup(ByVal sender As System.Object, ByVal
e As System.EventArg s) Handles ContextMenu1.Po pup

' Define the MenuItem objects to display for the TextBox.
Dim menuItem1 As New MenuItem("&Copy ")
Dim menuItem2 As New MenuItem("&Find and Replace")
' Define the MenuItem object to display for the PictureBox.
Dim menuItem3 As New MenuItem("C&han ge Picture")

' Clear all previously added MenuItems.
ContextMenu1.Me nuItems.Clear()

If ContextMenu1.So urceControl Is richtextbox1The n
' Add MenuItems to display for the TextBox.
ContextMenu1.Me nuItems.Add(men uItem1)
ContextMenu1.Me nuItems.Add(men uItem2)
ElseIf ContextMenu1.So urceControl Is datagrid1 Then
' Add the MenuItem to display for the PictureBox.
ContextMenu1.Me nuItems.Add(men uItem3)
End If

Aug 17 '06 #3
Your code looks fine. Are you able to type information into the richtextbox
to be sure it can get the focus? Also, does the contextmenu1 appear when you
right click on the richtextbox?
--
Dennis in Houston
"wandii" wrote:
>
Dennis wrote:
Need some more code, like the event handler sub declaration and what it
handles.
--
Dennis in Houston
"wandii" wrote:
Hi,
I am trying to show the shortcut menu on a richtextbox control by
adding the contextmenu component onto the form. The richtextbox
property is assigned to the contextmenu. I created my shorcuts, copy,
paste, etc. However, on the form I have a datagrid
which is also assigned to the same contextmenu and contextmenupopu p
event as follows:
....
If ContextMenu1.So urceControl Is richtextbox1The n
' Add MenuItems to display for the TextBox.
ContextMenu1.Me nuItems.Add(men uItem1)
ContextMenu1.Me nuItems.Add(men uItem2)
ElseIf ContextMenu1.So urceControl Is datagrid1 Then
' Add the MenuItem
ContextMenu1.Me nuItems.Add(men uItem3)
End If
....
when I right-click on the richtext control I get the sourcecontrol =
Nothing, but r-click on grid
i get the control name. I droped the richtext control and added another
one and set the
cmenu property and still nothing. Any idea?
>
Thanks in advance
>
>

Thanks for your time Dennis. Here you go... I have the property of
datagrid and richtext
are assigned to contextmenu. Works fine for the datagrid and I get
nothing for the rtext. Thanks

Public Sub ContextMenu1_Po pup(ByVal sender As System.Object, ByVal
e As System.EventArg s) Handles ContextMenu1.Po pup

' Define the MenuItem objects to display for the TextBox.
Dim menuItem1 As New MenuItem("&Copy ")
Dim menuItem2 As New MenuItem("&Find and Replace")
' Define the MenuItem object to display for the PictureBox.
Dim menuItem3 As New MenuItem("C&han ge Picture")

' Clear all previously added MenuItems.
ContextMenu1.Me nuItems.Clear()

If ContextMenu1.So urceControl Is richtextbox1The n
' Add MenuItems to display for the TextBox.
ContextMenu1.Me nuItems.Add(men uItem1)
ContextMenu1.Me nuItems.Add(men uItem2)
ElseIf ContextMenu1.So urceControl Is datagrid1 Then
' Add the MenuItem to display for the PictureBox.
ContextMenu1.Me nuItems.Add(men uItem3)
End If

Aug 18 '06 #4
Sorry Dennis I could not get back to you soon. Yes I tried to setfocus
to richtext on form load and can type into richtext, however, no
contextmenu appears when I r-click on
it. I put a breakpoint please see below:
bp If ContextMenu1.So urceControl Is richtextbox1The n
' Add MenuItems to display for the TextBox.
ContextMenu1.Me nuItems.Add(men uItem1)
ContextMenu1.Me nuItems.Add(men uItem2)
ElseIf ContextMenu1.So urceControl Is datagrid1 Then
' Add the MenuItem
ContextMenu1.Me nuItems.Add(men uItem3)
End If
and sourcecontrol is nothing. Plan B: deleted the old richtext control
and added a new one still sourcecontrol is nothing. I tried on a
button, datagrid and sourcecontrol is not
null. Richtext's contextmenu property is to the contextmenu2. This is
very strange?
I am not sure if I need to set another property. Any other
suggestions. Thanks
Dennis wrote:
Your code looks fine. Are you able to type information into the richtextbox
to be sure it can get the focus? Also, does the contextmenu1 appear when you
right click on the richtextbox?
--
Dennis in Houston
"wandii" wrote:

Dennis wrote:
Need some more code, like the event handler sub declaration and what it
handles.
--
Dennis in Houston
>
>
"wandii" wrote:
>
Hi,
I am trying to show the shortcut menu on a richtextbox control by
adding the contextmenu component onto the form. The richtextbox
property is assigned to the contextmenu. I created my shorcuts, copy,
paste, etc. However, on the form I have a datagrid
which is also assigned to the same contextmenu and contextmenupopu p
event as follows:
....
If ContextMenu1.So urceControl Is richtextbox1The n
' Add MenuItems to display for the TextBox.
ContextMenu1.Me nuItems.Add(men uItem1)
ContextMenu1.Me nuItems.Add(men uItem2)
ElseIf ContextMenu1.So urceControl Is datagrid1 Then
' Add the MenuItem
ContextMenu1.Me nuItems.Add(men uItem3)
End If
....
when I right-click on the richtext control I get the sourcecontrol =
Nothing, but r-click on grid
i get the control name. I droped the richtext control and added another
one and set the
cmenu property and still nothing. Any idea?

Thanks in advance
Thanks for your time Dennis. Here you go... I have the property of
datagrid and richtext
are assigned to contextmenu. Works fine for the datagrid and I get
nothing for the rtext. Thanks

Public Sub ContextMenu1_Po pup(ByVal sender As System.Object, ByVal
e As System.EventArg s) Handles ContextMenu1.Po pup

' Define the MenuItem objects to display for the TextBox.
Dim menuItem1 As New MenuItem("&Copy ")
Dim menuItem2 As New MenuItem("&Find and Replace")
' Define the MenuItem object to display for the PictureBox.
Dim menuItem3 As New MenuItem("C&han ge Picture")

' Clear all previously added MenuItems.
ContextMenu1.Me nuItems.Clear()

If ContextMenu1.So urceControl Is richtextbox1The n
' Add MenuItems to display for the TextBox.
ContextMenu1.Me nuItems.Add(men uItem1)
ContextMenu1.Me nuItems.Add(men uItem2)
ElseIf ContextMenu1.So urceControl Is datagrid1 Then
' Add the MenuItem to display for the PictureBox.
ContextMenu1.Me nuItems.Add(men uItem3)
End If
Sep 2 '06 #5
Try this code (note the "sender" in the if statments:
Public Sub ContextMenu1_Po pup(ByVal sender As System.Object, ByVal _
e As System.EventArg s) Handles ContextMenu1.Po pup

' Define the MenuItem objects to display for the TextBox.
Dim menuItem1 As New MenuItem("&Copy ")
Dim menuItem2 As New MenuItem("&Find and Replace")
' Define the MenuItem object to display for the PictureBox.
Dim menuItem3 As New MenuItem("C&han ge Picture")

' Clear all previously added MenuItems.
ContextMenu1.Me nuItems.Clear()

If Sender Is richtextbox1The n
' Add MenuItems to display for the TextBox.
ContextMenu1.Me nuItems.Add(men uItem1)
ContextMenu1.Me nuItems.Add(men uItem2)
ElseIf Sender Is datagrid1 Then
' Add the MenuItem to display for the PictureBox.
ContextMenu1.Me nuItems.Add(men uItem3)
End If

--
Dennis in Houston

Sep 3 '06 #6
Nope - didn't work. The reason is that the sender listed below is
looking at the contextmenu (1, 2, ...) controls.
Dennis wrote:
Try this code (note the "sender" in the if statments:
Public Sub ContextMenu1_Po pup(ByVal sender As System.Object, ByVal _
e As System.EventArg s) Handles ContextMenu1.Po pup

' Define the MenuItem objects to display for the TextBox.
Dim menuItem1 As New MenuItem("&Copy ")
Dim menuItem2 As New MenuItem("&Find and Replace")
' Define the MenuItem object to display for the PictureBox.
Dim menuItem3 As New MenuItem("C&han ge Picture")

' Clear all previously added MenuItems.
ContextMenu1.Me nuItems.Clear()

If Sender Is richtextbox1The n
' Add MenuItems to display for the TextBox.
ContextMenu1.Me nuItems.Add(men uItem1)
ContextMenu1.Me nuItems.Add(men uItem2)
ElseIf Sender Is datagrid1 Then
' Add the MenuItem to display for the PictureBox.
ContextMenu1.Me nuItems.Add(men uItem3)
End If

--
Dennis in Houston
Sep 5 '06 #7
Sorry, I don't know what to try next. Are you sure you spelled the name of
the richtext box correctly? You might want to add a second contextmenu
dedicated to your richtextbox.
--
Dennis in Houston
"wandii" wrote:
Nope - didn't work. The reason is that the sender listed below is
looking at the contextmenu (1, 2, ...) controls.
Dennis wrote:
Try this code (note the "sender" in the if statments:
Public Sub ContextMenu1_Po pup(ByVal sender As System.Object, ByVal _
e As System.EventArg s) Handles ContextMenu1.Po pup

' Define the MenuItem objects to display for the TextBox.
Dim menuItem1 As New MenuItem("&Copy ")
Dim menuItem2 As New MenuItem("&Find and Replace")
' Define the MenuItem object to display for the PictureBox.
Dim menuItem3 As New MenuItem("C&han ge Picture")

' Clear all previously added MenuItems.
ContextMenu1.Me nuItems.Clear()

If Sender Is richtextbox1The n
' Add MenuItems to display for the TextBox.
ContextMenu1.Me nuItems.Add(men uItem1)
ContextMenu1.Me nuItems.Add(men uItem2)
ElseIf Sender Is datagrid1 Then
' Add the MenuItem to display for the PictureBox.
ContextMenu1.Me nuItems.Add(men uItem3)
End If

--
Dennis in Houston

Sep 5 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1667
by: MD | last post by:
I have a ContextMenu that is assigned to 3 RichTextBox's (i.e., if you right-click on any of the 3 RichTextBox's, you get the same ContextMenu). My ContextMenu has 2 items, each of which have their own click event handlers. When I click on any of the options in the ContextMenu, I want to know which RichTextBox the ContextMenu is currently opened in, so I thought I could check the SourceControl property. The problem is, the property is...
2
2927
by: Derrick | last post by:
I've been working on an application which has a NotifyIcon (system tray icon), and a corresponding ContextMenu. I want to be able to update this menu dynamically. However, when I make changes to the menu, it seems to disappear. This only breaks when the context menu is tied to a NotifyIcon - not to any other control. Below is a C# file for a form which should illustrate this (at least it does on my machine!). The same contextmenu is...
2
2128
by: Zieben | last post by:
Hello! I have such problem! I have my UserControl. I override property ContextMenu for this Control as ..... new ContextMenu ContextMenu{ set {_contextMenu = value;}
0
1370
by: cemino | last post by:
Hi, I got a problem with ContextMenu. I'm using a hot-key (like Ctrl-B) to show contextMenu in my program. Things is like below: contextMenu.Show(Form1, New Point(Cursor.Position.X,Cursor.Position.Y)); But it looks that the contextMenu can not get focus in this way, because I can not use the Up/Down keys on keyboard to do menu selections with the contextMenu.
10
21332
by: tmaster | last post by:
When I try to dynamically add a second sub menu item to this ContextMenu item, I get an error 'Specified argument was out of the range of valid values'. Private Sub mnuTopics_Show_Select(ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles mnuTopics_Show.Select Dim mShowMenuItem As MenuItem mShowMenuItem = DirectCast(sender, MenuItem)
7
1396
by: TryingLikeHeck | last post by:
I have a usercontrol on which I've generated a context menu in designer. The properties of the control lists for ContextMenu (none) The menu shows up in the designer window and I can edit it To assign my menu to the property in New I do ContextMenu = RePopupMenu To show it, on right mouse down I do ContextMenu.Show(Me, New Drawing.Point(e.X, e.Y))
11
2681
by: Graham Charles | last post by:
I'm writing a control inheriting from ComboBox, and I'd like to add an entry to the ContextMenu for that combo box. I have no problem if I create an entirely new ContextMenu from scratch, but I'd prefer just to tack my MenuItem on to the existing, built-in ContextMenu (Cut, Copy, Paste, etc.): _RemoveMRUItemMenu = New MenuItem _RemoveMRUItemMenu.Text = "&Remove Item" _RemoveMRUItemMenu.Enabled = False
3
2512
by: Libby Sharf | last post by:
Hello, I have several ContextMenus and I want to connect them to the GridControl's ContextMenu property depending on the row that was right clicked. Is there an event that is raised just before the ContextMenu is displayed? (In Delphi we used to have the ContextPopup event and we could change the ContextMenu there.) What is the best way to achieve this? Libby
0
1561
by: Steve Richter | last post by:
I cant get a contextmenu to popup in the context of a datagridview. It pops up in the ListBox, and in the form itself. But not the DataGridView. How could that be? here is my code: using System; using System.ComponentModel; using System.Data; using System.Drawing;
3
347
by: asharda | last post by:
Hi, I am trying to create a context menu in my application. The context menu takes menu otems from an XML file. In XAML the code is <Grid.ContextMenu> <ContextMenu Name="cm" StaysOpen="true" Width="Auto" Height="Auto" ItemsSource="{Binding Mode=OneWay, Source={StaticResource ListItemsDS}, XPath=/ListboxItems/ListboxItem/ ScreenName}" MenuItem.Click="add_Click">
0
9715
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10603
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10353
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10099
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4314
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3003
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.