ContextMenuStrip
添加控件后可在其他空间属性中进行绑定
MenuStrip
设置热键:在编辑的时候输入(&F)
设置快捷键:选中菜单项--右键属性--ShortCutKeys--设置快捷键
设置分隔线:在输入的时候输入减号(-)
StatusStrip
状态栏,可以添加按钮,文本等
ToolStrip
在ToolStripContainer控件内可被拖动修改位置
ToolStripContainer
帮助ToolStrip布局控件
计算器
/// <summary> /// 根据点击的控件输入数字 /// </summary> /// <param name="e"></param> private void shuru(string str) { "||qk){ textBox1.Text = str; qk = false; } else textBox1.Text += str; } /// <summary> /// 输入数字 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void b0_Click(object sender, EventArgs e) { shuru((sender as Control).Text); } /// <summary> /// 小数点 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dian_Click(object sender, EventArgs e) { if(!textBox1.Text.Contains(".")) textBox1.Text+="."; } /// <summary> /// 退格 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void back_Click(object sender, EventArgs e) { ) textBox1.Text = "; else textBox1.Text = textBox1.Text.Substring(, textBox1.TextLength-); } /// <summary> /// 根据按下的按键键入计算符号 /// </summary> /// <param name="e"></param> private void jis(string str) { if (qk) { if (shang != str) { textBox2.Text = textBox2.Text.Substring(, textBox2.TextLength - ) + str; shang = str; } } else { qk = true; dq = Convert.ToDecimal(textBox1.Text); if (textBox2.Text == "") { jieguo = Convert.ToDecimal(textBox1.Text); textBox2.Text = textBox1.Text + str; shang = str; } else { js(); ) textBox2.Text += textBox1.Text + str; else textBox2.Text += "(" + textBox1.Text + ")" + str; textBox1.Text = jieguo.ToString(); shang = str; } } } //标记是否点击运算符号 bool qk = false; //保存结果 ; ; //上一步操作 string shang = ""; /// <summary> /// 运算符操作 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void jia_Click(object sender, EventArgs e) { jis((sender as Control).Text); } /// <summary> /// 根据上一次运算符操作 /// </summary> private void js() { try { switch(shang) { case "+": jieguo = jieguo + dq; break; case "-": jieguo = jieguo - dq; break; case "*": jieguo = jieguo * dq; break; case "/": jieguo = jieguo / dq; break; } } "; } } /// <summary> /// 等号 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button20_Click(object sender, EventArgs e) { js(); textBox2.Text = ""; textBox1.Text = jieguo.ToString(); } private void button20_KeyPress(object sender, KeyPressEventArgs e) { switch(e.KeyChar) { case '.': if (!textBox1.Text.Contains(".")) textBox1.Text += "."; break; case (char)Keys.Back: ) textBox1.Text = "; else textBox1.Text = textBox1.Text.Substring(, textBox1.TextLength - ); break; : js(); textBox2.Text = ""; textBox1.Text = jieguo.ToString(); break; ': shuru("); break; ': shuru("); break; ': shuru("); break; ': shuru("); break; ': shuru("); break; ': shuru("); break; ': shuru("); break; ': shuru("); break; ': shuru("); break; ': shuru("); break; case '+': jis("+"); break; case '-': jis("-"); break; case '*': jis("*"); break; case '/': jis("/"); break; } } private void button3_Click(object sender, EventArgs e) { textBox1.Text = textBox2.Text = ""; } private void textBox2_TextChanged(object sender, EventArgs e) { textBox1.SelectionStart = textBox1.Text.Length; textBox2.SelectionStart = textBox2.Text.Length; } private void button4_Click(object sender, EventArgs e) { textBox1.SelectionStart = textBox1.Text.Length; }
一版