运用C#编写一个miniword
首先布局好相关的前端界面

相关的菜单栏的添加设置可以参考网上的其他文章。
然后设计子窗体

这些实现也比较简单。
再就是需要一些C#里自带的工具

主页面form1的代码块
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace miniword
{
public delegate void ClickPanel(string s);
public partial class Form1 : Form
{
public static int panel_count = 0;
public static Panel panel_active = null;
public static bool ishavefindpanel = false;
public static Form2 _findpanel = null;
public static string cookie_s = null;
public static bool cookie_isup = false;
public void Click_Panel(string s)
{
foreach (ToolStripItem con in this.窗口ToolStripMenuItem.DropDownItems)
{
if (con is ToolStripMenuItem)
{
if ((string)con.Tag == s)
{
con.Image = miniword.Properties.Resources.PENCIL03;
}
else
{
con.Image = null;
}
}
}
}
public void Update_Panel(string s, bool isdrop)
{
int p_c = this.MdiChildren.Length;
if(isdrop)
{
p_c = p_c - 1;
}
while(this.窗口ToolStripMenuItem.DropDownItems.Count >= 3)
{
this.窗口ToolStripMenuItem.DropDownItems.RemoveAt(2);
}
if (p_c >= 1)
{
System.Windows.Forms.ToolStripSeparator toolStripSeparator = new System.Windows.Forms.ToolStripSeparator();
this.窗口ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
toolStripSeparator});
}
int c_i = 0;
foreach (Form child in this.MdiChildren)
{
if (child.Text == s && isdrop) continue;
System.Windows.Forms.ToolStripMenuItem PanelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
c_i++;
this.窗口ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
PanelToolStripMenuItem});
PanelToolStripMenuItem.Name = child.Text + "ToolStripMenuItem";
PanelToolStripMenuItem.Size = new System.Drawing.Size(122, 26);
PanelToolStripMenuItem.Text = c_i + " " + child.Text;
PanelToolStripMenuItem.Click += new System.EventHandler(FileToolStripMenuItem_Click);
PanelToolStripMenuItem.Tag = child.Text;
if (child.Text != s)
{
PanelToolStripMenuItem.Image = null;
}
else
{
PanelToolStripMenuItem.Image = miniword.Properties.Resources.PENCIL03;
}
}
}
public void Create_Panel()
{
Panel newPanel = new Panel();
newPanel.TopLevel = false;
newPanel.Show();
newPanel.BringToFront();
newPanel.MdiParent = this;
newPanel.Tag = true;
newPanel.Focus();
Form1.panel_count++;
newPanel.Text = "新建文档" + Form1.panel_count;
newPanel.updatepanel += new UpdatePanel(Update_Panel);
newPanel.Activated += new System.EventHandler(PanelGetFocus);
this.Update_Panel(newPanel.Text, false);
Form1.panel_active = newPanel;
this.自动换行ToolStripMenuItem.Image = null;
}
public Form1()
{

本文介绍了一个使用C#编写的简易文字编辑器项目,包括主界面Form1的设计与子界面Panel的功能实现,如文档创建、保存、字体颜色设置等,并提供了详细的代码示例。
最低0.47元/天 解锁文章
1313

被折叠的 条评论
为什么被折叠?



