📄 mainform.cs
字号:
}
#endregion
#endregion
#region 查看--工具栏和状态栏
private void 工具栏ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (工具栏ToolStripMenuItem.Checked)
{
this.toolStrip1.Dock = DockStyle.None;
this.toolStrip1.Hide();
工具栏ToolStripMenuItem.Checked = false;
}
else
{
this.toolStrip1.Dock = DockStyle.Top;
this.toolStrip1.Show();
工具栏ToolStripMenuItem.Checked = true;
}
}
private void 格式栏ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (格式栏ToolStripMenuItem.Checked)
{
this.toolStrip2.Dock = DockStyle.None;
this.toolStrip2.Hide();
格式栏ToolStripMenuItem.Checked = false;
}
else
{
this.toolStrip2.Dock = DockStyle.Top;
this.toolStrip2.Show();
格式栏ToolStripMenuItem.Checked = true;
}
}
private void 状态栏ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (状态栏ToolStripMenuItem.Checked)
{
this.statusStrip1.Dock = DockStyle.None;
this.statusStrip1.Hide();
状态栏ToolStripMenuItem.Checked = false;
}
else
{
this.statusStrip1.Dock = DockStyle.Bottom;
this.statusStrip1.Show();
状态栏ToolStripMenuItem.Checked = true;
}
}
#endregion
#region 窗口--层叠显示,水平排列和垂直排列
private void 层叠显示ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.LayoutMdi(MdiLayout.Cascade);
层叠显示ToolStripMenuItem.Checked = true;
水平排列ToolStripMenuItem.Checked = false;
垂直排列ToolStripMenuItem.Checked = false;
}
private void 水平排列ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.LayoutMdi(MdiLayout.TileHorizontal);
层叠显示ToolStripMenuItem.Checked = false;
水平排列ToolStripMenuItem.Checked = true;
垂直排列ToolStripMenuItem.Checked = false;
}
private void 垂直排列ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.LayoutMdi(MdiLayout.TileVertical);
层叠显示ToolStripMenuItem.Checked = false;
水平排列ToolStripMenuItem.Checked = false;
垂直排列ToolStripMenuItem.Checked = true;
}
#endregion
#region 帮助--帮助主题和关于
private void 帮助主题ToolStripMenuItem_Click(object sender, EventArgs e)
{
string strHelpFilePath = Application.StartupPath + "\\Notepad 使用帮助.chm";
if (File.Exists(strHelpFilePath))
{
//如果你只加载这个文件
Help.ShowHelp(this, strHelpFilePath);
}
}
private void 关于CSharpNotepadToolStripMenuItem_Click(object sender, EventArgs e)
{
new aboutForm().Show();
}
#endregion
#endregion
#region 主窗口工具栏事件处理的方法
#region 填充字体和字号数据
private void GetFontFamilyNames()
{
Graphics graphics = this.CreateGraphics();
FontFamily[] fontFamilyNames = FontFamily.GetFamilies(graphics);
for (int i = 0; i < fontFamilyNames.Length; i++)
{
tscbFontFamilyName.Items.Add(fontFamilyNames[i].Name);
}
}
private void GetFontSize()
{
float[] fontSize = new float[] { 5f, 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72 };
for (int i = 0; i < fontSize.Length; i++)
tscbFontSize.Items.Add(fontSize[i].ToString());
}
#endregion
#region 设置文本的字体和字号
//单独设置字体
private void tscbFontFamilyName_SelectedIndexChanged(object sender, EventArgs e)
{
string newFontFamilyName;
float FontSize;
newFontFamilyName = tscbFontFamilyName.SelectedItem.ToString();
if (tscbFontSize.SelectedIndex == -1)
{
FontSize = float.Parse(tscbFontSize.Items[6].ToString());
}
else
{
FontSize = float.Parse(tscbFontSize.SelectedItem.ToString());
}
currentForm.SetFontFamilyName(newFontFamilyName, FontSize);
currentForm.GetCurrentFontAndAlignment();
}
//单独设置字号
private void tscbFontSize_SelectedIndexChanged(object sender, EventArgs e)
{
string FontFamilyName;
float newFontSize;
newFontSize = float.Parse(tscbFontSize.Text.ToString());
if (tscbFontFamilyName.SelectedIndex == -1)
{
FontFamilyName = tscbFontFamilyName.Items[1].ToString();
}
else
{
FontFamilyName = tscbFontFamilyName.SelectedItem.ToString();
}
currentForm.SetFontSize(FontFamilyName, newFontSize);
currentForm.GetCurrentFontAndAlignment();
}
private void tscbFontSize_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(Char.IsNumber(e.KeyChar) || e.KeyChar == (char)8))
e.Handled = true;
}
private void tscbFontSize_TextChanged(object sender, System.EventArgs e)
{
if (this.MdiChildren.Length == 0 || tscbFontSize.Text == "")
return;
else
{
string FontFamilyName;
float newFontSize;
newFontSize = float.Parse(tscbFontSize.Text.ToString());
if (tscbFontFamilyName.SelectedIndex == -1)
{
FontFamilyName = tscbFontFamilyName.Items[1].ToString();
}
else
{
FontFamilyName = tscbFontFamilyName.SelectedItem.ToString();
}
currentForm.SetFontSize(FontFamilyName, newFontSize);
currentForm.GetCurrentFontAndAlignment();
}
}
#endregion
#region 设置文本的字形(粗体/斜体/下划线)
private void tsbBold_Click(object sender, EventArgs e)
{
currentForm.SetBold();
currentForm.GetCurrentFontAndAlignment();
this.SetCurrentFont();
}
private void tsbItalic_Click(object sender, EventArgs e)
{
currentForm.SetItalic();
currentForm.GetCurrentFontAndAlignment();
this.SetCurrentFont();
}
private void tsbUnderLine_Click(object sender, EventArgs e)
{
currentForm.SetUnderLine();
currentForm.GetCurrentFontAndAlignment();
this.SetCurrentFont();
}
#endregion
#region 设置文本的对齐格式
private void LeftAlign_Click(object sender, EventArgs e) //左对齐
{
左对齐ToolStripMenuItem_Click(sender, e);
currentForm.GetCurrentFontAndAlignment();
this.SetCurrentAlignment();
}
private void MiddleAlign_Click(object sender, EventArgs e) //居中
{
居中ToolStripMenuItem_Click(sender, e);
currentForm.GetCurrentFontAndAlignment();
this.SetCurrentAlignment();
}
private void RightAlign_Click(object sender, EventArgs e) //右对齐
{
右对齐ToolStripMenuItem_Click(sender, e);
currentForm.GetCurrentFontAndAlignment();
this.SetCurrentAlignment();
}
#endregion
#region 设置文本的颜色
private void tssbFontColor_Click(object sender, EventArgs e)
{
颜色ToolStripMenuItem_Click(sender, e);
}
#endregion
#endregion
#region 主窗口格式栏事件处理的方法
private void 新建NToolStripButton_Click(object sender, EventArgs e)
{
新建ToolStripMenuItem_Click(sender, e);
}
private void 打开OToolStripButton_Click(object sender, EventArgs e)
{
打开ToolStripMenuItem_Click(sender, e);
}
private void 保存SToolStripButton_Click(object sender, EventArgs e)
{
保存ToolStripMenuItem_Click(sender, e);
}
private void 打印PToolStripButton_Click(object sender, EventArgs e)
{
打印ToolStripMenuItem_Click(sender, e);
}
private void 打印预览VToolStripButton_Click(object sender, EventArgs e)
{
打印预览ToolStripMenuItem_Click(sender, e);
}
private void 剪切UToolStripButton_Click(object sender, EventArgs e)
{
剪切ToolStripMenuItem_Click(sender, e);
}
private void 复制CToolStripButton_Click(object sender, EventArgs e)
{
复制ToolStripMenuItem_Click(sender, e);
}
private void 粘贴PToolStripButton_Click(object sender, EventArgs e)
{
粘贴ToolStripMenuItem_Click(sender, e);
}
private void 撤消UToolStripButton_Click(object sender, EventArgs e)
{
撤消ToolStripMenuItem_Click(sender, e);
}
private void 恢复RToolStripButton_Click(object sender, EventArgs e)
{
恢复ToolStripMenuItem_Click(sender, e);
}
private void 帮助LToolStripButton_Click(object sender, EventArgs e)
{
帮助主题ToolStripMenuItem_Click(sender, e);
}
private void tscbDisplayRatio_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar != (char)37)
{
if (!(Char.IsNumber(e.KeyChar) || e.KeyChar == (char)8))
e.Handled = true;
}
return;
}
private void tscbDisplayRatio_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (this.MdiChildren.Length == 0)
return;
this.currentForm.richTextBox1.ZoomFactor = float.Parse(tscbDisplayRatio.Text.Remove(tscbDisplayRatio.Text.Length - 1, 1)) / 100.0f;
}
private void tscbDisplayRatio_TextChanged(object sender, System.EventArgs e)
{
string[] temp = this.tscbDisplayRatio.Text.Split('%');
if (this.MdiChildren.Length == 0 || temp[0] == "")
{
this.tscbDisplayRatio.Text = "10%";
return;
}
else
{
float ratio;
//if (tscbDisplayRatio.Text.EndsWith("%"))
//ratio = float.Parse(tscbDisplayRatio.Text.Remove(tscbDisplayRatio.Text.Length - 1, 1)) / 100.0f;
this.tscbDisplayRatio.Text = temp[0] + "%";
ratio = float.Parse(temp[0]) / 100.0f;
if (ratio <= 0.05)
{
this.currentForm.richTextBox1.ZoomFactor = 0.05f;
}
else if (ratio > 16.0)
{
this.currentForm.richTextBox1.ZoomFactor = 16.0f;
}
else
{
this.currentForm.richTextBox1.ZoomFactor = ratio;
}
}
}
private void tsbProject_Click(object sender, EventArgs e)
{
项目符号样式ToolStripMenuItem_Click(sender, e);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -