I guess you can take two path..
One is attaching the context menu to the Control using the "ContextMen u"
property of the control or else.. you can create a object of the Context
menu and use the .Show method..
Nirosh.
"Dean L. Howen" <coldman@hotpop .com> wrote in message
news:%23Vp75mSw EHA.3620@TK2MSF TNGP09.phx.gbl. ..[color=blue]
> Dear friends,
> Could we determine when context menu should appear?
>
>[/color]
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" <test@test.lk > wrote in message
news:eplP8hWwEH A.3976@TK2MSFTN GP09.phx.gbl...[color=blue]
> Yes you can...
>
> I guess you can take two path..
> One is attaching the context menu to the Control using the "ContextMen u"
> property of the control or else.. you can create a object of the Context
> menu and use the .Show method..
>
> Nirosh.
>
> "Dean L. Howen" <coldman@hotpop .com> wrote in message
> news:%23Vp75mSw EHA.3620@TK2MSF TNGP09.phx.gbl. ..[color=green]
> > Dear friends,
> > Could we determine when context menu should appear?
> >
> >[/color]
>
>[/color]
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 SpecializedTree View : TreeView
{
private const int WM_CONTEXTMENU = 0x007B;
private bool contextMenuEnab led;
public SpecializedTree View()
{
this.contextMen uEnabled = true;
}
/// <summary>
/// Gets or sets a value to enable or disable the displaying of the
context menu for this control.
/// </summary>
public bool EnableContextMe nu
{
get
{
return this.contextMen uEnabled;
}
set
{
this.contextMen uEnabled = value;
}
}
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_CONTEXTMENU:
if (!this.contextM enuEnabled)
return;
break;
}
base.WndProc(re f m);
}
}
On the MouseDown event for the SpecializedTree View control I check if a
node was right-clicked:
// get the node that was clicked
TreeNode selectedNode = this.specialize dTreeView.GetNo deAt(e.X, e.Y);
This way the context menu is only displayed if a node is right-clicked.
hth
-Joel
--------------------[color=blue]
>From: "Dean L. Howen" <coldman@hotpop .com>
>References: <#Vp75mSwEHA.36 20@TK2MSFTNGP09 .phx.gbl>[/color]
<eplP8hWwEHA.39 76@TK2MSFTNGP09 .phx.gbl>[color=blue]
>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: <#vWq5sqwEHA.36 68@tk2msftngp13 .phx.gbl>
>Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
>NNTP-Posting-Host: ci76-243.netnam.vn 203.162.76.243
>Path:[/color]
cpmsftngxa10.ph x.gbl!TK2MSFTFE ED01.phx.gbl!TK 2MSFTNGP08.phx. gbl!tk2msftngp1 3
.phx.gbl[color=blue]
>Xref: cpmsftngxa10.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:2845 61
>X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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" <test@test.lk > wrote in message
>news:eplP8hWwE HA.3976@TK2MSFT NGP09.phx.gbl.. .[color=green]
>> Yes you can...
>>
>> I guess you can take two path..
>> One is attaching the context menu to the Control using the "ContextMen u"
>> property of the control or else.. you can create a object of the Context
>> menu and use the .Show method..
>>
>> Nirosh.
>>
>> "Dean L. Howen" <coldman@hotpop .com> wrote in message
>> news:%23Vp75mSw EHA.3620@TK2MSF TNGP09.phx.gbl. ..[color=darkred]
>> > Dear friends,
>> > Could we determine when context menu should appear?
>> >
>> >[/color]
>>
>>[/color]
>
>
>[/color]
This reply is provided AS IS, without warranty (express or implied).
Could you give me some tutorial on Window programming?
"Joel Hendrix [MSFT]" <noparity@onlin e.microsoft.com > wrote in message
news:a0kd0zdxEH A.2916@cpmsftng xa10.phx.gbl...[color=blue]
> 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 SpecializedTree View : TreeView
> {
> private const int WM_CONTEXTMENU = 0x007B;
> private bool contextMenuEnab led;
>
> public SpecializedTree View()
> {
> this.contextMen uEnabled = true;
> }
>
> /// <summary>
> /// Gets or sets a value to enable or disable the displaying of the
> context menu for this control.
> /// </summary>
> public bool EnableContextMe nu
> {
> get
> {
> return this.contextMen uEnabled;
> }
> set
> {
> this.contextMen uEnabled = value;
> }
> }
>
> protected override void WndProc(ref Message m)
> {
> switch (m.Msg)
> {
> case WM_CONTEXTMENU:
> if (!this.contextM enuEnabled)
> return;
>
> break;
> }
>
> base.WndProc(re f m);
> }
> }
>
> On the MouseDown event for the SpecializedTree View control I check if a
> node was right-clicked:
>
> // get the node that was clicked
> TreeNode selectedNode = this.specialize dTreeView.GetNo deAt(e.X, e.Y);
>
> if(selectedNode != null && e.Button == MouseButtons.Ri ght)
> {
> this.specialize dTreeView.Enabl eContextMenu = true;
> }
> else
> {
> this.specialize dTreeView.Enabl eContextMenu = false;
> }
>
> This way the context menu is only displayed if a node is right-clicked.
>
> hth
>
> -Joel
>
> --------------------[color=green]
> >From: "Dean L. Howen" <coldman@hotpop .com>
> >References: <#Vp75mSwEHA.36 20@TK2MSFTNGP09 .phx.gbl>[/color]
> <eplP8hWwEHA.39 76@TK2MSFTNGP09 .phx.gbl>[color=green]
> >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: <#vWq5sqwEHA.36 68@tk2msftngp13 .phx.gbl>
> >Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
> >NNTP-Posting-Host: ci76-243.netnam.vn 203.162.76.243
> >Path:[/color]
>[/color]
cpmsftngxa10.ph x.gbl!TK2MSFTFE ED01.phx.gbl!TK 2MSFTNGP08.phx. gbl!tk2msftngp1 3[color=blue]
> phx.gbl[color=green]
> >Xref: cpmsftngxa10.ph x.gbl[/color][/color]
microsoft.publi c.dotnet.langua ges.csharp:2845 61[color=blue][color=green]
> >X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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[/color][/color]
TreeView,[color=blue][color=green]
> >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[/color][/color]
disable[color=blue][color=green]
> >all the menu items in context menu. So it's better if context menu not[/color][/color]
show[color=blue][color=green]
> >in this situation
> >
> >
> >----------------
> >"Champika Nirosh" <test@test.lk > wrote in message
> >news:eplP8hWwE HA.3976@TK2MSFT NGP09.phx.gbl.. .[color=darkred]
> >> Yes you can...
> >>
> >> I guess you can take two path..
> >> One is attaching the context menu to the Control using the[/color][/color][/color]
"ContextMen u"[color=blue][color=green][color=darkred]
> >> property of the control or else.. you can create a object of the[/color][/color][/color]
Context[color=blue][color=green][color=darkred]
> >> menu and use the .Show method..
> >>
> >> Nirosh.
> >>
> >> "Dean L. Howen" <coldman@hotpop .com> wrote in message
> >> news:%23Vp75mSw EHA.3620@TK2MSF TNGP09.phx.gbl. ..
> >> > Dear friends,
> >> > Could we determine when context menu should appear?
> >> >
> >> >
> >>
> >>[/color]
> >
> >
> >[/color]
>
> This reply is provided AS IS, without warranty (express or implied).
>[/color]
That's a pretty broad topic. :) I'd recommend getting a copy of
"Programmin g Windows" by Charles Petzold. It's all in C, but it's a great
intro book for the fundamentals of Win32 programming.
-Joel
--------------------[color=blue]
>From: "Dean L. Howen" <coldman@hotpop .com>
>References: <#Vp75mSwEHA.36 20@TK2MSFTNGP09 .phx.gbl>[/color]
<eplP8hWwEHA.39 76@TK2MSFTNGP09 .phx.gbl>
<#vWq5sqwEHA.36 68@tk2msftngp13 .phx.gbl>
<a0kd0zdxEHA.29 16@cpmsftngxa10 .phx.gbl>[color=blue]
>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: <Op5gYJhxEHA.14 52@TK2MSFTNGP09 .phx.gbl>
>Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
>NNTP-Posting-Host: ci76-245.netnam.vn 203.162.76.245
>Path:[/color]
cpmsftngxa10.ph x.gbl!TK2MSFTNG XA03.phx.gbl!TK 2MSFTNGP08.phx. gbl!TK2MSFTNGP0 9
phx.gbl[color=blue]
>Xref: cpmsftngxa10.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:2853 69
>X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
>
>Dear Joel,
>Thanks so much.
>
>Could you give me some tutorial on Window programming?
>
>"Joel Hendrix [MSFT]" <noparity@onlin e.microsoft.com > wrote in message
>news:a0kd0zdxE HA.2916@cpmsftn gxa10.phx.gbl.. .[color=green]
>> I have an application where that does the same thing. The solution that[/color][/color]
I[color=blue][color=green]
>> 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[/color][/color]
subclassed[color=blue][color=green]
>> TreeView:
>>
>> public class SpecializedTree View : TreeView
>> {
>> private const int WM_CONTEXTMENU = 0x007B;
>> private bool contextMenuEnab led;
>>
>> public SpecializedTree View()
>> {
>> this.contextMen uEnabled = true;
>> }
>>
>> /// <summary>
>> /// Gets or sets a value to enable or disable the displaying of the
>> context menu for this control.
>> /// </summary>
>> public bool EnableContextMe nu
>> {
>> get
>> {
>> return this.contextMen uEnabled;
>> }
>> set
>> {
>> this.contextMen uEnabled = value;
>> }
>> }
>>
>> protected override void WndProc(ref Message m)
>> {
>> switch (m.Msg)
>> {
>> case WM_CONTEXTMENU:
>> if (!this.contextM enuEnabled)
>> return;
>>
>> break;
>> }
>>
>> base.WndProc(re f m);
>> }
>> }
>>
>> On the MouseDown event for the SpecializedTree View control I check if a
>> node was right-clicked:
>>
>> // get the node that was clicked
>> TreeNode selectedNode = this.specialize dTreeView.GetNo deAt(e.X, e.Y);
>>
>> if(selectedNode != null && e.Button == MouseButtons.Ri ght)
>> {
>> this.specialize dTreeView.Enabl eContextMenu = true;
>> }
>> else
>> {
>> this.specialize dTreeView.Enabl eContextMenu = false;
>> }
>>
>> This way the context menu is only displayed if a node is right-clicked.
>>
>> hth
>>
>> -Joel
>>
>> --------------------[color=darkred]
>> >From: "Dean L. Howen" <coldman@hotpop .com>
>> >References: <#Vp75mSwEHA.36 20@TK2MSFTNGP09 .phx.gbl>[/color]
>> <eplP8hWwEHA.39 76@TK2MSFTNGP09 .phx.gbl>[color=darkred]
>> >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: <#vWq5sqwEHA.36 68@tk2msftngp13 .phx.gbl>
>> >Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
>> >NNTP-Posting-Host: ci76-243.netnam.vn 203.162.76.243
>> >Path:[/color]
>>[/color]
>cpmsftngxa10.p hx.gbl!TK2MSFTF EED01.phx.gbl!T K2MSFTNGP08.phx .gbl!tk2msftngp 1[/color]
3[color=blue][color=green]
>> phx.gbl[color=darkred]
>> >Xref: cpmsftngxa10.ph x.gbl[/color][/color]
>microsoft.publ ic.dotnet.langu ages.csharp:284 561[color=green][color=darkred]
>> >X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp
>> >
>> >Yeah, I could.
>> >But I want sometime the context menu disappears (I could find the[/color][/color][/color]
support[color=blue][color=green][color=darkred]
>> >method).
>> >Why?
>> >For example, I want the context menu work on TreeNode rather than[/color][/color]
>TreeView,[color=green][color=darkred]
>> >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[/color][/color]
>disable[color=green][color=darkred]
>> >all the menu items in context menu. So it's better if context menu not[/color][/color]
>show[color=green][color=darkred]
>> >in this situation
>> >
>> >
>> >----------------
>> >"Champika Nirosh" <test@test.lk > wrote in message
>> >news:eplP8hWwE HA.3976@TK2MSFT NGP09.phx.gbl.. .
>> >> Yes you can...
>> >>
>> >> I guess you can take two path..
>> >> One is attaching the context menu to the Control using the[/color][/color]
>"ContextMenu "[color=green][color=darkred]
>> >> property of the control or else.. you can create a object of the[/color][/color]
>Context[color=green][color=darkred]
>> >> menu and use the .Show method..
>> >>
>> >> Nirosh.
>> >>
>> >> "Dean L. Howen" <coldman@hotpop .com> wrote in message
>> >> news:%23Vp75mSw EHA.3620@TK2MSF TNGP09.phx.gbl. ..
>> >> > Dear friends,
>> >> > Could we determine when context menu should appear?
>> >> >
>> >> >
>> >>
>> >>
>> >
>> >
>> >[/color]
>>
>> This reply is provided AS IS, without warranty (express or implied).
>>[/color]
>
>
>[/color]
This reply is provided AS IS, without warranty (express or implied).
Comment