C# menuStrip菜單欄 toolStrip工具條 statusStrip狀態欄_常用操作、主窗體,子窗體

1.實現子窗體在父窗體內的顯示和排列

要先設置父窗體的IsMdiContainer = true;

        public void openForm2()
        {
            frm2 form2 = new frm2();
            form2.TopLevel = false;//設置該窗體不爲頂級窗體。
            form2.MdiParent = this;
            //form1.showdialog();//錯誤,因爲TopLevel屬性爲false.
            form2.Show(); //正常
        }
MdiLayout枚舉成員及說明
Casecade 層疊在父窗體
TileHorizontal 水平平鋪
TitleVertical 垂直平鋪
        private void 垂直排列ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

 

2. 加載文檔到窗體內 richboxtext

        private void frmHelp_Load(object sender, EventArgs e)
        {
            this.richTextBox1.LoadFile("123.rtf", RichTextBoxStreamType.RichText);
        }

3.toolStrip上的tooltip可以在tooltip上屬性值一欄設置, 菜單欄快捷操作ShortcutKeys

4.子菜單項中加入separator可以直接右鍵添加separtor

就加入了分隔線 

5.關閉所有子窗體

        public void closeForm()
        {
            foreach (Form myForm in this.MdiChildren)// 遍歷所有子窗體{
            {
                myForm.Close(); //關閉子窗體
            }
        }

6.退出對話框寫法

DialogResult dr = MessageBox.Show("確認退出嗎?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2);
if (dr == DialogResult.Yes)
{
    Application.Exit();
}

 

 

 

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