简体   繁体   English

如何访问 C# 中 Winform TableLayoutPanel 中的每个字段

[英]How to access each field in a Winform TableLayoutPanel in C#

I have a TableLayoutPanel in Winforms , each field contains exactly one label.我在Winforms中有一个TableLayoutPanel ,每个字段都包含一个 label。 I now need to get the row/colum and also what is in that field.我现在需要获取行/列以及该字段中的内容。

fE: I have to check if the lables in the first row all have the same text. fE:我必须检查第一行中的标签是否都具有相同的文本。

How can I do that?我怎样才能做到这一点?

I have to check if the lables in the first row all have the same text.我必须检查第一行中的标签是否都具有相同的文本。

Use TableLayoutPanel.GetControlFromPosition in a loop...something like:在循环中使用TableLayoutPanel.GetControlFromPosition ...类似于:

private void button1_Click(object sender, EventArgs e)
{
    bool matching = RowMatches(0);
    Console.WriteLine(matching);
}

private bool RowMatches(int row)
{
    string value = null;
    for(int col=0; col<tableLayoutPanel1.ColumnCount; col++)
    {
        Label lbl = (Label)tableLayoutPanel1.GetControlFromPosition(col, row);
        if (value == null)
        {
            value = lbl.Text;
        }
        else if (lbl.Text != value)
        {
            return false;
        }
    }
    return true;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM