当时,我制作了一个非常简单的文本编辑器进行练习,安装了所有表单,但是当我开始添加代码时,所有表单组件突然从表单中消失了,但仍然存在于某个地方。不太确定发生了什么。
我已经发布了我到目前为止编写的代码。我希望此文本编辑器遵循自由书写风格,因此很多功能可能都将被删除。我真的只打算使用“文件”下拉选择(新建,打开,保存和退出)。
预先感谢您的协助。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Text;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CustomTextEditor2 {
public partial class TextEditor : Form {
public TextEditor() {
InitializeComponent();
}
#region Editor and General
#endregion
#region MainMenu
#endregion
#region Toolbar
#endregion
#region contextmenu
#endregion
#region Methods
#region file
void New()
{
Document.Clear();
}
void Open()
{
if (openWork.ShowDialog() == DialogResult.OK)
{
Document.LoadFile(openWork.FileName, RichTextBoxStreamType.PlainText);
}
}
void Save()
{
if (saveWork.ShowDialog() == DialogResult.OK)
{
try
{
Document.SaveFile(saveWork.FileName, RichTextBoxStreamType.PlainText);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
void Exit()
{
Application.Exit();
}
#endregion
#region edit
#endregion
#region tools
void customise()
{
ColorDialog myDialog = new ColorDialog();
if (myDialog.ShowDialog() == DialogResult.OK)
{
mainMenu.BackColor = myDialog.Color;
Status.BackColor = myDialog.Color;
Tools.BackColor = myDialog.Color;
}
}
#endregion
#endregion
}
}
好的,这是TextEditor.Designer.cs中的代码:
namespace CustomTextEditor2
{
partial class TextEditor
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
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()
{
this.SuspendLayout();
//
// TextEditor
//
this.ClientSize = new System.Drawing.Size(732, 434);
this.MinimumSize = new System.Drawing.Size(748, 473);
this.Name = "TextEditor";
/this.Load += new System.EventHandler(this.TextEditor_Load_1);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.MenuStrip mainMenu;
private System.Windows.Forms.RichTextBox Document;
private System.Windows.Forms.StatusStrip Status;
private System.Windows.Forms.ToolStripMenuItem mM_File;
private System.Windows.Forms.ToolStripMenuItem file_New;
private System.Windows.Forms.ToolStripMenuItem file_Open;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator;
private System.Windows.Forms.ToolStripMenuItem file_Save;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
private System.Windows.Forms.ToolStripMenuItem file_Exit;
private System.Windows.Forms.ToolStripStatusLabel charCount;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;
private System.Windows.Forms.ToolStripStatusLabel zoom;
private System.Windows.Forms.OpenFileDialog openWork;
private System.Windows.Forms.SaveFileDialog saveWork;
private System.Windows.Forms.Timer timer;
}
}