MenuStrip — это контейнер для структур меню в приложении.


Наиболее удобно добавлять элементы управления в контейнер MenuStrip и редактировать с помощью свойства Items, нажав на кнопку, откроется редактор.

Form1.cs
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
_0065 {
-
public
partial
class
Form1 : Form {
-
public
Form1() {
-
InitializeComponent();
-
}
-
//FILE / New
-
private
void
toolStripMenuItemNew_Click(
object
sender, EventArgs e) {
-
richTextBox1.Visible =
true
;
-
richTextBox1.Select();
-
}
-
//FILE / Open
-
private
void
toolStripMenuItemOpen_Click(
object
sender, EventArgs e) {
-
richTextBox1.Clear();
-
if
(richTextBox1.Visible ==
false
) {
-
richTextBox1.Visible =
true
;
-
}
-
openFileDialog1.Filter =
"Text (*.txt) | *.txt"
;
-
if
(openFileDialog1.ShowDialog() == DialogResult.OK) {
-
richTextBox1.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.PlainText);
-
richTextBox1.Select();
-
}
-
}
-
//FILE / Save
-
private
void
toolStripMenuItemSave_Click(
object
sender, EventArgs e) {
-
saveFileDialog1.Filter =
"Text (*.txt) | *.txt"
;
-
if
(saveFileDialog1.ShowDialog() == DialogResult.OK) {
-
richTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);
-
}
-
}
-
//FILE / Exit
-
private
void
toolStripMenuItemExit_Click(
object
sender, EventArgs e) {
-
//this.Close();
-
Application.Exit();
-
}
-
//SETTING / Font
-
private
void
toolStripMenuItemFont_Click(
object
sender, EventArgs e) {
-
if
(fontDialog1.ShowDialog() == DialogResult.OK) {
-
richTextBox1.Select();
-
richTextBox1.SelectionFont = fontDialog1.Font;
-
}
-
}
-
//SETTING / Color
-
private
void
toolStripMenuItemColor_Click(
object
sender, EventArgs e) {
-
if
(colorDialog1.ShowDialog() == DialogResult.OK) {
-
richTextBox1.Select();
-
richTextBox1.SelectionColor = colorDialog1.Color;
-
}
-
}
-
//CLEAR / Clear text
-
private
void
toolStripMenuItemClearText_Click(
object
sender, EventArgs e) {
-
richTextBox1.Clear();
-
richTextBox1.Select();
-
}
-
}
}
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
_0065 {
-
public
partial
class
Form1 : Form {
-
public
Form1() {
-
InitializeComponent();
-
}
-
//FILE / New
-
private
void
toolStripMenuItemNew_Click(
object
sender, EventArgs e) {
-
richTextBox1.Visible =
true
;
-
richTextBox1.Select();
-
}
-
//FILE / Open
-
private
void
toolStripMenuItemOpen_Click(
object
sender, EventArgs e) {
-
richTextBox1.Clear();
-
if
(richTextBox1.Visible ==
false
) {
-
richTextBox1.Visible =
true
;
-
}
-
openFileDialog1.Filter =
"Text (*.txt) | *.txt"
;
-
if
(openFileDialog1.ShowDialog() == DialogResult.OK) {
-
richTextBox1.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.PlainText);
-
richTextBox1.Select();
-
}
-
}
-
//FILE / Save
-
private
void
toolStripMenuItemSave_Click(
object
sender, EventArgs e) {
-
saveFileDialog1.Filter =
"Text (*.txt) | *.txt"
;
-
if
(saveFileDialog1.ShowDialog() == DialogResult.OK) {
-
richTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);
-
}
-
}
-
//FILE / Exit
-
private
void
toolStripMenuItemExit_Click(
object
sender, EventArgs e) {
-
//this.Close();
-
Application.Exit();
-
}
-
//SETTING / Font
-
private
void
toolStripMenuItemFont_Click(
object
sender, EventArgs e) {
-
if
(fontDialog1.ShowDialog() == DialogResult.OK) {
-
richTextBox1.Select();
-
richTextBox1.SelectionFont = fontDialog1.Font;
-
}
-
}
-
//SETTING / Color
-
private
void
toolStripMenuItemColor_Click(
object
sender, EventArgs e) {
-
if
(colorDialog1.ShowDialog() == DialogResult.OK) {
-
richTextBox1.Select();
-
richTextBox1.SelectionColor = colorDialog1.Color;
-
}
-
}
-
//CLEAR / Clear text
-
private
void
toolStripMenuItemClearText_Click(
object
sender, EventArgs e) {
-
richTextBox1.Clear();
-
richTextBox1.Select();
-
}
-
}
}
