C#winformナビゲーションインタフェース..winform用groupbox,buttonとlistview

8161 ワード

winformはbuttonとlistviewを利用してQQ設定のようなナビゲーションメニューを実現する.
主にDockStyleを利用しています.
具体的なコードは以下の通りです.
(注)特にコントロールの作成順序に注意してください.
私のコントロールの作成順序は次のとおりです(.Design.cs).
            this .groupBox1 = new System .Windows . Forms. GroupBox ();
            this .button1 = new System .Windows . Forms. Button ();
            this .button2 = new System .Windows . Forms. Button ();
            this .button3 = new System .Windows . Forms. Button ();
            this .button4 = new System .Windows . Forms. Button ();
            this .button5 = new System .Windows . Forms. Button ();
            this .button6 = new System .Windows . Forms. Button ();
            this .listView1 = new System .Windows . Forms. ListView ();

主なコードは次のとおりです.
//listviewと6つのbuttonでナビゲーションメニューを実現できる
private void button1_Click( object sender, EventArgs e)
        {
            ResetButton();  //reset button


            listView1 . Dock = DockStyle. None;


            button2 . Dock = DockStyle. Bottom;
            button3 . Dock = DockStyle. Bottom;
            button4 . Dock = DockStyle. Bottom;
            button5 . Dock = DockStyle. Bottom;
            button6 . Dock = DockStyle. Bottom;


            listView1 . BringToFront();
            listView1 . Dock = DockStyle. Bottom;
            listView1 . Clear();
        }


        private void button2_Click( object sender, EventArgs e)
        {
            ResetButton();  //reset button
            listView1 . Dock = DockStyle. None;


            button3 . Dock = DockStyle. Bottom;
            button4 . Dock = DockStyle. Bottom;
            button5 . Dock = DockStyle. Bottom;
            button6 . Dock = DockStyle. Bottom;




            listView1 . BringToFront();
            listView1 . Dock = DockStyle. Bottom;
            listView1 . Clear();


        }


        private void button3_Click( object sender, EventArgs e)
        {
            ResetButton();  //reset button


            listView1 . Dock = DockStyle. None;


            button4 . Dock = DockStyle. Bottom;
            button5 . Dock = DockStyle. Bottom;
            button6 . Dock = DockStyle. Bottom;




            listView1 . BringToFront();
            listView1 . Dock = DockStyle. Bottom;
            listView1 . Clear();
        }


        private void button4_Click( object sender, EventArgs e)
        {
            ResetButton();  //reset button


            listView1 . Dock = DockStyle. None;


            button5 . Dock = DockStyle. Bottom;
            button6 . Dock = DockStyle. Bottom;




            listView1 . BringToFront();
            listView1 . Dock = DockStyle. Bottom;
            listView1 . Clear();
        }


        private void button5_Click( object sender, EventArgs e)
        {
            ResetButton();  //reset button


            listView1 . Dock = DockStyle. None;


            button6 . Dock = DockStyle. Bottom;




            listView1 . BringToFront();
            listView1 . Dock = DockStyle. Bottom;
            listView1 . Clear();
        }


        private void button6_Click( object sender, EventArgs e)
        {
            ResetButton();  //reset button


        }


        public void ResetButton()          // 
        {


            button1 . Dock = DockStyle. Bottom;
            button2 . Dock = DockStyle. Bottom;
            button3 . Dock = DockStyle. Bottom;
            button4 . Dock = DockStyle. Bottom;
            button5 . Dock = DockStyle. Bottom;
            button6 . Dock = DockStyle. Bottom;
            listView1 . Dock = DockStyle. Bottom;


            listView1 . Dock = DockStyle. None;
            button1 . Dock = DockStyle. None;
            button2 . Dock = DockStyle. None;
            button3 . Dock = DockStyle. None;
            button4 . Dock = DockStyle. None;
            button5 . Dock = DockStyle. None;
            button6 . Dock = DockStyle. None;


        }

次のような効果が得られます.
-------------------------------------------------------------------------------------2012年8月30日10:13:50
winformはbuttonとlistviewを利用してQQ設定のようなナビゲーションメニューを実現する.
主にDockStyleを利用しています.
具体的なコードは以下の通りです.
(注)特にコントロールの作成順序に注意してください.
私のコントロールの作成順序は次のとおりです(.Design.cs).
            this .groupBox1 = new System .Windows . Forms. GroupBox ();
            this .button1 = new System .Windows . Forms. Button ();
            this .button2 = new System .Windows . Forms. Button ();
            this .button3 = new System .Windows . Forms. Button ();
            this .button4 = new System .Windows . Forms. Button ();
            this .button5 = new System .Windows . Forms. Button ();
            this .button6 = new System .Windows . Forms. Button ();
            this .listView1 = new System .Windows . Forms. ListView ();

主なコードは次のとおりです.
//listviewと6つのbuttonでナビゲーションメニューを実現できる
private void button1_Click( object sender, EventArgs e)
        {
            ResetButton();  //reset button


            listView1 . Dock = DockStyle. None;


            button2 . Dock = DockStyle. Bottom;
            button3 . Dock = DockStyle. Bottom;
            button4 . Dock = DockStyle. Bottom;
            button5 . Dock = DockStyle. Bottom;
            button6 . Dock = DockStyle. Bottom;


            listView1 . BringToFront();
            listView1 . Dock = DockStyle. Bottom;
            listView1 . Clear();
        }


        private void button2_Click( object sender, EventArgs e)
        {
            ResetButton();  //reset button
            listView1 . Dock = DockStyle. None;


            button3 . Dock = DockStyle. Bottom;
            button4 . Dock = DockStyle. Bottom;
            button5 . Dock = DockStyle. Bottom;
            button6 . Dock = DockStyle. Bottom;




            listView1 . BringToFront();
            listView1 . Dock = DockStyle. Bottom;
            listView1 . Clear();


        }


        private void button3_Click( object sender, EventArgs e)
        {
            ResetButton();  //reset button


            listView1 . Dock = DockStyle. None;


            button4 . Dock = DockStyle. Bottom;
            button5 . Dock = DockStyle. Bottom;
            button6 . Dock = DockStyle. Bottom;




            listView1 . BringToFront();
            listView1 . Dock = DockStyle. Bottom;
            listView1 . Clear();
        }


        private void button4_Click( object sender, EventArgs e)
        {
            ResetButton();  //reset button


            listView1 . Dock = DockStyle. None;


            button5 . Dock = DockStyle. Bottom;
            button6 . Dock = DockStyle. Bottom;




            listView1 . BringToFront();
            listView1 . Dock = DockStyle. Bottom;
            listView1 . Clear();
        }


        private void button5_Click( object sender, EventArgs e)
        {
            ResetButton();  //reset button


            listView1 . Dock = DockStyle. None;


            button6 . Dock = DockStyle. Bottom;




            listView1 . BringToFront();
            listView1 . Dock = DockStyle. Bottom;
            listView1 . Clear();
        }


        private void button6_Click( object sender, EventArgs e)
        {
            ResetButton();  //reset button


        }


        public void ResetButton()          // 
        {


            button1 . Dock = DockStyle. Bottom;
            button2 . Dock = DockStyle. Bottom;
            button3 . Dock = DockStyle. Bottom;
            button4 . Dock = DockStyle. Bottom;
            button5 . Dock = DockStyle. Bottom;
            button6 . Dock = DockStyle. Bottom;
            listView1 . Dock = DockStyle. Bottom;


            listView1 . Dock = DockStyle. None;
            button1 . Dock = DockStyle. None;
            button2 . Dock = DockStyle. None;
            button3 . Dock = DockStyle. None;
            button4 . Dock = DockStyle. None;
            button5 . Dock = DockStyle. None;
            button6 . Dock = DockStyle. None;


        }

次のような効果が得られます.
-------------------------------------------------------------------------------------2012年8月30日10:13:50