zoukankan      html  css  js  c++  java
  • 一个比较完整的WindowsFormsApplication实现

    这是前两天课堂上的例子,提供了一个自定义WindowsFormsApplication的范例,主要包括如下的功能

    1. 单一实例

    2. 闪屏

    3. 登陆窗口

    4. 任务栏图标和菜单

    需要注意的是,WindowsFormsApplicationBase这个类是要添加Microsoft.VisualBisic.dll引用的

        class MyApplication : WindowsFormsApplicationBase
        {
            NotifyIcon taskBarIcon;
            public MyApplication(bool singleton)
                : base(AuthenticationMode.ApplicationDefined)
            {
                //设置单实例
                this.IsSingleInstance = true;
    
                
                //添加任务栏按钮
                taskBarIcon = new NotifyIcon();
                taskBarIcon.Icon = Properties.Resources.Northwind;
                ContextMenuStrip contextMenu = new ContextMenuStrip();
                contextMenu.Items.Add(
                    new ToolStripMenuItem(
                        "退出",
                        Properties.Resources.close,
                        (sender, eventArgs) =>
                        {
                            if (MessageBox.Show(
                                "你是否真的要退出?",
                                "确认",
                                MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question,
                                MessageBoxDefaultButton.Button2)
                                == DialogResult.Yes)
                            {
                                Application.Exit();
                            }
                        }));
                contextMenu.Items.Add(
                    new ToolStripMenuItem(
                        "帮助",
                        Properties.Resources.help,
                        (sender, eventArgs) =>
                        {
                            MessageBox.Show("帮助文档还在制作中");
                        }));
    
                taskBarIcon.ContextMenuStrip = contextMenu;
                taskBarIcon.ShowBalloonTip(2000, "欢迎", "欢迎使用该软件", ToolTipIcon.Info);
                taskBarIcon.Visible = true;
            }
    
            public MyApplication() : this(true) { }
    
            protected override void OnCreateSplashScreen()
            {
                base.OnCreateSplashScreen();
    
                LoginForm login = new LoginForm();
                if (login.ShowDialog() != DialogResult.OK)
                {
                    Environment.Exit(-1);//这里不能用Application.Exit,因为当前是一个自定义的Application
                }
    
                this.MinimumSplashScreenDisplayTime = 2000;//最少显示两秒
                this.SplashScreen = new SplashForm();
    
            }
    
    
    
    
            protected override void OnShutdown()
            {
                base.OnShutdown();
                taskBarIcon.Dispose();
    
            }
            protected override void OnStartupNextInstance(StartupNextInstanceEventArgs eventArgs)
            {
                base.OnStartupNextInstance(eventArgs);
                eventArgs.BringToForeground = true;
            }
    
    
    
            protected override void OnCreateMainForm()
            {
                base.OnCreateMainForm();
    
                this.MainForm = new MainForm();
            }
        }
  • 相关阅读:
    django中itsdangerous的用法
    Django之跨域请求同源策略
    django中如何建立抽象型数据库作为父模块可继承其功能
    cookie,session 的概念以及在django中的用法,以及cbv装饰器用法
    django开发日志配置
    RESTful API概念解析
    django Rest Framework---缓存通过drf-extensions扩展来实现
    匿名内部类
    android app出现红叉
    Failed to resolve: com.android.support:appcompat-v7:27.+
  • 原文地址:https://www.cnblogs.com/chenxizhang/p/1699358.html
Copyright © 2011-2022 走看看