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

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

循環(huán)文本框

循環(huán)文本框

揚(yáng)帆大魚 2019-08-08 16:59:17
循環(huán)文本框我有一個(gè)winforms應(yīng)用程序,在屏幕上有37個(gè)文本框。每一個(gè)都按順序編號(hào):DateTextBox0DateTextBox1 ...DateTextBox37我試圖遍歷文本框并為每個(gè)文本框分配一個(gè)值:int month = MonthYearPicker.Value.Month;int year = MonthYearPicker.Value.Year;int numberOfDays = DateTime.DaysInMonth(year, month);m_MonthStartDate = new DateTime(year, month, 1);m_MonthEndDate = new DateTime(year, month, numberOfDays);DayOfWeek monthStartDayOfWeek = m_MonthStartDate.DayOfWeek;int daysOffset = Math.Abs(DayOfWeek.Sunday - monthStartDayOfWeek);for (int i = 0; i <= (numberOfDays - 1); i++){  //Here is where I want to loop through the textboxes and assign values based on the 'i' value    DateTextBox(daysOffset + i) = m_MonthStartDate.AddDays(i).Day.ToString();}讓我澄清一下,這些文本框出現(xiàn)在單獨(dú)的面板上(其中37個(gè))。因此,為了讓我循環(huán)使用foreach,我必須遍歷主控件(面板),然后遍歷面板上的控件。它開始變得復(fù)雜。有關(guān)如何將此值分配給文本框的任何建議?
查看完整描述

3 回答

?
慕桂英3389331

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

要以遞歸方式獲取指定類型的所有控件和子控件,請(qǐng)使用以下擴(kuò)展方法:

public static IEnumerable<TControl> GetChildControls<TControl>(this Control control) where TControl : Control{
    var children = (control.Controls != null) ? control.Controls.OfType<TControl>() : Enumerable.Empty<TControl>();
    return children.SelectMany(c => GetChildControls<TControl>(c)).Concat(children);}

用法:

var allTextBoxes = this.GetChildControls<TextBox>();foreach (TextBox tb in allTextBoxes){
    tb.Text = ...;}


查看完整回答
反對(duì) 回復(fù) 2019-08-08
?
蝴蝶不菲

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

您可以循環(huán)顯示表單中的所有控件,如果它是“文本框”,則逐一返回它們的完整列表。

public List GetTextBoxes(){   
    var textBoxes = new List();   
        foreach (Control c in Controls){   
            if(c is TextBox){   
                textBoxes.add(c);   
        }   
    }   return textBoxes;   }


查看完整回答
反對(duì) 回復(fù) 2019-08-08
  • 3 回答
  • 0 關(guān)注
  • 588 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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