Click here to Skip to main content
15,890,512 members
Home / Discussions / C#
   

C#

 
GeneralRe: Naming Convention Pin
James T. Johnson11-Feb-02 16:39
James T. Johnson11-Feb-02 16:39 
GeneralRe: Naming Convention Pin
Peter Stephens8-Feb-02 7:44
Peter Stephens8-Feb-02 7:44 
Generaltrying to prevent user from exiting the application sometimes Pin
7-Feb-02 6:59
suss7-Feb-02 6:59 
GeneralRe: trying to prevent user from exiting the application sometimes Pin
7-Feb-02 13:01
suss7-Feb-02 13:01 
GeneralWindows Form Help Application Pin
kyledunn7-Feb-02 1:39
kyledunn7-Feb-02 1:39 
GeneralVisio with c# Pin
6-Feb-02 23:04
suss6-Feb-02 23:04 
GeneralShow ContextMenu in Node Pin
thongkk6-Feb-02 14:51
thongkk6-Feb-02 14:51 
GeneralRe: Show ContextMenu in Node Pin
Schnemar7-Mar-02 4:38
Schnemar7-Mar-02 4:38 
put a ContextMenu on your Form
private System.Windows.Forms.ContextMenu contextMenu;

Example:
(I used a Treeview (treeview) with 3 Nodes, every Node has one SubNode
and my ContextMenu has two MenuItem's)

Declare two Menu-Items for the ContextMenu:
private MenuItem contextMenuItem1 = new MenuItem();
private MenuItem contextMenuItem2 = new MenuItem();

Add the following Code to your Constructor:
//Initialize Context-Menu
this.treeView.ContextMenu = this.contextMenu;
contextMenuItem1.Text = "Action 1";
contextMenuItem2.Text = "Action 2";
this.contextMenu.MenuItems.Add(0,contextMenuItem1);
this.contextMenu.MenuItems.Add(1,contextMenuItem2);
contextMenuItem1.Click += new System.EventHandler(this.contextMenu_Action_1);
contextMenuItem2.Click += new System.EventHandler(this.contextMenu_Action_2);

Override the MouseDown Event from your Treeview Control:
private void treeView_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button != MouseButtons.Right) return;
this.contextMenuItem1.Text = "Action 1";
this.contextMenuItem2.Text = "Action 2";
TreeNode selectedTreeNode = this.treeView.GetNodeAt(new Point(e.X,e.Y));
if(selectedTreeNode != null)
{
this.contextMenuItem1.Text = "Action 1 (Selected Node = " + selectedTreeNode.Text + ")";
this.contextMenuItem2.Text = "Action 2 (Selected Node = " + selectedTreeNode.Text + ")";
}
}

Implement the Funktions for the Eventhandler:
private void contextMenu_Action_1(object sender, System.EventArgs e)
{
if(this.contextMenuItem1.Text == "Action 1")
MessageBox.Show("Action 1 fired for Treeview");
else
MessageBox.Show("Action 1 fired for selected Node in Treeview");
}
private void contextMenu_Action_2(object sender, System.EventArgs e)
{
if(this.contextMenuItem2.Text == "Action 2")
MessageBox.Show("Action 2 fired for Treeview");
else
MessageBox.Show("Action 2 fired for selected Node in Treeview");
}

I Hope this was helpfully for you.

rgrdsSmile | :)
Martin

GeneralRe: Show ContextMenu in Node Pin
thongkk7-Mar-02 14:26
thongkk7-Mar-02 14:26 
GeneralWin9x Pin
woodcarver6-Feb-02 11:41
woodcarver6-Feb-02 11:41 
GeneralRe: Win9x Pin
9-Feb-02 5:47
suss9-Feb-02 5:47 
GeneralIP Address in .NET Pin
Joe Folger6-Feb-02 10:07
Joe Folger6-Feb-02 10:07 
GeneralRe: IP Address in .NET Pin
Joe Folger6-Feb-02 11:06
Joe Folger6-Feb-02 11:06 
Generalproblems getting a timer to work Pin
6-Feb-02 8:32
suss6-Feb-02 8:32 
GeneralRe: problems getting a timer to work Pin
James T. Johnson6-Feb-02 10:39
James T. Johnson6-Feb-02 10:39 
GeneralRe: problems getting a timer to work Pin
7-Feb-02 5:50
suss7-Feb-02 5:50 
QuestionHow to call a C# Dll from C++ ?? Pin
6-Feb-02 5:03
suss6-Feb-02 5:03 
AnswerRe: How to call a C# Dll from C++ ?? Pin
James T. Johnson6-Feb-02 11:17
James T. Johnson6-Feb-02 11:17 
GeneralRe: How to call a C# Dll from C++ ?? Pin
9-Feb-02 3:00
suss9-Feb-02 3:00 
GeneralRe: How to call a C# Dll from C++ ?? Pin
James T. Johnson9-Feb-02 18:50
James T. Johnson9-Feb-02 18:50 
Generaltrap arrow keys in usercontrol Pin
6-Feb-02 3:13
suss6-Feb-02 3:13 
GeneralRe: trap arrow keys in usercontrol Pin
James T. Johnson6-Feb-02 10:46
James T. Johnson6-Feb-02 10:46 
GeneralPreserving dynamic controls across postbacks Pin
5-Feb-02 15:16
suss5-Feb-02 15:16 
GeneralRe: Preserving dynamic controls across postbacks Pin
James T. Johnson5-Feb-02 19:49
James T. Johnson5-Feb-02 19:49 
GeneralC# singleton Pin
Steve Severance5-Feb-02 8:10
Steve Severance5-Feb-02 8:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.