zoukankan      html  css  js  c++  java
  • 一个简单的通用面板和菜单类

    下面是该类的具体实现:

    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

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

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

  • 相关阅读:
    Gym 100989E
    解决Pycharm无法导入包问题 Unresolved reference
    模块介绍/time/os...
    列表/元组/字符串/字典/集合/文件/字符编码
    迭代器/生成器/装饰器 /Json & pickle 数据序列化
    network / shuangwangka / inner + outer
    performance python httprunner
    performance python locust
    web sec / fastjson safemode
    python 向下取整,向上取整,四舍五入
  • 原文地址:https://www.cnblogs.com/ethanwill/p/3250120.html
Copyright © 2011-2022 走看看