C#作业miniword

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

运用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()
        {
   
   
            
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值