• 一个简单的通用面板和菜单类


    下面是该类的具体实现:

    using System;
    using System.Linq;
    using System.Collections.Generic;
    using System.Collections;
    using System.Text;
    using System.ComponentModel;
    using System.Windows.Forms;
    
    namespace LPGMobileDevice
    {
        class PanelMenu
        {
            private Panel panel;
    
            public Panel Panel
            {
                get { return panel; }
               
            }
            private MainMenu menu;
    
            public MainMenu Menu
            {
                get { return menu; }
                
            }
            private MenuItem mi_Main, mi_Exit;
    
            public MenuItem Mi_Main
            {
                get { return mi_Main; }
            }
    
            public MenuItem Mi_Exit
            {
                get { return mi_Exit; }
                
            }
    
            public PanelMenu()
            {
                panel = new Panel();
                //System.Drawing.Point point=new System.Drawing.Point(0,0);
                //panel.Location = point;
                System.Drawing.Size size = new System.Drawing.Size(240, 25);
                panel.Size = size;
                menu = new MainMenu();
                mi_Main = new MenuItem();
                mi_Main.Text = "主页";
                mi_Exit = new MenuItem();
                mi_Exit.Text = "退出";
                menu.MenuItems.Add(mi_Main);
                menu.MenuItems.Add(mi_Exit);
                mi_Main.Click += new EventHandler(Main);
                mi_Exit.Click+=new EventHandler(Exit);
            }
    
            private void Main(object sender, EventArgs e)
            {
                MainForm mf = new MainForm();
                mf.ShowDialog();
            }
    
            private void Exit(object sender, EventArgs e)
            {
                //Application.Exit();
                System.Diagnostics.Process.GetCurrentProcess().Kill();
            }
            
        }
    }
    PanelMenu类

    在其他窗体中调用:

    PanelMenu pm = new PanelMenu();
                this.Menu = pm.Menu;
                this.Controls.Add(pm.Panel);
    View Code

    代码重用能减少大量的控件拖拽和事件的编写。

    但我感觉还是有更方便使用的方法,望各位指导!

  • 相关阅读:
    java 线程的终止与线程中断
    java 线程协作 wait(等待)与 notiy(通知)
    java 线程协作 yield()
    java 线程协作 join()
    python学习 文件操作
    linux 学习 常用命令
    linux 学习 设置固定网Ip
    web 安全
    MySQL数据物理备份之tar打包备份
    MySQL数据物理备份之lvm快照
  • 原文地址:https://www.cnblogs.com/ethanwill/p/3250120.html
Copyright © 2020-2023  润新知