您的位置:程序门 -> .net技术 -> c#



c#中notifyicon的contextmenu为什么出现右边呢?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


c#中notifyicon的contextmenu为什么出现右边呢?
发表于:2007-04-01 17:03:22 楼主
notifyicon的contextmenu设定好关联的contextmenu后右击为什么出现右边呢?
在托盘区的其他程序右击出现的菜单都在左边啊,请问怎么设置才能使其出现在右边?(不会贴图,请您自己试一下托盘区的图标,右击看看菜单的位置;再试试c#中的notifyicon),等待解决中!谢谢了.有知道的告诉一下……
发表于:2007-04-01 17:21:581楼 得分:0
自己顶一下…
发表于:2007-04-01 17:25:562楼 得分:0
我的在左边.
发表于:2007-04-01 18:02:113楼 得分:0
给你看看源代码:

public   class   frmlogin   :   system.windows.forms.form
{
private   system.windows.forms.label   lblselectoption;
private   system.windows.forms.combobox   cbooption;
private   system.windows.forms.notifyicon   ntibooks;
private   system.windows.forms.contextmenu   cmumouseright;
private   system.windows.forms.menuitem   mnuexit;
private   system.componentmodel.icontainer   components;

public   frmlogin()
{
initializecomponent();
}

///   <summary>
///   清理所有正在使用的资源。
///   </summary>
protected   override   void   dispose(   bool   disposing   )
{
if(   disposing   )
{
if   (components   !=   null)  
{
components.dispose();
}
}
base.dispose(   disposing   );
}

#region   windows   窗体设计器生成的代码
///   <summary>
///   设计器支持所需的方法   -   不要使用代码编辑器修改
///   此方法的内容。
///   </summary>
private   void   initializecomponent()
{
this.components   =   new   system.componentmodel.container();
system.resources.resourcemanager   resources   =   new   system.resources.resourcemanager(typeof(frmlogin));
this.lblselectoption   =   new   system.windows.forms.label();
this.cbooption   =   new   system.windows.forms.combobox();
this.ntibooks   =   new   system.windows.forms.notifyicon(this.components);
this.cmumouseright   =   new   system.windows.forms.contextmenu();
this.mnuexit   =   new   system.windows.forms.menuitem();
this.suspendlayout();
//  
//   lblselectoption
//  
this.lblselectoption.location   =   new   system.drawing.point(43,   51);
this.lblselectoption.name   =   "lblselectoption ";
this.lblselectoption.size   =   new   system.drawing.size(80,   23);
this.lblselectoption.tabindex   =   0;
this.lblselectoption.text   =   "选择选项: ";
this.lblselectoption.textalign   =   system.drawing.contentalignment.middleleft;
//  
//   cbooption
//  
this.cbooption.dropdownstyle   =   system.windows.forms.comboboxstyle.dropdownlist;
this.cbooption.items.addrange(new   object[]   {
      "选择1 ",
      "选择2 "});
this.cbooption.location   =   new   system.drawing.point(112,   51);
this.cbooption.name   =   "cbooption ";
this.cbooption.size   =   new   system.drawing.size(128,   20);
this.cbooption.tabindex   =   1;
this.cbooption.selectedindexchanged   +=   new   system.eventhandler(this.cbooption_selectedindexchanged);
//  
//   ntibooks
//  
this.ntibooks.contextmenu   =   this.cmumouseright;
this.ntibooks.icon   =   ((system.drawing.icon)(resources.getobject( "ntibooks.icon ")));
this.ntibooks.text   =   "notifyicon测试 ";
this.ntibooks.visible   =   true;
this.ntibooks.mousedown   +=   new   system.windows.forms.mouseeventhandler(this.ntibooks_mousedown);
//  
//   cmumouseright
//  
this.cmumouseright.menuitems.addrange(new   system.windows.forms.menuitem[]   {
    this.mnuexit});
//  
//   mnuexit
//  
this.mnuexit.index   =   0;
this.mnuexit.text   =   "退出(&e) ";
this.mnuexit.click   +=   new   system.eventhandler(this.exit);
//  
//   frmlogin
//  
this.autoscalebasesize   =   new   system.drawing.size(6,   14);
this.clientsize   =   new   system.drawing.size(294,   125);
this.controls.add(this.cbooption);
this.controls.add(this.lblselectoption);
this.formborderstyle   =   system.windows.forms.formborderstyle.fixeddialog;
this.icon   =   ((system.drawing.icon)(resources.getobject( "$this.icon ")));
this.maximizebox   =   false;
this.name   =   "frmlogin ";
this.startposition   =   system.windows.forms.formstartposition.centerscreen;
this.text   =   "notifyicon测试 ";
this.resumelayout(false);

}
#endregion

///   <summary>
///   应用程序的主入口点。
///   </summary>
[stathread]
static   void   main()  
{
application.run(new   frmlogin());
}

private   void   cbooption_selectedindexchanged(object   sender,   system.eventargs   e)
{
switch(cbooption.selectedindex)
{
case   0:
this.visible   =   false;
messagebox.show( "测试用对话框1 ");
break;
case   1:
this.visible   =   false;
messagebox.show( "测试用对话框2 ");                                     break;
default:
break;
}
}

private   void   exit(object   sender,   system.eventargs   e)
{
application.exit();
}

private   void   ntibooks_mousedown(object   sender,   system.windows.forms.mouseeventargs   e)
{
if   (e.button==mousebuttons.left   &   e.clicks   ==   2)
{
if   (!this.visible)
{
this.visible   =   true;
}
if   (this.windowstate   ==   formwindowstate.minimized)
{
this.windowstate   =   formwindowstate.normal;
}
this.activate();
}
}
}
发表于:2007-04-01 23:33:184楼 得分:0
怎么?没人知道吗?
算了,求人不如求自己........
发表于:2007-04-02 21:11:265楼 得分:0
怪了,我把自己的这段代码放到win2000的系统上运行就正常了……(本人的系统是winxp)
怎么?系统搞的鬼???????还是环境对象的过?………
发表于:2007-04-12 13:07:246楼 得分:0
你托盘里其他图标的菜单往哪个方向,   这好像是系统管理的吧.   不过都不影响使用吧.
不知道楼主是不是要做特殊用途.
发表于:2007-04-12 13:08:477楼 得分:0
帮顶..
发表于:2007-04-12 13:13:358楼 得分:0
什么意思?

上下文菜单默认就是出现在右边的,只有右边的空间不够,放不下的时候才会出现在左边,楼主到底想告诉我们什么?
发表于:2007-04-12 13:15:179楼 得分:0
你要它出现在左边把菜单搞大一点就行了,年度搞笑贴?
发表于:2007-04-12 13:21:1410楼 得分:0
2007年度最搞笑贴。
菜单的位置是由系统控制而不是由程序控制。如楼上所说,只有右边空间不够了,系统才会把菜单画到左边,就像目标下面的空间不够,菜单就会把菜单画到上面一样!


快速检索

最新资讯
热门点击