窗口?为何具有焦点时,父窗体不是去焦点? 
应该只有对mdi子窗体,才是这样的

解决方案 »

  1.   

    菜单使用的是一种叫做浮动控件的技术,本身类似于mdi与子窗体的结构
    子窗口获得焦点时实际上并不直接接受windows消息,而由父窗体将消息传递给子窗体
    tooltip是一个游离得浮动控件,这一点在delphi中显而易见。可能文不对题,请详细提出疑问,以便回答。不知1000分可否笔误
      

  2.   

    magic可以自己做菜单,但是,看的头都大了,谁能给些注释也好
      

  3.   

    如果是webform,你下载下面连接的软件就可以完成菜单得开发
    http://www.onlinedown.net/soft/5942.htm
    另外不知道你需要什么样的tooltip
      

  4.   

    自己完全可以写菜单。你可以自己画一个控件(从UserControl继承),然后再在这个控件的控件集(Controls属性)里面添加控件作为菜单项,所以无论你做什么形状的菜单都是可以的。
      

  5.   

    1.winform
    2.从UserControl继承,不行.
      

  6.   

    窗体和控件的结合体吧。
    反正这个是人家的成果,他们想怎么写就怎么写。我们又拿不到源代码,
    你看,如果你能把.net 2003的界面做出来(不用微软提供的东西),我想你也就能明白了。
      

  7.   

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;namespace MenuDemo
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private System.ComponentModel.IContainer components; private EastLibrary.Toolbar.ToolbarControl toolbarControl = null;
    internal System.Windows.Forms.ToolTip toolTip1;
    private System.Windows.Forms.ImageList imageList1;
    private EastLibrary.Toolbar.Toolbar toolbar = null;
    private EastLibrary.Toolbar.Toolbar toolbar1 = null;
    private EastLibrary.Toolbar.Toolbar toolbar2 = null;
    private EastLibrary.Toolbar.Toolbar toolbar3 = null;
    private System.Windows.Forms.ImageList imageList2;
    private System.Windows.Forms.ImageList imageList3;
    private EastLibrary.Toolbar.Toolbar toolbar4 = null; public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); toolbarControl = new EastLibrary.Toolbar.ToolbarControl();
    toolbarControl.Parent = this;
    EastLibrary.Menus.PopupMenu pm = new EastLibrary.Menus.PopupMenu();
    EastLibrary.Menus.MenuCommand mc1 = new EastLibrary.Menus.MenuCommand("ABCDEFG", this.imageList1, 0, new System.EventHandler(this.ButtonClick));
    EastLibrary.Menus.MenuCommand mc2 = new EastLibrary.Menus.MenuCommand("1234567", this.imageList1, 1, new System.EventHandler(this.ButtonClick));
    EastLibrary.Menus.MenuCommand mc3 = new EastLibrary.Menus.MenuCommand("ABCDEFG", this.imageList1, 2, new System.EventHandler(this.ButtonClick));
    EastLibrary.Menus.MenuCommand mc4 = new EastLibrary.Menus.MenuCommand("1234567", this.imageList1, 3, new System.EventHandler(this.ButtonClick));


    pm.MenuCommands.Add(mc1);
    pm.MenuCommands.Add(mc2);
    pm.MenuCommands.Add(mc3);
    pm.MenuCommands.Add(mc4);
    EastLibrary.Menus.MenuControl mc = new EastLibrary.Menus.MenuControl();
    mc.Parent = this; EastLibrary.Menus.MenuCommand mmc1 = new EastLibrary.Menus.MenuCommand("文件(&F)");
    EastLibrary.Menus.MenuCommand mmc2 = new EastLibrary.Menus.MenuCommand("编辑(&E)");
    EastLibrary.Menus.MenuCommand mmc3 = new EastLibrary.Menus.MenuCommand("视图(&V)");
    EastLibrary.Menus.MenuCommand mmc4 = new EastLibrary.Menus.MenuCommand("插入(&I)");
    EastLibrary.Menus.MenuCommand mmc5 = new EastLibrary.Menus.MenuCommand("格式(&O)");
    EastLibrary.Menus.MenuCommand mmc6 = new EastLibrary.Menus.MenuCommand("工具(&T)");
    EastLibrary.Menus.MenuCommand mmc7 = new EastLibrary.Menus.MenuCommand("表格(&A)");
    EastLibrary.Menus.MenuCommand mmc8 = new EastLibrary.Menus.MenuCommand("窗口(&W)");
    EastLibrary.Menus.MenuCommand mmc9 = new EastLibrary.Menus.MenuCommand("帮助(&H)"); mc.MenuCommands.Add(mmc1);
    mc.MenuCommands.Add(mmc2);
    mc.MenuCommands.Add(mmc3);
    mc.MenuCommands.Add(mmc4);
    mc.MenuCommands.Add(mmc5);
    mc.MenuCommands.Add(mmc7);
    mc.MenuCommands.Add(mmc8);
    mc.MenuCommands.Add(mmc9);
      

  8.   

    // 主菜单添加完毕 EastLibrary.Menus.MenuCommand mmc11 = new EastLibrary.Menus.MenuCommand("新建(&N)....             Ctrl+N", this.imageList2, 0);
    EastLibrary.Menus.MenuCommand mmc12 = new EastLibrary.Menus.MenuCommand("打开(&O)....             Ctrl+O", this.imageList2, 1);
    EastLibrary.Menus.MenuCommand mmc13 = new EastLibrary.Menus.MenuCommand("关闭(&E)",               this.imageList2, 2);

    EastLibrary.Menus.MenuCommand mmc14 = new EastLibrary.Menus.MenuCommand("-");
    EastLibrary.Menus.MenuCommand mmc15 = new EastLibrary.Menus.MenuCommand("保存(&S)                 Ctrl+O", this.imageList2, 3);
    EastLibrary.Menus.MenuCommand mmc16 = new EastLibrary.Menus.MenuCommand("另存为(&A)",                      this.imageList2, 4);
    EastLibrary.Menus.MenuCommand mmc17 = new EastLibrary.Menus.MenuCommand("另存Web页面(&G)                ", this.imageList2, 5);
    EastLibrary.Menus.MenuCommand mmc18 = new EastLibrary.Menus.MenuCommand("搜索(&H)                       ", this.imageList2, 6);
    EastLibrary.Menus.MenuCommand mmc110 = new EastLibrary.Menus.MenuCommand("-");
    EastLibrary.Menus.MenuCommand mmc111 = new EastLibrary.Menus.MenuCommand("版本                          ");
    EastLibrary.Menus.MenuCommand mmc112 = new EastLibrary.Menus.MenuCommand("-");
    EastLibrary.Menus.MenuCommand mmc113 = new EastLibrary.Menus.MenuCommand("Web预览");
    EastLibrary.Menus.MenuCommand mmc114 = new EastLibrary.Menus.MenuCommand("-");
    EastLibrary.Menus.MenuCommand mmc115 = new EastLibrary.Menus.MenuCommand("退出(&X)                 ", this.imageList2,7,new System.EventHandler(this.ButtonClick));


    mmc1.MenuCommands.Add(mmc11);
    mmc1.MenuCommands.Add(mmc12);
    mmc1.MenuCommands.Add(mmc13);
            mmc1.MenuCommands.Add(mmc14);
                mmc1.MenuCommands.Add(mmc15);     
    mmc1.MenuCommands.Add(mmc16); mmc1.MenuCommands.Add(mmc17);
    mmc1.MenuCommands.Add(mmc18);
            mmc1.MenuCommands.Add(mmc110);
    mmc1.MenuCommands.Add(mmc111);
    mmc1.MenuCommands.Add(mmc112);
    mmc1.MenuCommands.Add(mmc113);     
    mmc1.MenuCommands.Add(mmc114);
    mmc1.MenuCommands.Add(mmc115);       //文件菜单添加完毕     //编辑菜单
    EastLibrary.Menus.MenuCommand mmc21 = new EastLibrary.Menus.MenuCommand("撤销(&U)            Ctrl+U", this.imageList2, 8);
    EastLibrary.Menus.MenuCommand mmc22 = new EastLibrary.Menus.MenuCommand("重复(&R)            Ctrl+R", this.imageList2, 9);
    EastLibrary.Menus.MenuCommand mmc23 = new EastLibrary.Menus.MenuCommand("-");
    EastLibrary.Menus.MenuCommand mmc24 = new EastLibrary.Menus.MenuCommand("复制(&S)            Ctrl+S", this.imageList2, 10);
        EastLibrary.Menus.MenuCommand mmc25 = new EastLibrary.Menus.MenuCommand("剪切(&C)            Ctrl+C", this.imageList2, 11);
    EastLibrary.Menus.MenuCommand mmc26 = new EastLibrary.Menus.MenuCommand("粘贴(&P)            Ctrl+P", this.imageList2, 12);
    EastLibrary.Menus.MenuCommand mmc27 = new EastLibrary.Menus.MenuCommand("选择性粘贴                ");
    EastLibrary.Menus.MenuCommand mmc28 = new EastLibrary.Menus.MenuCommand("-");
    EastLibrary.Menus.MenuCommand mmc29 = new EastLibrary.Menus.MenuCommand("清除                          ");
     

    EastLibrary.Menus.MenuCommand mmc29_1 = new EastLibrary.Menus.MenuCommand("格式                          ", this.imageList2, 13);
    EastLibrary.Menus.MenuCommand mmc29_2 = new EastLibrary.Menus.MenuCommand("内容                          ", this.imageList2, 14); mmc29.MenuCommands.Add(mmc29_1);
    mmc29.MenuCommands.Add(mmc29_2); EastLibrary.Menus.MenuCommand mmc210 = new EastLibrary.Menus.MenuCommand("全选");
    EastLibrary.Menus.MenuCommand mmc211 = new EastLibrary.Menus.MenuCommand("-");

    EastLibrary.Menus.MenuCommand mmc212 = new EastLibrary.Menus.MenuCommand("任务窗格"   , new System.EventHandler(this.ButtonClick)                    );
    mmc212.Checked=true;
    EastLibrary.Menus.MenuCommand mmc213 = new EastLibrary.Menus.MenuCommand("标尺"  ,new System.EventHandler(this.ButtonClick)                       );

    EastLibrary.Menus.MenuCommand mmc214 = new EastLibrary.Menus.MenuCommand("工具栏", new System.EventHandler(this.ButtonClick)                      );
        mmc214.Checked=true;          
    mmc2.MenuCommands.Add(mmc21);
    mmc2.MenuCommands.Add(mmc22);
    mmc2.MenuCommands.Add(mmc23);
    mmc2.MenuCommands.Add(mmc24);
    mmc2.MenuCommands.Add(mmc25);     
    mmc2.MenuCommands.Add(mmc26); mmc2.MenuCommands.Add(mmc27);
    mmc2.MenuCommands.Add(mmc28);
    mmc2.MenuCommands.Add(mmc29);     
    mmc2.MenuCommands.Add(mmc210);
    mmc2.MenuCommands.Add(mmc211);
    mmc2.MenuCommands.Add(mmc212);
    mmc2.MenuCommands.Add(mmc213);     
    mmc2.MenuCommands.Add(mmc214);
      

  9.   

    EastLibrary.Menus.MenuCommand mmc91 = new EastLibrary.Menus.MenuCommand("动态帮助               " , this.imageList2, 15 );
    EastLibrary.Menus.MenuCommand mmc92 = new EastLibrary.Menus.MenuCommand("-"                    );
    EastLibrary.Menus.MenuCommand mmc93 = new EastLibrary.Menus.MenuCommand("目录"   , this.imageList3, 0                    );
    EastLibrary.Menus.MenuCommand mmc94 = new EastLibrary.Menus.MenuCommand("索引"    , this.imageList3, 1                   );
    EastLibrary.Menus.MenuCommand mmc95 = new EastLibrary.Menus.MenuCommand("搜索"                       );
    EastLibrary.Menus.MenuCommand mmc96 = new EastLibrary.Menus.MenuCommand("-"                    );

    EastLibrary.Menus.MenuCommand mmc97 = new EastLibrary.Menus.MenuCommand("关于...." , new System.EventHandler(this.ButtonClick)                     );

    mmc9.MenuCommands.Add(mmc91);
    mmc9.MenuCommands.Add(mmc92);
    mmc9.MenuCommands.Add(mmc93);     
    mmc9.MenuCommands.Add(mmc94);
              mmc9.MenuCommands.Add(mmc95);
    mmc9.MenuCommands.Add(mmc96);
            mmc9.MenuCommands.Add(mmc97);
    toolbar = new EastLibrary.Toolbar.Toolbar(); EastLibrary.Toolbar.ToolbarButton tb1 = new EastLibrary.Toolbar.ToolbarButton(EastLibrary.Toolbar.ToolbarButtonStyle.PushButton, "AAAAA", this.imageList1, 0, new System.EventHandler(this.ButtonClick));
    EastLibrary.Toolbar.ToolbarButton tb2 = new EastLibrary.Toolbar.ToolbarButton(EastLibrary.Toolbar.ToolbarButtonStyle.PushButton, "BBBBB", this.imageList1, 1, new System.EventHandler(this.ButtonClick));
    EastLibrary.Toolbar.ToolbarButton tb3 = new EastLibrary.Toolbar.ToolbarButton(EastLibrary.Toolbar.ToolbarButtonStyle.PushButton, "CCCCC", this.imageList1, 2, new System.EventHandler(this.ButtonClick));
    EastLibrary.Toolbar.ToolbarButton tb4 = new EastLibrary.Toolbar.ToolbarButton(EastLibrary.Toolbar.ToolbarButtonStyle.Separator, "DDDDD", this.imageList1, 3, new System.EventHandler(this.ButtonClick));
    EastLibrary.Toolbar.ToolbarButton tb5 = new EastLibrary.Toolbar.ToolbarButton(EastLibrary.Toolbar.ToolbarButtonStyle.ToggleButton, "EEEEE", this.imageList1, 4);
    EastLibrary.Toolbar.ToolbarButton tb6 = new EastLibrary.Toolbar.ToolbarButton(EastLibrary.Toolbar.ToolbarButtonStyle.ToggleButton, "FFFFF", this.imageList1, 5);
    EastLibrary.Toolbar.ToolbarButton tb7 = new EastLibrary.Toolbar.ToolbarButton(EastLibrary.Toolbar.ToolbarButtonStyle.DropDownButton, "GGGGG", this.imageList1, 6, new System.EventHandler(this.ButtonClick), pm);
    EastLibrary.Toolbar.ToolbarButton tb8 = new EastLibrary.Toolbar.ToolbarButton(EastLibrary.Toolbar.ToolbarButtonStyle.Separator, "DDDDD", this.imageList1, 3, new System.EventHandler(this.ButtonClick));
    EastLibrary.Toolbar.ToolbarButton tb9 = new EastLibrary.Toolbar.ToolbarButton(EastLibrary.Toolbar.ToolbarButtonStyle.PushButton, "HHHHH", this.imageList1, 7, new System.EventHandler(this.ButtonClick));
    EastLibrary.Toolbar.ToolbarButton tb10 = new EastLibrary.Toolbar.ToolbarButton(EastLibrary.Toolbar.ToolbarButtonStyle.PushButton, "IIIII", this.imageList1, 8, new System.EventHandler(this.ButtonClick));
    EastLibrary.Toolbar.ToolbarButton tb11 = new EastLibrary.Toolbar.ToolbarButton(EastLibrary.Toolbar.ToolbarButtonStyle.DropDownButton, "JJJJJ", this.imageList1, 9, new System.EventHandler(this.ButtonClick));
    EastLibrary.Toolbar.ToolbarButton tb12 = new EastLibrary.Toolbar.ToolbarButton(EastLibrary.Toolbar.ToolbarButtonStyle.PushButton, "KKKKK", this.imageList1, 10, new System.EventHandler(this.ButtonClick));
    System.Windows.Forms.TextBox t1 = new TextBox();
    t1.BorderStyle = BorderStyle.None;
    t1.Height = 20;
    t1.Width = 80;
    EastLibrary.Toolbar.ToolbarButton tb13 = new EastLibrary.Toolbar.ToolbarButton(EastLibrary.Toolbar.ToolbarButtonStyle.Control, "KKKKK", t1);
    EastLibrary.Toolbar.ToolbarButton tb14 = new EastLibrary.Toolbar.ToolbarButton(EastLibrary.Toolbar.ToolbarButtonStyle.Separator, "KKKKK");
    EastLibrary.Toolbar.ToolbarButton tb15 = new EastLibrary.Toolbar.ToolbarButton(EastLibrary.Toolbar.ToolbarButtonStyle.PushButton, "EEEEE", this.imageList1, 11, new System.EventHandler(this.ButtonClick));
    EastLibrary.Toolbar.ToolbarButton tb16 = new EastLibrary.Toolbar.ToolbarButton(EastLibrary.Toolbar.ToolbarButtonStyle.PushButton, "FFFFF", this.imageList1, 12, new System.EventHandler(this.ButtonClick));
    EastLibrary.Toolbar.ToolbarButton tb17 = new EastLibrary.Toolbar.ToolbarButton(EastLibrary.Toolbar.ToolbarButtonStyle.DropDownButton, "GGGGG", this.imageList1, 13, new System.EventHandler(this.ButtonClick), pm);
    EastLibrary.Toolbar.ToolbarButton tb18 = new EastLibrary.Toolbar.ToolbarButton(EastLibrary.Toolbar.ToolbarButtonStyle.Separator, "DDDDD", this.imageList3, 0, new System.EventHandler(this.ButtonClick));
    EastLibrary.Toolbar.ToolbarButton tb19 = new EastLibrary.Toolbar.ToolbarButton(EastLibrary.Toolbar.ToolbarButtonStyle.PushButton, "HHHHH", this.imageList3, 1, new System.EventHandler(this.ButtonClick));

    toolbar.Buttons.Add(tb1);
    toolbar.Buttons.Add(tb2);
    toolbar.Buttons.Add(tb3);
    toolbar.Buttons.Add(tb4);
    toolbar.Buttons.Add(tb5);
    toolbar.Buttons.Add(tb6);
    toolbar.Buttons.Add(tb7);
    toolbar.Buttons.Add(tb8);
    toolbar.Buttons.Add(tb9);
    toolbar.Buttons.Add(tb10);
    toolbar.Buttons.Add(tb11);
    toolbar.Buttons.Add(tb12);
    toolbar.Buttons.Add(tb13);
    toolbar.Buttons.Add(tb14);
    toolbar.Buttons.Add(tb15);
    toolbar.Buttons.Add(tb16);
    toolbar.Buttons.Add(tb17);
    toolbar.Buttons.Add(tb18);
    toolbar.Buttons.Add(tb19);
    toolbar1 = new EastLibrary.Toolbar.Toolbar();
    EastLibrary.Toolbar.ToolbarButton tb21 = new EastLibrary.Toolbar.ToolbarButton(EastLibrary.Toolbar.ToolbarButtonStyle.PushButton, "EEEEE", this.imageList1, 16, new System.EventHandler(this.ButtonClick));
    EastLibrary.Toolbar.ToolbarButton tb22 = new EastLibrary.Toolbar.ToolbarButton(EastLibrary.Toolbar.ToolbarButtonStyle.PushButton, "EEEEE", this.imageList1, 17, new System.EventHandler(this.ButtonClick));
    toolbar1.Buttons.Add(tb21);
    toolbar1.Buttons.Add(tb22); toolbar2 = new EastLibrary.Toolbar.Toolbar();
    EastLibrary.Toolbar.ToolbarButton tb31 = new EastLibrary.Toolbar.ToolbarButton(EastLibrary.Toolbar.ToolbarButtonStyle.PushButton, "EEEEE", this.imageList1, 18, new System.EventHandler(this.ButtonClick));
    EastLibrary.Toolbar.ToolbarButton tb32 = new EastLibrary.Toolbar.ToolbarButton(EastLibrary.Toolbar.ToolbarButtonStyle.PushButton, "EEEEE", this.imageList1, 19, new System.EventHandler(this.ButtonClick));
    EastLibrary.Toolbar.ToolbarButton tb33 = new EastLibrary.Toolbar.ToolbarButton(EastLibrary.Toolbar.ToolbarButtonStyle.PushButton, "EEEEE", this.imageList1, 1, new System.EventHandler(this.ButtonClick));
    EastLibrary.Toolbar.ToolbarButton tb34 = new EastLibrary.Toolbar.ToolbarButton(EastLibrary.Toolbar.ToolbarButtonStyle.PushButton, "EEEEE", this.imageList1, 5, new System.EventHandler(this.ButtonClick));
    toolbar2.Buttons.Add(tb31);
    toolbar2.Buttons.Add(tb32);
    toolbar2.Buttons.Add(tb33);
    toolbar2.Buttons.Add(tb34);
      

  10.   

    //自绘菜单
    /* *************************************** 
     *           NiceMenu.cs (v 1.1)
     *  --------------------------------------
     *  This is an improvement by Francesco Natali ([email protected])
     *  over an improvement by Sajith M 
     *  of the "Visual Studio .NET Menu Style" 
     *  by Carlos H. Perez that appeared on CodeProject 
     *  (http://www.codeproject.com)
     * ---------------------------------------
     *      How to use it
     *  You have to add: 
     * using Utility.NiceMenu;
     *  and after the "InitializeComponent()" code:
     *  NiceMenu myNiceMenu = new NiceMenu();
     * myNiceMenu.UpdateMenu(this.nameofyourmainmenu, new NiceMenuClickEvent(nameofyourclickfunction));
     * ---------------------------------------
     *  With only three lines of code your menu
     *    will be AUTOMATICALLY updated with 
     *       a new great .Net style menu!
     * ****************************************/namespace Utility.NiceMenu
    {
    using System;
    using System.Windows.Forms;
    using System.Drawing;
    using System.Drawing.Text;
    using System.Diagnostics;
    using System.Collections; /* ******************************************************
     *   NiceMenuClickEvent(object sender, System.EventArgs e)
     * ------------------------------------------------------
     * this is a delegate event that will be initializate with
     *  the user function to handle the click event on the menu
     * ******************************************************/
    public delegate void NiceMenuClickEvent(object sender, System.EventArgs e);
    /* ******************************************************
     *  This is a simple example of a function 
     *  to handle the click event:  
     *  -----------------------------------------------------
        public void myClickMenuEvent(object sender, System.EventArgs e)
    {
       if (typeof(NiceMenu).IsInstanceOfType(sender)) 
    {
    NiceMenu item = (NiceMenu)sender;
    MessageBox.Show(item.Text); //example
    }
    }
     * ******************************************************/ /// <summary>
    /// A great and free improvement menu class!
    /// </summary>
    public class NiceMenu : MenuItem 
    {
    /* If you want to add some incons in your menu 
     * you have to:
     * 1. add an imagelist control in your form
     * 2. add your icons in your imagelist control
     * 3. add in your menu items the index of the icon 
     *    in the first two characters. For example:
     *    00New
     *    01Open
     *    02Close
     * 4. After the "NiceMenu myNiceMenu = new NiceMenu();" code
     *    you have to add this simple line of code: 
     *    myNiceMenu.imgMenu = nameofyourimagelist; 
     * */
    /// <summary>
    /// Set "MenuImages" with the your ImageList to add icons in your menu.
    /// </summary>
    public ImageList MenuImages; // NiceMenu array to save the main menu item
    // so at runtime i can search an item and modify it
    private static NiceMenu[] myModifyNiceMenu = new NiceMenu[20];
    private static NiceMenu[] myModifyContextNiceMenu = new NiceMenu[20];
    private static int contModify = 0;
    private static int contModifyContext = 0; private static Color window;
    // Some useful properties to change the color of your menu
    private static Color backcolor;
    private static Color barcolor;
    private static Color selectioncolor;
    private static Color framecolor;

    private static int iconSize = SystemInformation.SmallIconSize.Width + 5;
    private static int itemHeight;
    private static bool doColorUpdate = false;
    private string shortcuttext = "";
    private Image icon   = null;
    private static int BITMAP_SIZE = 16;
    private static int STRIPE_WIDTH = iconSize + 5;

    public NiceMenu() : base() 
    {
    OwnerDraw = true; UpdateColors();
    }

    private NiceMenu(string name) : base(name) 
    {
    OwnerDraw = true; UpdateColors();
    }
    // public for the AddRecentFile function
    public NiceMenu(string name, EventHandler handler) : base(name, handler) 
    {
    OwnerDraw = true; UpdateColors();
    } private NiceMenu(string name, NiceMenu[] items) : base(name, items) 
    {
    OwnerDraw = true; UpdateColors();
    } private NiceMenu(string name, EventHandler handler, Shortcut shortcut) : base(name, handler, shortcut) 
    {
    OwnerDraw = true; UpdateColors();
    } private NiceMenu(MenuMerge mergeType, int mergeOrder, Shortcut shortcut, string name, EventHandler onClick, EventHandler onPopup, EventHandler onSelect, NiceMenu[] items) : base(mergeType, mergeOrder, shortcut, name, onClick, onPopup, onSelect, items) 
    {
    OwnerDraw = true; UpdateColors();
    } private NiceMenu(string name, Image img) : this(name) 
    {
    icon = img;
    } private NiceMenu(string name, EventHandler handler, Image img) : this(name, handler) 
    {
    icon = img;
    }

    private NiceMenu(string name, EventHandler handler, Shortcut shortcut, Image img) : this(name, handler, shortcut) 
    {
    icon = img;
    }

    // ********************************************************* private Image Icon 
    {
    get 
    { return icon; }
    set 
    { icon = value; }
    } private string ShortcutText 
    {
    get 
    { return shortcuttext; }
    set 
    { shortcuttext = value; }
    } public Color SelectionColor
    {
    get
    { return selectioncolor; }
    set
    { selectioncolor = value; }
    } public Color BackColor
    {
    get
    { return backcolor; }
    set
    { backcolor = value; }
    } public Color BarColor
    {
    get
    { return barcolor; }
    set
    { barcolor = value; }
    } public Color FrameColor
    {
    get
    { return framecolor; }
    set
    { framecolor = value; }
    } //************************************************************************
      

  11.   

    private void UpdateColors() 
    {
    window = SystemColors.Window;
    backcolor  = SystemColors.ControlLightLight;
    barcolor = SystemColors.Control;
    selectioncolor  = SystemColors.Highlight;
    framecolor = SystemColors.Highlight; int wa = (int)window.A;
    int wr = (int)window.R;
    int wg = (int)window.G;
    int wb = (int)window.B; int mna = (int)backcolor.A;
    int mnr = (int)backcolor.R;
    int mng = (int)backcolor.G;
    int mnb = (int)backcolor.B; int sta = (int)barcolor.A;
    int str = (int)barcolor.R;
    int stg = (int)barcolor.G;
    int stb = (int)barcolor.B; int sla = (int)selectioncolor.A;
    int slr = (int)selectioncolor.R;
    int slg = (int)selectioncolor.G;
    int slb = (int)selectioncolor.B; backcolor = Color.FromArgb(wr-(((wr-mnr)*2)/5), wg-(((wg-mng)*2)/5), wb-(((wb-mnb)*2)/5));
    barcolor = Color.FromArgb(wr-(((wr-str)*4)/5), wg-(((wg-stg)*4)/5), wb-(((wb-stb)*4)/5));
    selectioncolor = Color.FromArgb(wr-(((wr-slr)*2)/5), wg-(((wg-slg)*2)/5), wb-(((wb-slb)*2)/5));
    } private static void UpdateMenuColors() 
    {            
    doColorUpdate = true;
    } private void DoUpdateMenuColors() 
    {
    UpdateColors();
    doColorUpdate = false;
    } protected override void OnMeasureItem(MeasureItemEventArgs e) 
    {
    base.OnMeasureItem(e);

    if (Shortcut != Shortcut.None) 
    {
    string text = "";
    int    key  = (int)Shortcut;
    int    ch   = key & 0xFF;
    if (((int)Keys.Control & key) > 0) text += "Ctrl+";
    if (((int)Keys.Shift & key) > 0) text += "Shift+";
    if (((int)Keys.Alt & key) > 0) text += "Alt+";

    if (ch >= (int)Shortcut.F1 && ch <= (int)Shortcut.F12)
    text += "F" + (ch - (int)Shortcut.F1 + 1);
    else 
    {
    if ( Shortcut == Shortcut.Del) 
    {
    text += "Del";
    }
    else 
    {
    text += (char)ch;
    }
    }
    shortcuttext = text;


    if (Text == "-") 
    {
    e.ItemHeight = 8;
    e.ItemWidth  = 4;
    return;
    }

    bool topLevel = Parent == Parent.GetMainMenu();
    string tempShortcutText = shortcuttext;
    if ( topLevel ) 
    {
    tempShortcutText = "";
    }
    int textwidth = (int)(e.Graphics.MeasureString(Text + tempShortcutText, SystemInformation.MenuFont).Width);
    int extraHeight = 4;
    e.ItemHeight  = SystemInformation.MenuHeight + extraHeight;
    if ( topLevel )
    e.ItemWidth  = textwidth - 5; 
    else
    e.ItemWidth   = Math.Max(160, textwidth + 50); itemHeight = e.ItemHeight;
    }

    protected override void OnDrawItem(DrawItemEventArgs e) 
    {
    if ( doColorUpdate) 
    {
    DoUpdateMenuColors();
    }

    base.OnDrawItem(e); Graphics  g      = e.Graphics;
    Rectangle bounds = e.Bounds;
    bool selected = (e.State & DrawItemState.Selected) > 0;
    bool toplevel = (Parent == Parent.GetMainMenu());
    bool hasicon  = Icon != null;
    bool enabled = Enabled;

    DrawBackground(g, bounds, e.State, toplevel, hasicon, enabled);
    if (hasicon)
    DrawIcon(g, Icon, bounds, selected, Enabled, Checked);
    else
    {
    if (Checked)
    DrawCheck(g, bounds, selected);
    if (RadioCheck)
    DrawRadioCheck(g, bounds, selected);
    }

    if (Text == "-") 
    { DrawSeparator(g, bounds); } 
    else 
    { DrawMenuText(g, bounds, Text, shortcuttext, Enabled, toplevel, e.State); }
    } /* ******************************
     * DrawRadioCheck
     * ******************************/
    private void DrawRadioCheck(Graphics g, Rectangle bounds, bool selected) 
    {
    int checkTop = bounds.Top + (itemHeight - BITMAP_SIZE)/2;
    int checkLeft = bounds.Left + ( STRIPE_WIDTH - BITMAP_SIZE)/2;
    ControlPaint.DrawMenuGlyph(g, new Rectangle(checkLeft, checkTop, BITMAP_SIZE, BITMAP_SIZE), MenuGlyph.Bullet);
    g.DrawRectangle(new Pen(framecolor), checkLeft-1, checkTop-1, BITMAP_SIZE+1, BITMAP_SIZE+1);
    }
    private void DrawCheck(Graphics g, Rectangle bounds, bool selected) 
    {
    int checkTop = bounds.Top + (itemHeight - BITMAP_SIZE)/2;
    int checkLeft = bounds.Left + ( STRIPE_WIDTH - BITMAP_SIZE)/2;
    ControlPaint.DrawMenuGlyph(g, new Rectangle(checkLeft, checkTop, BITMAP_SIZE, BITMAP_SIZE), MenuGlyph.Check);
    g.DrawRectangle(new Pen(framecolor), checkLeft-1, checkTop-1, BITMAP_SIZE+1, BITMAP_SIZE+1);
    }
    private void DrawIcon(Graphics g, Image icon, Rectangle bounds, bool selected, bool enabled, bool ischecked) 
    {
    int iconTop = bounds.Top + (itemHeight - BITMAP_SIZE)/2;
    int iconLeft = bounds.Left + (STRIPE_WIDTH - BITMAP_SIZE)/2;
    if (enabled) 
    {
    if (selected) 
    {
    ControlPaint.DrawImageDisabled(g, icon, iconLeft + 1, iconTop, Color.Black);
    g.DrawImage(icon, iconLeft, iconTop-1);

    else 
    {
    g.DrawImage(icon, iconLeft + 1, iconTop);
    }

    else 
    {
    ControlPaint.DrawImageDisabled(g, icon, iconLeft + 1, iconTop, SystemColors.HighlightText);
    }
    }

    private void DrawSeparator(Graphics g, Rectangle bounds) 
    {
    int y = bounds.Y + bounds.Height / 2;
    g.DrawLine(new Pen(SystemColors.ControlDark), bounds.X + iconSize + 7, y, bounds.X + bounds.Width - 2, y);
    }

    private void DrawBackground(Graphics g, Rectangle bounds, DrawItemState state, bool toplevel, bool hasicon, bool enabled) 
    {
    bool selected = (state & DrawItemState.Selected) > 0;

    if (selected || ((state & DrawItemState.HotLight) > 0)) 
    {
    if (toplevel && selected) 
    {
    bounds.Inflate(-1, 0);
    g.FillRectangle(new SolidBrush(barcolor), bounds);
    ControlPaint.DrawBorder3D(g, bounds.Left, bounds.Top, bounds.Width, bounds.Height, Border3DStyle.Flat, Border3DSide.Top | Border3DSide.Left | Border3DSide.Right);

    else 
    {
    if ( enabled ) 
    {
    g.FillRectangle(new SolidBrush(selectioncolor), bounds);
    g.DrawRectangle(new Pen(framecolor), bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1);
    }
    else 
    {
    g.FillRectangle(new SolidBrush(barcolor), bounds);
    bounds.X += STRIPE_WIDTH;
    bounds.Width -= STRIPE_WIDTH;
    g.FillRectangle(new SolidBrush(backcolor), bounds);
    }
    }

    else 
    {
    if (!toplevel) 
    {
    g.FillRectangle(new SolidBrush(barcolor), bounds);
    bounds.X += STRIPE_WIDTH;
    bounds.Width -= STRIPE_WIDTH;
    g.FillRectangle(new SolidBrush(backcolor), bounds);

    else 
    {
    g.FillRectangle(SystemBrushes.Control, bounds);
    }
    }
    }
      

  12.   

    private void DrawMenuText(Graphics g, Rectangle bounds, string text, string shortcut, bool enabled, bool toplevel, DrawItemState state )
    {
    StringFormat stringformat = new StringFormat();
    stringformat.HotkeyPrefix = ((state & DrawItemState.NoAccelerator) > 0) ? HotkeyPrefix.Hide : HotkeyPrefix.Show;

    if ( toplevel ) 
    {
    int index = text.IndexOf("&");
    if ( index != -1 ) 
    {
    text = text.Remove(index,1);
    }
    }

    int textwidth = (int)(g.MeasureString(text, SystemInformation.MenuFont).Width);
    int x = toplevel ? bounds.Left + (bounds.Width - textwidth) / 2: bounds.Left + iconSize + 10;
    int topGap = 4;
    if ( toplevel ) topGap = 2;
    int y = bounds.Top + topGap;
    Brush brush = null;

    if (!enabled)
    brush = new SolidBrush(SystemColors.GrayText);
    else 
    brush = new SolidBrush(SystemColors.MenuText);

    g.DrawString(text, SystemInformation.MenuFont, brush, x, y, stringformat); if ( !toplevel ) 
    {
    stringformat.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
    g.DrawString(shortcut, SystemInformation.MenuFont, brush, bounds.Width - 10 , bounds.Top + topGap, stringformat);
    }
    } /* ******************************************************
     * UpdateMenu(MainMenu yourOldMenu)
     * UpdateMenu(ContextMenu yourOldMenu)
     * ------------------------------------------------------
     * this function will update the user old menu
     * ******************************************************/
    /// <summary>
    /// this function will update your Main Menu.
    /// </summary>
    public void UpdateMenu(MainMenu yourOldMenu, NiceMenuClickEvent yourClickFunction)
    {
    IList myMenuList = new Menu.MenuItemCollection(yourOldMenu);
    BuildMenuTree(myMenuList, yourOldMenu, yourClickFunction);
    }
    /// <summary>
    /// this function will update your Context Menu.
    /// </summary>
    public void UpdateMenu(ContextMenu yourOldMenu, NiceMenuClickEvent yourClickFunction)
    {
    IList myMenuList = new Menu.MenuItemCollection(yourOldMenu);
    BuildMenuTree(myMenuList, yourOldMenu, yourClickFunction);
    }
    /* ***********************************************************
     * BuildMenuTree (IList myMenu, MenuItem parentMenu)
     * -----------------------------------------------------------
     * build the new submenu item 
     * ***********************************************************/
    private void BuildMenuTree(IList myMenu, MenuItem parentMenu, NiceMenuClickEvent yourClickFunction)
    {
    foreach (MenuItem myMenuItem in myMenu) 
    {
    // Declaration
    NiceMenu newSubMenu; string IndexImage = "";
    bool AddMenuImage = false;

    /* If in the first two characters of the menu item text 
     * there is a number I set AddMenuImage = true and the 
     * IndexImage to get the icon in the image list control. */
    if (myMenuItem.Text.Length > 2)
    {
    IndexImage = myMenuItem.Text.Substring(0,2);
    if (Char.IsNumber(IndexImage,1) == true)
    {
    AddMenuImage = true;
    // I have to delete first two characters
    myMenuItem.Text = myMenuItem.Text.Substring(2);
    }
    }
    if (AddMenuImage == true)
    newSubMenu = new NiceMenu(myMenuItem.Text, new EventHandler(yourClickFunction), myMenuItem.Shortcut, MenuImages.Images[Convert.ToInt32(IndexImage)]);
    else
    newSubMenu = new NiceMenu(myMenuItem.Text, new EventHandler(yourClickFunction), myMenuItem.Shortcut);
    // I add the new menu item to its parent
    parentMenu.MenuItems.Add(newSubMenu);
    // Checked 
    if (myMenuItem.Checked == true) newSubMenu.Checked = true;
    // RadioCheck 
    if (myMenuItem.RadioCheck == true) 
    if (myMenuItem.Checked == true) newSubMenu.RadioCheck = true;
    // DefaultItem 
    if (myMenuItem.DefaultItem == true) newSubMenu.DefaultItem = true;
    // Enabled
    if (myMenuItem.Enabled == false) newSubMenu.Enabled = false;
    // If this menu item contains child menu items
    if (myMenuItem.IsParent == true)
    {
    IList mySubMenu = new Menu.MenuItemCollection(myMenuItem);
    BuildMenuTree(mySubMenu, newSubMenu, yourClickFunction);
    }
    }
    }
      

  13.   

    类似于ComboBox控件的下拉列表,我也想知道。
    up
      

  14.   

    有点晕在
    windowForm下的toolBar
    可以很容易的完成你说的功能呀
    在不行也可以用第三方控件什么的
    绝对不是值1000分的问题,以到底要问什么