控件:工具欄菜單欄

 
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;
        }


     
       
    }

}

 

 

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