thisdocument.cs

来自「这是.net2005学习不可缺少的教程」· CS 代码 · 共 63 行

CS
63
字号
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;

namespace demoword
{
    public partial class ThisDocument
    {
        private Word.Range range;
        public float FontSize = 15.0f;
        private void ThisDocument_Startup(object sender, System.EventArgs e)
        {
            object start = System.Reflection.Missing.Value;
            object end = System.Reflection.Missing.Value;
            range = this.Range(ref start, ref end);
            range.Font = new Word.FontClass();
            range.Font.Name = "Arial";
            range.Font.Size = FontSize;
        }

        private void ThisDocument_Shutdown(object sender, System.EventArgs e)
        {
        }

        #region VSTO Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.button1.Click += new System.EventHandler(this.button1_Click);
            this.button2.Click += new System.EventHandler(this.button2_Click);
            this.Startup += new System.EventHandler(this.ThisDocument_Startup);
            this.Shutdown += new System.EventHandler(this.ThisDocument_Shutdown);

        }

        #endregion

        private void button2_Click(object sender, EventArgs e)
        {
            FontSize += 1;
            range.Font.Size = FontSize;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SizeDlg dlg = new SizeDlg(this);
            dlg.Show();
        }
        public void setSize(float size)
        {
            range.Font.Size = size;
        }
    }
}

⌨️ 快捷键说明

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