Frm_Main.cs
View Code
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using Microsoft.Office.Core;
10
11 namespace WordInForm
12 {
13 public partial class Frm_Main : Form
14 {
15 public Frm_Main()
16 {
17 InitializeComponent();
18 }
19
20 private void btn_Get_Click(object sender, EventArgs e)
21 {
22
23 }
24
25 private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
26 {
27 OpenFileDialog P_GetFile = new OpenFileDialog();//创建打开文件对话框对象
28 DialogResult P_dr = P_GetFile.ShowDialog();//显示打开文件对话框
29 if (P_dr == DialogResult.OK)//是否点击确定
30 {
31 WebBrowser.Navigate(P_GetFile.FileName);//打开Word文档并显示
32 }
33 }
34
35 private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
36 {
37 this.Close();//关闭当前窗体
38 }
39 }
40 }
Frm_Main.Designer.cs
View Code
1 namespace WordInForm
2 {
3 partial class Frm_Main
4 {
5 /// <summary>
6 /// 必需的设计器变量。
7 /// </summary>
8 private System.ComponentModel.IContainer components = null;
9
10 /// <summary>
11 /// 清理所有正在使用的资源。
12 /// </summary>
13 /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
14 protected override void Dispose(bool disposing)
15 {
16 if (disposing && (components != null))
17 {
18 components.Dispose();
19 }
20 base.Dispose(disposing);
21 }
22
23 #region Windows 窗体设计器生成的代码
24
25 /// <summary>
26 /// 设计器支持所需的方法 - 不要
27 /// 使用代码编辑器修改此方法的内容。
28 /// </summary>
29 private void InitializeComponent()
30 {
31 this.menuStrip1 = new System.Windows.Forms.MenuStrip();
32 this.文件ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
33 this.打开ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
34 this.退出ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
35 this.WebBrowser = new System.Windows.Forms.WebBrowser();
36 this.menuStrip1.SuspendLayout();
37 this.SuspendLayout();
38 //
39 // menuStrip1
40 //
41 this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
42 this.文件ToolStripMenuItem});
43 this.menuStrip1.Location = new System.Drawing.Point(0, 0);
44 this.menuStrip1.Name = "menuStrip1";
45 this.menuStrip1.Size = new System.Drawing.Size(475, 25);
46 this.menuStrip1.TabIndex = 1;
47 this.menuStrip1.Text = "menuStrip1";
48 //
49 // 文件ToolStripMenuItem
50 //
51 this.文件ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
52 this.打开ToolStripMenuItem,
53 this.退出ToolStripMenuItem});
54 this.文件ToolStripMenuItem.Name = "文件ToolStripMenuItem";
55 this.文件ToolStripMenuItem.Size = new System.Drawing.Size(44, 21);
56 this.文件ToolStripMenuItem.Text = "文件";
57 //
58 // 打开ToolStripMenuItem
59 //
60 this.打开ToolStripMenuItem.Name = "打开ToolStripMenuItem";
61 this.打开ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
62 this.打开ToolStripMenuItem.Text = "打开";
63 this.打开ToolStripMenuItem.Click += new System.EventHandler(this.打开ToolStripMenuItem_Click);
64 //
65 // 退出ToolStripMenuItem
66 //
67 this.退出ToolStripMenuItem.Name = "退出ToolStripMenuItem";
68 this.退出ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
69 this.退出ToolStripMenuItem.Text = "退出";
70 this.退出ToolStripMenuItem.Click += new System.EventHandler(this.退出ToolStripMenuItem_Click);
71 //
72 // WebBrowser
73 //
74 this.WebBrowser.Dock = System.Windows.Forms.DockStyle.Fill;
75 this.WebBrowser.Location = new System.Drawing.Point(0, 25);
76 this.WebBrowser.MinimumSize = new System.Drawing.Size(20, 20);
77 this.WebBrowser.Name = "WebBrowser";
78 this.WebBrowser.Size = new System.Drawing.Size(475, 373);
79 this.WebBrowser.TabIndex = 2;
80 //
81 // Frm_Main
82 //
83 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
84 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
85 this.ClientSize = new System.Drawing.Size(475, 398);
86 this.Controls.Add(this.WebBrowser);
87 this.Controls.Add(this.menuStrip1);
88 this.MainMenuStrip = this.menuStrip1;
89 this.Name = "Frm_Main";
90 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
91 this.Text = "将Word文档嵌入到WinForm窗体中";
92 this.menuStrip1.ResumeLayout(false);
93 this.menuStrip1.PerformLayout();
94 this.ResumeLayout(false);
95 this.PerformLayout();
96
97 }
98
99 #endregion
100
101 private System.Windows.Forms.MenuStrip menuStrip1;
102 private System.Windows.Forms.ToolStripMenuItem 文件ToolStripMenuItem;
103 private System.Windows.Forms.ToolStripMenuItem 打开ToolStripMenuItem;
104 private System.Windows.Forms.ToolStripMenuItem 退出ToolStripMenuItem;
105 private System.Windows.Forms.WebBrowser WebBrowser;
106
107 }
108 }
作者:墨明棋妙
出处:http://www.cnblogs.com/ynbt/
关于作者:专注于.Net、WCF和移动互联网开发。
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,如有问题,可以通过ynbt_wang@163.com联系我,非常感谢。 。
出处:http://www.cnblogs.com/ynbt/
关于作者:专注于.Net、WCF和移动互联网开发。
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,如有问题,可以通过ynbt_wang@163.com联系我,非常感谢。 。