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

📄 menutest.cs

📁 this is a good book for the visual c#
💻 CS
📖 第 1 页 / 共 2 页
字号:
         this.comicMenuItem.Index = 2;
         this.comicMenuItem.Text = "Comic Sans";
         this.comicMenuItem.Click += new System.EventHandler(this.comicMenuItem_Click);
         // 
         // separatorMenuItem
         // 
         this.separatorMenuItem.Index = 3;
         this.separatorMenuItem.Text = "-";
         // 
         // boldMenuItem
         // 
         this.boldMenuItem.Index = 4;
         this.boldMenuItem.Text = "Bold";
         this.boldMenuItem.Click += new System.EventHandler(this.boldMenuItem_Click);
         // 
         // italicMenuItem
         // 
         this.italicMenuItem.Index = 5;
         this.italicMenuItem.Text = "Italic";
         this.italicMenuItem.Click += new System.EventHandler(this.italicMenuItem_Click);
         // 
         // MenuTest
         // 
         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
         this.ClientSize = new System.Drawing.Size(292, 97);
         this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                      this.displayLabel});
         this.Menu = this.mainMenu;
         this.Name = "MenuTest";
         this.Text = "MenuTest";
         this.ResumeLayout(false);

      }
      #endregion

      /// <summary>
      /// The main entry point for the application.
      /// </summary>
      [STAThread]
      static void Main() 
      {
         Application.Run( new MenuTest() );
      }

      // display MessageBox
      private void aboutMenuItem_Click(
         object sender, System.EventArgs e )
      {
         MessageBox.Show( 
            "This is an example\nof using menus.",
            "About", MessageBoxButtons.OK, 
            MessageBoxIcon.Information );
      }

      // exit program
      private void exitMenuItem_Click(
         object sender, System.EventArgs e )
      {
         Application.Exit();
      }

      // reset color
      private void ClearColor()
      {
         // clear all checkmarks
         blackMenuItem.Checked = false;
         blueMenuItem.Checked = false;
         redMenuItem.Checked = false;
         greenMenuItem.Checked = false;
      }

      // update menu state and color display black
      private void blackMenuItem_Click(
         object sender, System.EventArgs e )
      {
         // reset checkmarks for color menu items
         ClearColor();

         // set color to black
         displayLabel.ForeColor = Color.Black;
         blackMenuItem.Checked = true;
      }

      // update menu state and color display blue
      private void blueMenuItem_Click(
         object sender, System.EventArgs e )
      {
         // reset checkmarks for color menu items
         ClearColor();

         // set color to blue
         displayLabel.ForeColor = Color.Blue;
         blueMenuItem.Checked = true;
      }

      // update menu state and color display red
      private void redMenuItem_Click(
         object sender, System.EventArgs e )
      {
         // reset checkmarks for color menu items
         ClearColor();

         // set color to red
         displayLabel.ForeColor = Color.Red;
         redMenuItem.Checked = true;
      }

      // update menu state and color display green
      private void greenMenuItem_Click(
         object sender, System.EventArgs e )
      {
         // reset checkmarks for color menu items
         ClearColor();

         // set color to green
         displayLabel.ForeColor = Color.Green;
         greenMenuItem.Checked = true;
      }

      // reset font types
      private void ClearFont()
      {
         // clear all checkmarks
         timesMenuItem.Checked = false;
         courierMenuItem.Checked = false;
         comicMenuItem.Checked = false;
      }

      // update menu state and set font to Times
      private void timesMenuItem_Click(
         object sender, System.EventArgs e )
      {
         // reset checkmarks for font menu items
         ClearFont();

         // set Times New Roman font
         timesMenuItem.Checked = true;
         displayLabel.Font = new Font( 
            "Times New Roman", 14, displayLabel.Font.Style );
      }

      // update menu state and set font to Courier
      private void courierMenuItem_Click(
         object sender, System.EventArgs e )
      {
         // reset checkmarks for font menu items
         ClearFont();

         // set Courier font
         courierMenuItem.Checked = true;
         displayLabel.Font = new Font( 
            "Courier New", 14, displayLabel.Font.Style );
      }

      // update menu state and set font to Comic Sans MS
      private void comicMenuItem_Click(
         object sender, System.EventArgs e )
      {
         // reset checkmarks for font menu items
         ClearFont();

         // set Comic Sans font
         comicMenuItem.Checked = true;
         displayLabel.Font = new Font( 
            "Comic Sans MS", 14, displayLabel.Font.Style );
      }

      // toggle checkmark and toggle bold style
      private void boldMenuItem_Click(
         object sender, System.EventArgs e )
      {
         // toggle checkmark
         boldMenuItem.Checked = !boldMenuItem.Checked;

         // use Xor to toggle bold, keep all other styles
         displayLabel.Font = new Font( 
            displayLabel.Font.FontFamily, 14,
            displayLabel.Font.Style ^ FontStyle.Bold );
      }

      // toggle checkmark and toggle italic style
      private void italicMenuItem_Click(
         object sender, System.EventArgs e)
      {
         // toggle checkmark
         italicMenuItem.Checked = !italicMenuItem.Checked;

         // use Xor to toggle bold, keep all other styles
         displayLabel.Font = new Font( 
            displayLabel.Font.FontFamily, 14,
            displayLabel.Font.Style ^ FontStyle.Italic );
      }

   } // end class MenuTest
}

/*
 ************************************************************************** 
 * (C) Copyright 2002 by Deitel & Associates, Inc. and Prentice Hall.     *
 * All Rights Reserved.                                                   *
 *                                                                        *
 * DISCLAIMER: The authors and publisher of this book have used their     *
 * best efforts in preparing the book. These efforts include the          *
 * development, research, and testing of the theories and programs        *
 * to determine their effectiveness. The authors and publisher make       *
 * no warranty of any kind, expressed or implied, with regard to these    *
 * programs or to the documentation contained in these books. The authors *
 * and publisher shall not be liable in any event for incidental or       *
 * consequential damages in connection with, or arising out of, the       *
 * furnishing, performance, or use of these programs.                     *
 **************************************************************************
*/

⌨️ 快捷键说明

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