⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 menutest.cs

📁 this is a good book for the visual c#
💻 CS
📖 第 1 页 / 共 2 页
字号:
// Fig 13.4: MenuTest.cs
// Using menus to change font colors and styles.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace UsingMenus
{
   /// <summary>
   /// allows user to change font characteristics of text
   /// through interaction with a menu
   /// </summary>
   public class MenuTest : System.Windows.Forms.Form
   {
      // display label
      private System.Windows.Forms.Label displayLabel;

      // main menu (contains file and format menu)
      private System.Windows.Forms.MainMenu mainMenu;
      
      // file menu
      private System.Windows.Forms.MenuItem fileMenuItem;
      private System.Windows.Forms.MenuItem aboutMenuItem;
      private System.Windows.Forms.MenuItem exitMenuItem;

      // format menu
      private System.Windows.Forms.MenuItem formatMenuItem;

      // color submenu
      private System.Windows.Forms.MenuItem colorMenuItem;
      private System.Windows.Forms.MenuItem blackMenuItem;
      private System.Windows.Forms.MenuItem blueMenuItem;
      private System.Windows.Forms.MenuItem redMenuItem;
      private System.Windows.Forms.MenuItem greenMenuItem;

      // font submenu
      private System.Windows.Forms.MenuItem timesMenuItem;
      private System.Windows.Forms.MenuItem courierMenuItem;
      private System.Windows.Forms.MenuItem comicMenuItem;
      private System.Windows.Forms.MenuItem boldMenuItem;
      private System.Windows.Forms.MenuItem italicMenuItem;
      private System.Windows.Forms.MenuItem fontMenuItem;

      
      private System.Windows.Forms.MenuItem separatorMenuItem;
      /// <summary>
      /// Required designer variable.
      /// </summary>
      private 
         System.ComponentModel.Container components = null;

      // default constructor
      public MenuTest()
      {
         //
         // Required for Windows Form Designer support
         //
         InitializeComponent();

      }

      /// <summary>
      /// Clean up any resources being used.
      /// </summary>
      protected override void Dispose( bool disposing )
      {
         if( disposing )
         {
            if (components != null) 
            {
               components.Dispose();
            }
         }
         base.Dispose( disposing );
      }

      #region Windows Form Designer generated code
      /// <summary>
      /// Required method for Designer support - do not modify
      /// the contents of this method with the code editor.
      /// </summary>
      private void InitializeComponent()
      {
         this.displayLabel = new System.Windows.Forms.Label();
         this.mainMenu = new System.Windows.Forms.MainMenu();
         this.fileMenuItem = new System.Windows.Forms.MenuItem();
         this.aboutMenuItem = new System.Windows.Forms.MenuItem();
         this.exitMenuItem = new System.Windows.Forms.MenuItem();
         this.formatMenuItem = new System.Windows.Forms.MenuItem();
         this.colorMenuItem = new System.Windows.Forms.MenuItem();
         this.blackMenuItem = new System.Windows.Forms.MenuItem();
         this.blueMenuItem = new System.Windows.Forms.MenuItem();
         this.redMenuItem = new System.Windows.Forms.MenuItem();
         this.greenMenuItem = new System.Windows.Forms.MenuItem();
         this.fontMenuItem = new System.Windows.Forms.MenuItem();
         this.timesMenuItem = new System.Windows.Forms.MenuItem();
         this.courierMenuItem = new System.Windows.Forms.MenuItem();
         this.comicMenuItem = new System.Windows.Forms.MenuItem();
         this.separatorMenuItem = new System.Windows.Forms.MenuItem();
         this.boldMenuItem = new System.Windows.Forms.MenuItem();
         this.italicMenuItem = new System.Windows.Forms.MenuItem();
         this.SuspendLayout();
         // 
         // displayLabel
         // 
         this.displayLabel.Font = new System.Drawing.Font("Times New Roman", 14F);
         this.displayLabel.Location = new System.Drawing.Point(16, 8);
         this.displayLabel.Name = "displayLabel";
         this.displayLabel.Size = new System.Drawing.Size(264, 88);
         this.displayLabel.TabIndex = 0;
         this.displayLabel.Text = "Use the Format menu to change the appearance of this text.";
         // 
         // mainMenu
         // 
         this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                                                                 this.fileMenuItem,
                                                                                 this.formatMenuItem});
         // 
         // fileMenuItem
         // 
         this.fileMenuItem.Index = 0;
         this.fileMenuItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                                                                     this.aboutMenuItem,
                                                                                     this.exitMenuItem});
         this.fileMenuItem.Text = "File";
         // 
         // aboutMenuItem
         // 
         this.aboutMenuItem.Index = 0;
         this.aboutMenuItem.Text = "About";
         this.aboutMenuItem.Click += new System.EventHandler(this.aboutMenuItem_Click);
         // 
         // exitMenuItem
         // 
         this.exitMenuItem.Index = 1;
         this.exitMenuItem.Text = "Exit";
         this.exitMenuItem.Click += new System.EventHandler(this.exitMenuItem_Click);
         // 
         // formatMenuItem
         // 
         this.formatMenuItem.Index = 1;
         this.formatMenuItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                                                                       this.colorMenuItem,
                                                                                       this.fontMenuItem});
         this.formatMenuItem.Text = "Format";
         // 
         // colorMenuItem
         // 
         this.colorMenuItem.Index = 0;
         this.colorMenuItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                                                                      this.blackMenuItem,
                                                                                      this.blueMenuItem,
                                                                                      this.redMenuItem,
                                                                                      this.greenMenuItem});
         this.colorMenuItem.Text = "Color";
         // 
         // blackMenuItem
         // 
         this.blackMenuItem.Index = 0;
         this.blackMenuItem.RadioCheck = true;
         this.blackMenuItem.Text = "Black";
         this.blackMenuItem.Click += new System.EventHandler(this.blackMenuItem_Click);
         // 
         // blueMenuItem
         // 
         this.blueMenuItem.Index = 1;
         this.blueMenuItem.RadioCheck = true;
         this.blueMenuItem.Text = "Blue";
         this.blueMenuItem.Click += new System.EventHandler(this.blueMenuItem_Click);
         // 
         // redMenuItem
         // 
         this.redMenuItem.Index = 2;
         this.redMenuItem.RadioCheck = true;
         this.redMenuItem.Text = "Red";
         this.redMenuItem.Click += new System.EventHandler(this.redMenuItem_Click);
         // 
         // greenMenuItem
         // 
         this.greenMenuItem.Index = 3;
         this.greenMenuItem.RadioCheck = true;
         this.greenMenuItem.Text = "Green";
         this.greenMenuItem.Click += new System.EventHandler(this.greenMenuItem_Click);
         // 
         // fontMenuItem
         // 
         this.fontMenuItem.Index = 1;
         this.fontMenuItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                                                                     this.timesMenuItem,
                                                                                     this.courierMenuItem,
                                                                                     this.comicMenuItem,
                                                                                     this.separatorMenuItem,
                                                                                     this.boldMenuItem,
                                                                                     this.italicMenuItem});
         this.fontMenuItem.Text = "Font";
         // 
         // timesMenuItem
         // 
         this.timesMenuItem.Index = 0;
         this.timesMenuItem.Text = "Times New Roman";
         this.timesMenuItem.Click += new System.EventHandler(this.timesMenuItem_Click);
         // 
         // courierMenuItem
         // 
         this.courierMenuItem.Index = 1;
         this.courierMenuItem.Text = "Courier";
         this.courierMenuItem.Click += new System.EventHandler(this.courierMenuItem_Click);
         // 
         // comicMenuItem
         // 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -