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

📄 textedit.cs

📁 windows mobile 开发实例wi ndows mobile 开发实例
💻 CS
📖 第 1 页 / 共 3 页
字号:
// TextEdit.cs - Main form for TextEdit sample.
//
// Code from _Programming the .NET Compact Framework 
// with C# and _Programming the .NET Compact Framework 
// with VB 
// (c) Copyright 2002-2004 Paul Yao and David Durant. 
// All rights reserved.

using System;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.IO;

namespace DialogBoxes
{
   /// <summary>
   /// DialogBoxes -- Displays two dialog boxes which show
   /// settings for a text box.
   /// </summary>
   
   public class FormMain : Form
   {
      #region Menu items and Toolbar buttons

      private MainMenu menuMain;
      private MenuItem mitemFilePopup;
      private MenuItem mitemFileOpen;
      private MenuItem mitemFileSave;
      private MenuItem mitemFileSaveAs;
      private MenuItem mitemFileFormat;
      private MenuItem mitemFFAscii;
      private MenuItem mitemFFUnicode;
      private MenuItem mitemFFUtf7;
      private MenuItem mitemFFUtf8;
      private MenuItem mitemFFDefault;
      private MenuItem mitemSettingsPopup;
      private MenuItem mitemSettingsSave;
      private MenuItem mitemSettingsRestore;
      private MenuItem mitemSettingsInit;
      private MenuItem mitemEditPopup;
      private MenuItem mitemToolsPopup;
      private TextBox textInput;
      private ToolBar tbarCommands;
      private ToolBarButton tbbEditFormat;
      private ToolBarButton tbbViewOptions;
      private ImageList ilistCommands;
      private ContextMenu cmenuMain;
      private MenuItem mitemProgramMenu;
      private MenuItem mitemToolbar;
      private MenuItem mitemEditFont;
      private MenuItem mitemToolsOptions;

      #endregion

      public FormMain()
      {
         //
         // Required for Windows Form Designer support
         //
         InitializeComponent();
      }

      /// <summary>
      /// Clean up any resources being used.
      /// </summary>
      protected override void Dispose( bool disposing )
      {
         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()
      {
         System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FormMain));
         this.menuMain = new System.Windows.Forms.MainMenu();
         this.mitemFilePopup = new System.Windows.Forms.MenuItem();
         this.mitemFileOpen = new System.Windows.Forms.MenuItem();
         this.mitemFileSave = new System.Windows.Forms.MenuItem();
         this.mitemFileSaveAs = new System.Windows.Forms.MenuItem();
         this.mitemFileFormat = new System.Windows.Forms.MenuItem();
         this.mitemFFAscii = new System.Windows.Forms.MenuItem();
         this.mitemFFUnicode = new System.Windows.Forms.MenuItem();
         this.mitemFFUtf7 = new System.Windows.Forms.MenuItem();
         this.mitemFFUtf8 = new System.Windows.Forms.MenuItem();
         this.mitemFFDefault = new System.Windows.Forms.MenuItem();
         this.mitemEditPopup = new System.Windows.Forms.MenuItem();
         this.mitemEditFont = new System.Windows.Forms.MenuItem();
         this.mitemToolsPopup = new System.Windows.Forms.MenuItem();
         this.mitemToolsOptions = new System.Windows.Forms.MenuItem();
         this.mitemSettingsPopup = new System.Windows.Forms.MenuItem();
         this.mitemSettingsSave = new System.Windows.Forms.MenuItem();
         this.mitemSettingsRestore = new System.Windows.Forms.MenuItem();
         this.mitemSettingsInit = new System.Windows.Forms.MenuItem();
         this.textInput = new System.Windows.Forms.TextBox();
         this.tbarCommands = new System.Windows.Forms.ToolBar();
         this.tbbEditFormat = new System.Windows.Forms.ToolBarButton();
         this.tbbViewOptions = new System.Windows.Forms.ToolBarButton();
         this.ilistCommands = new System.Windows.Forms.ImageList();
         this.cmenuMain = new System.Windows.Forms.ContextMenu();
         this.mitemProgramMenu = new System.Windows.Forms.MenuItem();
         this.mitemToolbar = new System.Windows.Forms.MenuItem();
         // 
         // menuMain
         // 
         this.menuMain.MenuItems.Add(this.mitemFilePopup);
         this.menuMain.MenuItems.Add(this.mitemEditPopup);
         this.menuMain.MenuItems.Add(this.mitemToolsPopup);
         this.menuMain.MenuItems.Add(this.mitemSettingsPopup);
         // 
         // mitemFilePopup
         // 
         this.mitemFilePopup.MenuItems.Add(this.mitemFileOpen);
         this.mitemFilePopup.MenuItems.Add(this.mitemFileSave);
         this.mitemFilePopup.MenuItems.Add(this.mitemFileSaveAs);
         this.mitemFilePopup.MenuItems.Add(this.mitemFileFormat);
         this.mitemFilePopup.Text = "File";
         // 
         // mitemFileOpen
         // 
         this.mitemFileOpen.Text = "Open...";
         this.mitemFileOpen.Click += new System.EventHandler(this.mitemFileOpen_Click);
         // 
         // mitemFileSave
         // 
         this.mitemFileSave.Text = "Save";
         this.mitemFileSave.Click += new System.EventHandler(this.mitemFileSave_Click);
         // 
         // mitemFileSaveAs
         // 
         this.mitemFileSaveAs.Text = "SaveAs...";
         this.mitemFileSaveAs.Click += new System.EventHandler(this.mitemFileSaveAs_Click);
         // 
         // mitemFileFormat
         // 
         this.mitemFileFormat.MenuItems.Add(this.mitemFFAscii);
         this.mitemFileFormat.MenuItems.Add(this.mitemFFUnicode);
         this.mitemFileFormat.MenuItems.Add(this.mitemFFUtf7);
         this.mitemFileFormat.MenuItems.Add(this.mitemFFUtf8);
         this.mitemFileFormat.MenuItems.Add(this.mitemFFDefault);
         this.mitemFileFormat.Text = "Format";
         // 
         // mitemFFAscii
         // 
         this.mitemFFAscii.Text = "Ascii";
         this.mitemFFAscii.Click += new System.EventHandler(this.mitemFFFormat_Click);
         // 
         // mitemFFUnicode
         // 
         this.mitemFFUnicode.Text = "Unicode";
         this.mitemFFUnicode.Click += new System.EventHandler(this.mitemFFFormat_Click);
         // 
         // mitemFFUtf7
         // 
         this.mitemFFUtf7.Text = "Utf7";
         this.mitemFFUtf7.Click += new System.EventHandler(this.mitemFFFormat_Click);
         // 
         // mitemFFUtf8
         // 
         this.mitemFFUtf8.Text = "Utf8";
         this.mitemFFUtf8.Click += new System.EventHandler(this.mitemFFFormat_Click);
         // 
         // mitemFFDefault
         // 
         this.mitemFFDefault.Text = "Default";
         this.mitemFFDefault.Click += new System.EventHandler(this.mitemFFFormat_Click);
         // 
         // mitemEditPopup
         // 
         this.mitemEditPopup.MenuItems.Add(this.mitemEditFont);
         this.mitemEditPopup.Text = "Edit";
         // 
         // mitemEditFont
         // 
         this.mitemEditFont.Text = "Font...";
         this.mitemEditFont.Click += new System.EventHandler(this.mitemEditFont_Click);
         // 
         // mitemToolsPopup
         // 
         this.mitemToolsPopup.MenuItems.Add(this.mitemToolsOptions);
         this.mitemToolsPopup.Text = "Tools";
         // 
         // mitemToolsOptions
         // 
         this.mitemToolsOptions.Text = "Options...";
         this.mitemToolsOptions.Click += new System.EventHandler(this.mitemToolsOptions_Click);
         // 
         // mitemSettingsPopup
         // 
         this.mitemSettingsPopup.MenuItems.Add(this.mitemSettingsSave);
         this.mitemSettingsPopup.MenuItems.Add(this.mitemSettingsRestore);
         this.mitemSettingsPopup.MenuItems.Add(this.mitemSettingsInit);
         this.mitemSettingsPopup.Text = "Settings";
         // 
         // mitemSettingsSave
         // 
         this.mitemSettingsSave.Text = "Save";
         this.mitemSettingsSave.Click += new System.EventHandler(this.mitemSettingsSave_Click);
         // 
         // mitemSettingsRestore
         // 
         this.mitemSettingsRestore.Text = "Restore";
         this.mitemSettingsRestore.Click += new System.EventHandler(this.mitemSettingsRestore_Click);
         // 
         // mitemSettingsInit
         // 
         this.mitemSettingsInit.Text = "Initialize";
         this.mitemSettingsInit.Click += new System.EventHandler(this.mitemSettingsInit_Click);
         // 
         // textInput
         // 
         this.textInput.Location = new System.Drawing.Point(8, 8);
         this.textInput.Multiline = true;
         this.textInput.ScrollBars = System.Windows.Forms.ScrollBars.Both;
         this.textInput.Size = new System.Drawing.Size(224, 248);
         this.textInput.Text = "Some text inside a textbox.";
         // 
         // tbarCommands
         // 
         this.tbarCommands.Buttons.Add(this.tbbEditFormat);
         this.tbarCommands.Buttons.Add(this.tbbViewOptions);
         this.tbarCommands.ImageList = this.ilistCommands;
         this.tbarCommands.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.tbarCommands_ButtonClick);
         // 
         // tbbEditFormat
         // 
         this.tbbEditFormat.ImageIndex = 0;
         // 
         // tbbViewOptions
         // 
         this.tbbViewOptions.ImageIndex = 1;
         // 
         // ilistCommands
         // 
         this.ilistCommands.Images.Add(((System.Drawing.Image)(resources.GetObject("resource"))));
         this.ilistCommands.Images.Add(((System.Drawing.Image)(resources.GetObject("resource1"))));
         this.ilistCommands.ImageSize = new System.Drawing.Size(16, 16);
         // 
         // cmenuMain
         // 
         this.cmenuMain.MenuItems.Add(this.mitemProgramMenu);
         this.cmenuMain.MenuItems.Add(this.mitemToolbar);
         this.cmenuMain.Popup += new System.EventHandler(this.cmenuMain_Popup);
         // 
         // mitemProgramMenu
         // 
         this.mitemProgramMenu.Text = "Program Menu";
         this.mitemProgramMenu.Click += new System.EventHandler(this.mitemProgramMenu_Click);
         // 
         // mitemToolbar
         // 
         this.mitemToolbar.Text = "Toolbar";
         this.mitemToolbar.Click += new System.EventHandler(this.mitemToolbar_Click);
         // 
         // FormMain
         // 
         this.ContextMenu = this.cmenuMain;
         this.Controls.Add(this.textInput);
         this.Controls.Add(this.tbarCommands);
         this.Menu = this.menuMain;
         this.MinimizeBox = false;
         this.Text = "TextEdit";
         this.Load += new System.EventHandler(this.FormMain_Load);

      }
      #endregion

      /// <summary>
      /// The main entry point for the application.
      /// </summary>

      static void Main() 
      {
         Application.Run(new FormMain());
      }

      private void FormMain_Load(object sender, System.EventArgs e)
      {
         mitemSettingsRestore_Click(this, EventArgs.Empty);
      }

      #region Fonts and Settings

      /// mitemEditFont - Respond to menu selection Edit->Font...
      private void mitemEditFont_Click(
         object sender, 
         System.EventArgs e)
      {
         DlgFont dlg = new DlgFont(this);

         // Initialize input values to dialog.
         dlg.strFontName = textInput.Font.Name;
         dlg.cemFontSize = textInput.Font.Size;
         FontStyle fsTemp = textInput.Font.Style;
         dlg.bBold = ((fsTemp & FontStyle.Bold) != 0);
         dlg.bItalic = ((fsTemp & FontStyle.Italic) != 0);
         dlg.bUnderline = ((fsTemp & FontStyle.Underline) != 0);

         // Summon dialog box.
         if (dlg.ShowDialog() != DialogResult.OK)
            return;

         // Modify settings based on user input.
         Font fontOld = textInput.Font;
         fsTemp = 0;
         if (dlg.bBold) fsTemp |= FontStyle.Bold;
         if (dlg.bItalic) fsTemp |= FontStyle.Italic;
         if (dlg.bUnderline) fsTemp |= FontStyle.Underline;
         textInput.Font = 
            new Font(dlg.strFontName, dlg.cemFontSize, fsTemp);
         fontOld.Dispose();
      } // mitemEditFont_Click

⌨️ 快捷键说明

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