怎么在按钮单击事件里获取下面文本框的值Grid grid = new Grid;gridRowDefinitionsAddnew RowDefinition Height = new GridLength70 ;gridRowDefinitionsAddnew RowDefinition Height = GridLengthAuto ;gridRowDefinitionsAddnew Row
假设你要在某个按钮的单击事件中获取第一个文本框的值,可以这样做:
private void Button_Click(object sender, RoutedEventArgs e) { // 获取第一个文本框 TextBox firstTextBox = (TextBox)grid.Children[4];
// 获取文本框的值
string value = firstTextBox.Text;
// 在控制台输出值
Console.WriteLine(value);
}
在这个例子中,第一个文本框的索引是4,因为它是第二行第一个单元格的子元素。你可以根据自己的需要修改索引,或者使用其他方法来获取文本框的引用。
原文地址: https://www.cveoy.top/t/topic/cZCc 著作权归作者所有。请勿转载和采集!