A step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.
A C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.
This tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.
Creating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.
Making a Context MenuShows you how to make a context menu (right click / shortcut menu) in C# using Visual C# .NET and how to attach it to a control. |
On Tuesday, July 6th 2004 at 07:17 AM By Andrew Pociu (View Profile) ![]() ![]() ![]() ![]() (Rated 4 with 72 votes) |
||
|
You can hardly find an application that doesn't use any context menu. Adding a context menu to your application isn't hard at all, thanks to Visual C# .NET. Start a new Windows Application project. Look in the Toolbox for ContextMenu: Add it to the form by double clicking or dragging. After the context menu is added to the application project, when you click on it at the top of the form, below the Title Bar the menu appears waiting to be edited. Of course, that's not where the menu appears when you run the application. The menu appears when you right click the control. ![]() Let's add a few items to the menu. You can add new items just by clicking on the Type Here area. In the following screenshot you can see we added 3 items (Help -> About and Exit): ![]() You can add code to the click event of an item the same way you would with any control. Select the item and switch to Events in the properties window and double click the Click event. This will take you to where you need to insert the code for the event. Here is the code for the event of the 'Exit' item:
Ok, we have created the context menu now we need to attach it to the control we need to have a context menu when it is right clicked. You can attach a context menu to any control that has a ContextMenu property. To a Form, to a ListView, to a DataGrid, just use the Properties window to select a context menu: ![]() And here's the result to attaching the context menu to a form: |
|||
Digg It!
Del.icio.us
Reddit
StumbleIt
Newsvine
Furl
BlinkList
|
|||
|
|||
Current CommentsThat is O.K.
But, try to make context menu in runtime using Add method, wire up the same handler for different items of that menu and try to achieve different actions.
Nice and simple tutorial, thanks 8)
Can you help me create such a context menu in an asp.net application on a Web Form???
Hi thank you very much . but in my project i fill the menuItem by data taking from a datatable and i add them by code. so i cliked to one item of the menu how can i get this item .
any explanation please mail me.
thank you again
@azzam
either with the 'sender' object or you just index your menuitems or write something in the tags..
This Code can be useful only to the beginner.
For the Beginner we have so many like MSDN which is automatically provided by the microsoft.
Please publish your web page with some innotative concepts with the code. Will make this page a world of good.
As a beginner to C# I found this to be a great reference. It quickly shows me exactly what I need to know.
this is great. i was unable to create context menu but this helped me a lot. GREAT REFERENCE............................HURAYYYYYYYYY
thanks you it is very nice and simple to follow
Nice And Simple Toutorial.
Thanks.............
I want to add a submenu at runtime to existing context menu like shown above. Can anybone help me.
how can we assign click event for context menu
thanks mate.
good tutorial
Very nice.
here is the simple tutorial
http://www.ceveni.com/2009/10/sample-code-for-context-menu-in-c.html
i want C# code for
finding text i.e FIND ctrl F
find next i.e Findnext F3
in notepade application
void MenuFileFindOnClick(object obj, EventArgs ea)
{
MessageBox.Show("File FIND item clicked!", Text);
}
void MenuFileFindNextOnClick(object obj, EventArgs ea)
{
}
void MenuFileReplaceOnClick(object obj, EventArgs ea)
{
}
void MenuFileFGoToOnClick(object obj, EventArgs ea)
{
}
Thank you! Very simple and helpful :)
I bet this don't work for WPF?
in comparison to spending twenty to thirty thousand on an original Swiss-designed model. In addition, your watch will have the same look and feel of a real watch, and you will have thousands of dollars in savings. This situation is ideal in the event that you need an impressive and stylish luxury timepiece from a world-class brand name, but are not in a position to afford to buy one.
I'm fifty several years old user. My living adjustments after i lastly turned to e-cigarettes. It had been correct consider to try and do and that I designed it. Now I really feel healthier along with check out gymnasium following operate.
Business is never so healthy as when, like a chicken, it must do a certain amount of scratching around for what it gets
thank u for providing me information on List View.
I want to know how i can display data in datalist in Newsletter layout and Thank you so much, this is easy to understand and fun to continue along with. I am a migrating VB.NET/C# Developer looking for an insight into VC .NET. I've found the VC tutorials on many sites to be confusing, and the navigation around the sites to be near impossible to use! Thanks once again.
I am happy to find so many useful information here in the post, we need develop more strategies in this regard, thanks for sharing.
Once you have recreated the problem and captured these steps, you can save them to a file and send it to your support person, who can then open it up and view
Hi thank you very much . but in my project i fill the menuItem by data taking from a datatable and i add them by code. so i cliked to one item of the menu how can i get this item .
For the Beginner we have so many like MSDN which is automatically provided by the microsoft.
I was just browsing through the internet looking for some information and came across. I am impressed by the information. It shows how well you understand this subject. Bookmarked this page, will come back for more.
Thank you for sharing, I will often come to patronize your site
I always wondered how they built these, its pretty standard, and I would never guess it takes this much effort, but then again I'm still new to the programming crowd. Thanks for the TUT...!
If you're in the corner and have got no cash to get out from that, you would require to receive the <a href="http://goodfinance-blog.com/topics/credit-loans">credit loans</a>. Just because it would help you emphatically. I take sba loan every year and feel great just because of it.
I have been absent for a while, but now I remember why I used to love this blog. Thank you
Related Tutorials
Related Source Code
C# Job Search