[Windows] making the text box

Renderings

 

 


[New knowledge]

1, Sender As attempted conversion.

Null is returned if the conversion failed.

private void ToolStripMenuItem_Click(object sender, EventArgs e)
ToolStripMenuItem menu = sender as ToolStripMenuItem;

 

2, the color processing portion

1), the menu bar has been pre-selected check mark Name.Checked = true.

2), change color:

richTextBox1.ForeColor = Color.Black;

3), the status display frame

toolStripStatusLabel2.Text = menu.Text;

 

4), custom color window

// 1, to drag the color box on the form; create a color dialog 
ColorDialog ColorDialog1 = new new ColorDialog ();
 // 2, displays a dialog box 
the DialogResult DR = colorDialog1.ShowDialog ();
 IF (DR == the DialogResult . OK) 
{ 
    richTextBox1.ForeColor = colorDialog1.Color; 
}

 

【Display of results】

 

 

 

DETAILED Code]

. 1  Private  void ToolStripMenuItem_Click ( Object SENDER, EventArgs E)
 2          {
 . 3              the ToolStripMenuItem MENU = SENDER AS the ToolStripMenuItem;
 . 4              IF (! MENU = null )
 . 5              {
 . 6                  // set Check text box foreground color attribute + + status box 
. 7                  Red.Checked = to false ;
 . 8                  Green.Checked = to false ;
 . 9                  Default.Checked = to false ;
 10                  CustomizeColor.Checked =false;
11 
12                 menu.Checked = true;
13                 switch (menu.Name)
14                 {
15                     case "Red": 
16                         richTextBox1.ForeColor = Color.Red;
17                         break;
18                     case "Green": 
19                         richTextBox1.ForeColor = Color.Green;
20                         break;
21                     case "Default": 
22                         = richTextBox1.ForeColor Color.Black;
 23 is                          BREAK ;
 24                      default :
 25                          // . 1, the color box to the form drag; creates a color box 
26 is                          ColorDialog ColorDialog1 = new new ColorDialog ();
 27                          // 2, the display dialog box 
28                          the DialogResult DR = colorDialog1.ShowDialog ();
 29                          IF (DR == DialogResult.OK)
 30                          {
 31 is                              richTextBox1.ForeColor = colorDialog1.Color;
 32                          }
 33 is                         break;
34                 }
35                 toolStripStatusLabel2.Text = menu.Text;
36             }
37         }
Color of the text box

 


 

 

3, part of the font size

toolStripComboBox1 (collection - Items)

Renderings

 

 

private void toolStripComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
  if (toolStripComboBox1.SelectedIndex == 0)
    richTextBox1.Font = new Font(richTextBox1.Font.FontFamily, 10);
  else
       richTextBox1.Font = new Font(richTextBox1.Font.FontFamily, 20);
}

 


 

4, shortcut menu (right display)

Icon:

 

DETAILED Code]

private void 撤销ToolStripMenuItem_Click(object sender, EventArgs e)
{
    richTextBox1.Undo();
}

 

Guess you like

Origin www.cnblogs.com/Osea/p/12524792.html