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

Home Posts Topics Members FAQ

Custom event handling for click of menu item.

Hi all,

I am having application in whihc i am inserting menuitem dynamically.

When i add menuitem to mainmenu, i want to pass extra parameter to
eventargs. So what i did is derived class from eventargs and created
my own variable into this class.

And then while setting eventhandler i am passing this custom event
args. But this is not working.

Can anyone tell me what i am doing wrong. Can't i create my own
handler and attach it to client event.

Please help me asap.

Any sample code will be truely appreciated.

Feb 21 '07 #1
2 1869
In article <11************ **********@l53g 2000cwa.googleg roups.com>,
tr************* *@yahoo.com says...
I am having application in whihc i am inserting menuitem dynamically.

When i add menuitem to mainmenu, i want to pass extra parameter to
eventargs. So what i did is derived class from eventargs and created
my own variable into this class.
The MenuItem class already defines a specific signature for each of its
events. You can't change that.

If you want to store "extra" information with your MenuItem's you could
either subclass it, or, if its something really simple, use the Tag
property.

--
Patrick Steele
http://weblogs.asp.net/psteele
Feb 22 '07 #2
On Feb 21, 8:07 am, trialproduct2.. .@yahoo.com wrote:
Hi all,

I am having application in whihc i am inserting menuitem dynamically.

When i add menuitem to mainmenu, i want to pass extra parameter to
eventargs. So what i did is derived class from eventargs and created
my own variable into this class.

And then while setting eventhandler i am passing this custom event
args. But this is not working.

Can anyone tell me what i am doing wrong. Can't i create my own
handler and attach it to client event.

Please help me asap.

Any sample code will be truely appreciated.
You would have to derive your own menu item and add your custom data
to it. Something like this (check syntax):

Public Class MyMenuItemClass
Inherits ToolStripMenuIt em

Protected Overrides Sub OnClick(ByVal e As System.EventArg s)
Dim myEvent As New MyMenuEventArgs
myEvent.MyCusto mProperty = "Custom Data"

MyBase.OnClick( myEvent)
End Sub

End Class

Public Class MyMenuEventArgs
Inherits System.EventArg s

Private _myCustomProper ty As String
Public Property MyCustomPropert y() As String
Get
Return _myCustomProper ty
End Get
Set(ByVal value As String)
_myCustomProper ty = value
End Set
End Property
End Class

Then when you add your menu item dynamically and handle the click
event you can get the custom property data:

'In the Form class:

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e
As System.EventArg s) Handles Button1.Click

Dim customMenuItem As New MyMenuItemClass ()
AddHandler customMenuItem. Click, AddressOf MenuItem_Click

RootMenu.DropDo wnItems.Add(cus tomMenuItem)
End Sub
Private Sub MenuItem_Click( ByVal sender As System.Object, ByVal e
As System.EventArg s)
If TypeOf sender Is MyMenuItemClass Then
MsgBox("Custom data for menu: " & DirectCast(e,
MyMenuEventArgs ).MyCustomPrope rty)
Else
MsgBox("Normal menu item")
End If
End Sub

Notice in the MenuClick handler I first check to make sure the sender
is actually an instance of my custom menu class. If that is true,
then I can safely cast the EventArgs parameter (e) to my custom event
args.

Hope this helps

Feb 23 '07 #3

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

Similar topics

3
1829
by: serge calderara | last post by:
Dear all, I have a class named for Instance "MyClass" which populate trough an interface a context menu object to the main application. The click event on any of the context menu itemm will be proceed in the myClass event handler. Actally default event handle has two parameters: Sender and e Actually the context menu is shown in my main application
18
2892
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code that applies to all these events, but I need to have specific code execute when the form closes. The properties for this method are sender (the originator) and e (event arguments). I know how to get typeof (sender) to determine what form or...
11
1210
by: Marcelo | last post by:
Hello! I am developping a Visual C++ .NET 2003 multiple forms application. My problem is: When running my application, I click a button and a new main menu item is created. Ok. Now I want to relate an event to the click of this new item created. How do I create an event related to a component that is created in runtime? If somebody could help me anyway I thank very much.
6
2278
by: Joseph Geretz | last post by:
Writing an Outlook AddIn with C#. For the user interface within Outlook I'm adding matching pairs of Toolbar buttons and Menu items. All of the buttons and menu items are wired up to send events to the same method (aka delegate?). I use the Tag property within this method to determine what user action is taking place. Very simple: When adding toolbar button: tbButton.Click += new...
6
8781
by: Joseph Geretz | last post by:
I'm porting a C# Outlook Addin originally engineered as a COM Addin over to use VSTO. I've gotten this to the point where my VSTO Addin installs its Menu items and Toolbar buttons when Outlook launches. I've wired up my event handler to each Menu item and toolbar button. (I use the same Event handler and I use the Tag property which is different for every Menu Item and Toolbar buton to determine which menu or button is being clicked and to...
2
7101
by: AmericanGotham | last post by:
The following method adds items to a toolstripmenu named colums public void AddColumnMenu() { foreach (ColumnHeader column in messagesListView.Columns) { ToolStripMenuItem item = (ToolStripMenuItem)columnsToolStripMenuItem.DropDownItems.Add(column.Text); item.Checked = true;
12
4031
by: Tom Bean | last post by:
I am trying to display a ContextMenuStrip when a user right-clicks on an item in a ListView and have encountered a something that seems strange to me. When the ListView is initially populated, no items are selected. When the first item is selected by clicking either the left or right button, the SelectedIndexChanged event fires but not the MouseUp event. After the first item is selected and another item clicked on, both the...
2
19496
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
0
2897
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
0
9704
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
9571
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
10318
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...
1
10302
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9132
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...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2976
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.