コンピューター実験レポート4のC#フォームデザイン

1.飛行機に乗る目的

1.Windowsフォームデザインの方法を習得します。

2.一般的なフォームコントロールの機能、使用法、プロパティなどを習得します。

3.ファイル関連クラスのプログラミングメソッドとアプリケーションを習得します。

第二に、マシンのコンテンツ

トピック1:

フォームプログラムを作成します。プログラムの実行開始時に、フォームを画面の中央に表示する必要があります。フォームのタイトルは「テストフォーム」で、外観は固定されており、サイズは変更できません。実行結果のテクスチャと関連するプロパティの設定を指定する必要があります。

ソースプログラム:

namespace 题目一
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
        }

        private void button1_Click(object sender, EventArgs e)
        {

            MessageBox.Show(textBox1.Text + " 测试成功!");
        }
    }
}

演算結果:

トピック2:

書籍販売システムをシミュレートするには、フォームにListBoxコントロール、ComboBoxコントロール、および削除ボタンを設定します。ComboBoxは、デフォルトで次の5冊の本のデータを保存します。

Java2プログラミング

C#プログラミング

C++プログラミング

動作中のASP.NET

VB.NETの戦闘

ユーザーがドロップダウンメニューを展開し、データの任意の項目をクリックして、リストボックスリストにデータを表示できるようにすることができます。削除ボタンをクリックすると、リストボックスで選択した本が削除されます。

ソースプログラム:

namespace 题目二
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            listBox1.Items.Add(comboBox1.SelectedItem);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
        }
    }
}

演算結果:

トピック3:

フォームプログラムを作成します。フォームのコントロールを図1に示します。ここでは、水産物と調味料がGroupBoxコントロールであり、送信後に選択したコンテンツがテキストボックスに表示されます。もう一度クリックして選択すると、テキストボックスがクリアされます。 。

ソースプログラム:

namespace 题目三
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            StartPosition = FormStartPosition.CenterScreen;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text += "您选择的水产是: ";
            if (radioButton1.Checked)
                textBox1.Text += radioButton1.Text + "  ";
            if (radioButton2.Checked)
                textBox1.Text += radioButton2.Text + "  ";
            if (radioButton3.Checked)
                textBox1.Text += radioButton3.Text + "  ";

            if ((!radioButton1.Checked) && (!radioButton2.Checked) && (!radioButton3.Checked))
            {
                textBox1.Text += "不选水产你吃啥?";
            }

            textBox1.Text += "您选择的佐料是: ";
            if (checkBox1.Checked)
                textBox1.Text += checkBox1.Text + " ";
            if (checkBox2.Checked)
                textBox1.Text += checkBox2.Text + " ";
            if (checkBox3.Checked)
                textBox1.Text += checkBox3.Text + " ";

            if ((!checkBox1.Checked) && (!checkBox2.Checked) && (!checkBox3.Checked))
                textBox1.Text += "不选佐料不好吃!";

        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            radioButton1.Checked = false;
            radioButton2.Checked = false;
            radioButton3.Checked = false;
            checkBox1.Checked = false;
            checkBox2.Checked = false;
            checkBox3.Checked = false;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

演算結果:

トピック4:

図2に示すように、マルチドキュメントインターフェイスを設計し、メニューのさまざまなオプションをクリックして、メインフォームでサブフォームの3つの異なる配置を実現し、フォームを閉じる機能を実現します。

ソースプログラム:

namespace 题目四
{
    public partial class Form1 : Form
    {
        int z = 1;
        public Form1()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
            this.IsMdiContainer = true;
        }

        private void 加载子窗体ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Console.WriteLine("加载子窗体");
            Form f = new Form();
            f.MdiParent = this;
            f.Text = "窗体" + (z++);
            f.Show();
        }

        private void 水平平铺ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void 垂直平铺ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void 层叠平铺ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void 关闭子窗体ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.MdiChildren.Length > 0) 
            {
                foreach (Form myForm in this.MdiChildren)
                    myForm.Close();
            }
        }
    }
}

演算結果:

おすすめ

転載: blog.csdn.net/qq_45037155/article/details/124276074