FormSystemMenuDemo.cs
上传用户:dzysfj
上传日期:2021-09-14
资源大小:118k
文件大小:2k
源码类别:

菜单

开发平台:

C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using CSharpWin;
  9. using System.Diagnostics;
  10. namespace SystemMenuDemo
  11. {
  12.     public partial class FormSystemMenuDemo : Form
  13.     {
  14.         private SystemMenuNativeWindow _systemMenuNativeWindow;
  15.         public FormSystemMenuDemo()
  16.         {
  17.             InitializeComponent();
  18.             linkLabel1.Click += delegate(object sender, EventArgs e)
  19.             {
  20.                 Process.Start("www.csharpwin.com");
  21.             };
  22.         }
  23.         protected override void OnCreateControl()
  24.         {
  25.             base.OnCreateControl();
  26.             if (_systemMenuNativeWindow == null)
  27.             {
  28.                 _systemMenuNativeWindow = new SystemMenuNativeWindow(this);
  29.             }
  30.             _systemMenuNativeWindow.InertSeparator(7);
  31.             _systemMenuNativeWindow.InsertMenu(
  32.                 8,
  33.                 1001,
  34.                 "访问 www.csharpwin.com",
  35.                 delegate(object sender,EventArgs e)
  36.                 {
  37.                     Process.Start("www.csharpwin.com");
  38.                 });
  39.             _systemMenuNativeWindow.AppendSeparator();
  40.             _systemMenuNativeWindow.AppendMenu(
  41.                 1000,
  42.                 "关于...(&A)",
  43.                 delegate(object sender, EventArgs e)
  44.                 {
  45.                     AboutBox about = new AboutBox();
  46.                     about.ShowDialog();
  47.                 });
  48.         }
  49.         protected override void OnHandleDestroyed(EventArgs e)
  50.         {
  51.             base.OnHandleDestroyed(e);
  52.             if (_systemMenuNativeWindow != null)
  53.             {
  54.                 _systemMenuNativeWindow.Dispose();
  55.                 _systemMenuNativeWindow = null;
  56.             }
  57.         }
  58.         private void button1_Click(object sender, EventArgs e)
  59.         {
  60.             _systemMenuNativeWindow.Revert();
  61.         }
  62.     }
  63. }