context menu

  • Thread starter Thread starter Dean L. Howen
  • Start date Start date
Yes you can...

I guess you can take two path..
One is attaching the context menu to the Control using the "ContextMenu"
property of the control or else.. you can create a object of the Context
menu and use the .Show method..

Nirosh.
 
Yeah, I could.
But I want sometime the context menu disappears (I could find the support
method).
Why?
For example, I want the context menu work on TreeNode rather than TreeView,
but it seems for me to attach the context menu to TreeView.
What I'm doing is determine if Right-click clicks on the node, and disable
all the menu items in context menu. So it's better if context menu not show
in this situation


----------------
 
I have an application where that does the same thing. The solution that I
used was to subclass the TreeView control and add a property to determine
if I want to display the context menu. Here's the code for the subclassed
TreeView:

public class SpecializedTreeView : TreeView
{
private const int WM_CONTEXTMENU = 0x007B;
private bool contextMenuEnabled;

public SpecializedTreeView()
{
this.contextMenuEnabled = true;
}

/// <summary>
/// Gets or sets a value to enable or disable the displaying of the
context menu for this control.
/// </summary>
public bool EnableContextMenu
{
get
{
return this.contextMenuEnabled;
}
set
{
this.contextMenuEnabled = value;
}
}

protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_CONTEXTMENU:
if (!this.contextMenuEnabled)
return;

break;
}

base.WndProc(ref m);
}
}

On the MouseDown event for the SpecializedTreeView control I check if a
node was right-clicked:

// get the node that was clicked
TreeNode selectedNode = this.specializedTreeView.GetNodeAt(e.X, e.Y);

if(selectedNode != null && e.Button == MouseButtons.Right)
{
this.specializedTreeView.EnableContextMenu = true;
}
else
{
this.specializedTreeView.EnableContextMenu = false;
}

This way the context menu is only displayed if a node is right-clicked.

hth

-Joel

--------------------
From: "Dean L. Howen" <[email protected]>
References: <#[email protected]>
Subject: Re: context menu
Date: Fri, 5 Nov 2004 03:13:57 +0700
Lines: 33
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
Message-ID: <#[email protected]>
Newsgroups: microsoft.public.dotnet.languages.csharp
NNTP-Posting-Host: ci76-243.netnam.vn 203.162.76.243
Path: cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13
.phx.gbl
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.languages.csharp:284561
X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

Yeah, I could.
But I want sometime the context menu disappears (I could find the support
method).
Why?
For example, I want the context menu work on TreeNode rather than TreeView,
but it seems for me to attach the context menu to TreeView.
What I'm doing is determine if Right-click clicks on the node, and disable
all the menu items in context menu. So it's better if context menu not show
in this situation

This reply is provided AS IS, without warranty (express or implied).
 
Dear Joel,
Thanks so much.

Could you give me some tutorial on Window programming?
 
That's a pretty broad topic. :) I'd recommend getting a copy of
"Programming Windows" by Charles Petzold. It's all in C, but it's a great
intro book for the fundamentals of Win32 programming.

-Joel
--------------------
From: "Dean L. Howen" <[email protected]>
References: <#[email protected]>
<[email protected]>
Subject: Re: context menu
Date: Tue, 9 Nov 2004 11:11:29 +0700
Lines: 140
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.csharp
NNTP-Posting-Host: ci76-245.netnam.vn 203.162.76.245
Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09
phx.gbl
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.languages.csharp:285369
X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

Dear Joel,
Thanks so much.

Could you give me some tutorial on Window programming?

This reply is provided AS IS, without warranty (express or implied).
 
Back
Top