第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

使用復(fù)選框動(dòng)態(tài)添加組合框

使用復(fù)選框動(dòng)態(tài)添加組合框

C#
呼喚遠(yuǎn)方 2022-09-04 16:29:51
我正在嘗試在單擊復(fù)選框時(shí)添加組合框。我使用的代碼如下。就目前而言,我可以讓它在已經(jīng)存在的組合框中移動(dòng),但它不會(huì)創(chuàng)建一個(gè)新的組合框。        private void checkBox1_CheckedChanged(object sender, EventArgs e)    {        // Determine the CheckState of the check box.          if (checkBox1.CheckState == CheckState.Checked)        {              combo.Items.AddRange(new object[] {                "Item 1",                "Item 2",                "Item 3",                "Item 4",                "item 5",                "Item 6"});            combo.Location = new System.Drawing.Point(19, 123);            combo.Name = "combo";            combo.Size = new System.Drawing.Size(121, 21);            combo.TabIndex = 0;            combo.SelectedIndexChanged += new System.EventHandler(this.combo_SelectedIndexChanged);            combo.BringToFront();            this.AllowDrop = false;        }    }    private void checkBox1_Click(object sender, System.EventArgs e)    {        switch (checkBox1.CheckState)        {            case CheckState.Checked:                ComboBox combo = new ComboBox();                Controls.Add(combo);                break;            case CheckState.Unchecked:                break;            case CheckState.Indeterminate:                break;        }    }
查看完整描述

1 回答

?
慕婉清6462132

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超2個(gè)贊

解決方法是注意要將語句放入哪個(gè)函數(shù)。組合框的設(shè)置(范圍,位置等)將在條件下的函數(shù)中。這些將與 和 一起,以防萬一它最終落后于某些東西。CheckChangedif checkedgroupbox.controls.add();combo.BringToFront();


private void checkBox1_CheckedChanged(object sender, EventArgs e)

    {

        // Determine the CheckState of the check box.  

        if (checkBox1.CheckState == CheckState.Checked)

        {

            groupBox1.Controls.Add(combo);

            combo.Items.AddRange(new object[] {

                "Item 1",

                "Item 2",

                "Item 3",

                "Item 4",

                "Item 5",

                "Item 6"});

            combo.Location = new System.Drawing.Point(19, 123);

            combo.Name = "combo";

            combo.Size = new System.Drawing.Size(121, 21);

            combo.TabIndex = 0;

            combo.SelectedIndexChanged += new System.EventHandler(this.combo_SelectedIndexChanged);

            combo.BringToFront();


            this.AllowDrop = false;

}

同時(shí),在函數(shù)中,您必須實(shí)例化組合框并添加它。Click


    private void checkBox1_Click(object sender, System.EventArgs e)

    {

        switch (checkBox1.CheckState)

        {

            case CheckState.Checked:

                ComboBox combo = new ComboBox();

                Controls.Add(combo);

                break;

            case CheckState.Unchecked:


                break;

            case CheckState.Indeterminate:


                break;

        }

    }

如果您想在取消選中復(fù)選框后刪除組合框,只需添加


        if (checkBox1.CheckState == CheckState.Unchecked)

        {

            groupBox1.Controls.Remove(combo);

            Controls.Remove(combo);

            combo.Items.Clear();

        }

進(jìn)入函數(shù)。確保放置,否則它會(huì)將組合框的新實(shí)例的范圍添加到舊實(shí)例中。private void checkBox1_CheckedChanged(object sender, EventArgs e)combo.items.Clear()


查看完整回答
反對 回復(fù) 2022-09-04
  • 1 回答
  • 0 關(guān)注
  • 105 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號