控件:工具栏菜单栏

 
namespace WorkTime
{
    
public partial class Form1 : Form
    
{
        
private string workTime;
        
public Form1()
        
{
            InitializeComponent();
        }

        
public string MyWorkTime
        
{
            
set
            
{
                workTime 
= value;
            }

            
get
            
{
                
return workTime;
            }

        }


        
private void button1_Click(object sender, EventArgs e)
        
{
            Form1 test 
= new Form1();
            test.MyWorkTime 
= "我的工作时间是" + this.textBox1.Text;
            
this.label1.Text = test.MyWorkTime;
        }

    }

}

上例是有一个可以在区域中填写内容,按下按钮后就可以显示出来。

linkLabel         键接

linkLabel1_LinkClicked

System.Diagnostics.Process.Start("http://www.baidu.com");
-----------------------------------------------------------------------------------

退出

this.Close();

--------------------------
ALT+快捷方式
(&字母)

按ALT可以跳到menuStrip上去

--------------------------
组合键
ALT   SHIFT   CTRL
ShortcutKeys   设置为True   并可以选择.

-------------------------------------------------------------------------------------
在toolStrip中,
按钮有按下去的效果:CheckOnClick  选为True

-------------------------------------------------------------------------------------
ComboBox可以有下拉菜单的效果
   选Items 并在里面加内容.

   事件 SelectedIndexChanged

---------------------------------------------------------------------------------------
richTextBox
  提供一个可以输写文字的空间。
----------------------------------------------------------------------------------------
从现有的label1中的字体创建新的字体,myFontStyle是一个FontStyle枚举:
Bold 加粗文本
Italic 倾斜文本
Regular 普通文本
Strikeout 中间有直线通过的文本
Underline 带下划线的文本
这些值,用二进制表示的,有可能是00001,00010,00100,01000,10000
这样,就可以用二进制运算符对其进行运算了
如果myFontStyle = Bold | Italic,
myFontStyle = 00001|00010
那么,得到的结果将会是00011,右数第一位第二位都是一,表示,字体即是Blod,也是Italic,即粗的斜体.
如果myFontStyle = Bold | Italic.这里是粗斜体.
如果我想除掉斜体呢,那么
myFontStyle=myFontStyle &(~FontStyle.Italic );
即myFontStyle=00011 & (~00010)
=00011 & 11101
=00001
这样,刚好通过00010将00011的右数第二位变成0了.

附注:
|表示"或", 1|1=1,1|0=1,0|1=1,0|0=0
&表示"与", 1|1=1,1&0=0,0&1=0,0&0=0
~表示"反", ~1=0,~0=1,~00010=11101逐位求反
----------------------------------------------------------------------------------------
click事件   里面要带参数

Font newfont;
            Font oldfont;
            oldfont = this.richTextBox1.SelectionFont;
            bool checkState = ((ToolStripButton)sender).Checked;
            if(checkState && !oldfont.Bold)
            {
                newfont = new Font(oldfont, oldfont.Style | FontStyle.Bold);
            }
            else
            {
                newfont = new Font(oldfont, oldfont.Style & ~FontStyle.Bold);   
            }
            this.richTextBox1.SelectionFont=newfont;
            this.richTextBox1.Focus();
----------------------------------------------------------------------------------
----------------------------------------------------------------------------------

CheckedChanged   重点区分啊!

this.toolStripButton1.Checked=this.boldToolStripMenuItem.Checked;


---------------------------------------------------------------------------------

下面代码是一个文字编辑

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Application1
{
    
public partial class Form1 : Form
    
{
        
public Form1()
        
{
            InitializeComponent();
        }


        
private void Form1_Load(object sender, EventArgs e)
        
{

        }


        
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        
{
            System.Diagnostics.Process.Start(
"http://www.baidu.com");
            
        }


        
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        
{
            
this.Close();
        }


        
//private void toolStripButton1_Click(object sender, EventArgs e)
        
//{
        
//    Font newfont;
        
//    Font oldfont;
        
//    oldfont = this.richTextBox1.SelectionFont;
        
//    bool checkState = ((ToolStripButton)sender).Checked;
        
//    if(checkState && !oldfont.Bold)
        
//    {
        
//        newfont = new Font(oldfont, oldfont.Style | FontStyle.Bold);
        
//    }
        
//    else
        
//    {
        
//        newfont = new Font(oldfont, oldfont.Style & ~FontStyle.Bold);    
        
//    }
        
//    this.richTextBox1.SelectionFont=newfont;
        
//    this.richTextBox1.Focus();
        
//}

        
//private void toolStripButton2_Click(object sender, EventArgs e)
        
//{
        
//    Font newfont;
        
//    Font oldfont;
        
//    oldfont = this.richTextBox1.SelectionFont;
        
//    bool checkState = ((ToolStripButton)sender).Checked;
        
//    if (checkState && !oldfont.Italic)
        
//    {
        
//        newfont = new Font(oldfont, oldfont.Style | FontStyle.Italic);
        
//    }
        
//    else
        
//    {
        
//        newfont = new Font(oldfont, oldfont.Style & ~FontStyle.Italic);
        
//    }
        
//    this.richTextBox1.SelectionFont = newfont;
        
//    this.richTextBox1.Focus();
        
//}

        
//private void toolStripButton3_Click(object sender, EventArgs e)
        
//{
        
//    Font newfont;
        
//    Font oldfont;
        
//    oldfont = this.richTextBox1.SelectionFont;
        
//    bool checkState = ((ToolStripButton)sender).Checked;
        
//    if (checkState && !oldfont.Underline)
        
//    {
        
//        newfont = new Font(oldfont, oldfont.Style | FontStyle.Underline);
        
//    }
        
//    else
        
//    {
        
//        newfont = new Font(oldfont, oldfont.Style & ~FontStyle.Underline);
        
//    }
        
//    this.richTextBox1.SelectionFont = newfont;
        
//    this.richTextBox1.Focus();
        
//}

        
private void toolStripComboBox1_SelectedIndexChanged(object sender, EventArgs e)
        
{
            
string str = ((ToolStripComboBox)sender).SelectedItem.ToString();
            Font newFont 
= new Font(str, 30, richTextBox1.SelectionFont.Style);
            richTextBox1.SelectionFont 
= newFont;
        }


        
private void toolStripButton1_CheckedChanged(object sender, EventArgs e)
        
{
            Font newfont;
            Font oldfont;
            oldfont 
= this.richTextBox1.SelectionFont;
            
bool checkState = ((ToolStripButton)sender).Checked;
            
if (checkState && !oldfont.Bold)
            
{
                newfont 
= new Font(oldfont, oldfont.Style | FontStyle.Bold);
            }

            
else
            
{
                newfont 
= new Font(oldfont, oldfont.Style & ~FontStyle.Bold);
            }

            
this.richTextBox1.SelectionFont = newfont;
            
this.richTextBox1.Focus();
        }


        
private void toolStripButton2_CheckedChanged(object sender, EventArgs e)
        
{
            Font newfont;
            Font oldfont;
            oldfont 
= this.richTextBox1.SelectionFont;
            
bool checkState = ((ToolStripButton)sender).Checked;
            
if (checkState && !oldfont.Italic)
            
{
                newfont 
= new Font(oldfont, oldfont.Style | FontStyle.Italic);
            }

            
else
            
{
                newfont 
= new Font(oldfont, oldfont.Style & ~FontStyle.Italic);
            }

            
this.richTextBox1.SelectionFont = newfont;
            
this.richTextBox1.Focus();
        }


        
private void toolStripButton3_CheckedChanged(object sender, EventArgs e)
        
{
            Font newfont;
            Font oldfont;
            oldfont 
= this.richTextBox1.SelectionFont;
            
bool checkState = ((ToolStripButton)sender).Checked;
            
if (checkState && !oldfont.Underline)
            
{
                newfont 
= new Font(oldfont, oldfont.Style | FontStyle.Underline);
            }

            
else
            
{
                newfont 
= new Font(oldfont, oldfont.Style & ~FontStyle.Underline);
            }

            
this.richTextBox1.SelectionFont = newfont;
            
this.richTextBox1.Focus();
        }


      

        
private void boldToolStripMenuItem_CheckedChanged(object sender, EventArgs e)
        
{
            
this.toolStripButton1.Checked = this.boldToolStripMenuItem.Checked;
        }


        
private void italicToolStripMenuItem_CheckedChanged(object sender, EventArgs e)
        
{
            
this.toolStripButton2.Checked = this.italicToolStripMenuItem.Checked;
        }


        
private void underLineToolStripMenuItem_CheckedChanged(object sender, EventArgs e)
        
{
            
this.toolStripButton3.Checked = this.underLineToolStripMenuItem.Checked;
        }


     
       
    }

}

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章