By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,312 Members | 1,248 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,312 IT Pros & Developers. It's quick & easy.

context menu

P: n/a
Dear friends,
Could we determine when context menu should appear?
Nov 16 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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.

"Dean L. Howen" <co*****@hotpop.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Dear friends,
Could we determine when context menu should appear?

Nov 16 '05 #2

P: n/a
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
----------------
"Champika Nirosh" <te**@test.lk> wrote in message
news:ep**************@TK2MSFTNGP09.phx.gbl...
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.

"Dean L. Howen" <co*****@hotpop.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Dear friends,
Could we determine when context menu should appear?


Nov 16 '05 #3

P: n/a
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" <co*****@hotpop.com>
References: <#V**************@TK2MSFTNGP09.phx.gbl> <ep**************@TK2MSFTNGP09.phx.gbl>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: <#v**************@tk2msftngp13.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.csharp
NNTP-Posting-Host: ci76-243.netnam.vn 203.162.76.243
Path: cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFT NGP08.phx.gbl!tk2msftngp13
.phx.gblXref: 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
----------------
"Champika Nirosh" <te**@test.lk> wrote in message
news:ep**************@TK2MSFTNGP09.phx.gbl...
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.

"Dean L. Howen" <co*****@hotpop.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
> Dear friends,
> Could we determine when context menu should appear?
>
>




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

Nov 16 '05 #4

P: n/a
Dear Joel,
Thanks so much.

Could you give me some tutorial on Window programming?

"Joel Hendrix [MSFT]" <no******@online.microsoft.com> wrote in message
news:a0**************@cpmsftngxa10.phx.gbl...
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" <co*****@hotpop.com>
References: <#V**************@TK2MSFTNGP09.phx.gbl> <ep**************@TK2MSFTNGP09.phx.gbl>
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: <#v**************@tk2msftngp13.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.csharp
NNTP-Posting-Host: ci76-243.netnam.vn 203.162.76.243
Path:

cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFT NGP08.phx.gbl!tk2msftngp13 phx.gbl
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.languages.csharp:284561X-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 disableall the menu items in context menu. So it's better if context menu not showin this situation
----------------
"Champika Nirosh" <te**@test.lk> wrote in message
news:ep**************@TK2MSFTNGP09.phx.gbl...
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.

"Dean L. Howen" <co*****@hotpop.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
> Dear friends,
> Could we determine when context menu should appear?
>
>



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

Nov 16 '05 #5

P: n/a
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" <co*****@hotpop.com>
References: <#V**************@TK2MSFTNGP09.phx.gbl> <ep**************@TK2MSFTNGP09.phx.gbl>
<#v**************@tk2msftngp13.phx.gbl>
<a0**************@cpmsftngxa10.phx.gbl>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: <Op**************@TK2MSFTNGP09.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.csharp
NNTP-Posting-Host: ci76-245.netnam.vn 203.162.76.245
Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl!TK2MSFT NGP08.phx.gbl!TK2MSFTNGP09
phx.gblXref: 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?

"Joel Hendrix [MSFT]" <no******@online.microsoft.com> wrote in message
news:a0**************@cpmsftngxa10.phx.gbl...
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" <co*****@hotpop.com>
>References: <#V**************@TK2MSFTNGP09.phx.gbl>

<ep**************@TK2MSFTNGP09.phx.gbl>
>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: <#v**************@tk2msftngp13.phx.gbl>
>Newsgroups: microsoft.public.dotnet.languages.csharp
>NNTP-Posting-Host: ci76-243.netnam.vn 203.162.76.243
>Path:

cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSF TNGP08.phx.gbl!tk2msftngp1

3
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 thanTreeView, >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, anddisable >all the menu items in context menu. So it's better if context menu notshow >in this situation
>
>
>----------------
>"Champika Nirosh" <te**@test.lk> wrote in message
>news:ep**************@TK2MSFTNGP09.phx.gbl...
>> 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 theContext >> menu and use the .Show method..
>>
>> Nirosh.
>>
>> "Dean L. Howen" <co*****@hotpop.com> wrote in message
>> news:%2****************@TK2MSFTNGP09.phx.gbl...
>> > Dear friends,
>> > Could we determine when context menu should appear?
>> >
>> >
>>
>>
>
>
>


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



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

Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.