- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我的应用程序中有一个包含子控件的组框。(如附加图片所示)。我想枚举所有文本框以使用简单的 foreach 循环执行一些验证。
这份文件大纲将给出控件外壳的合理概念
foreach (Control control in grpBxTargetSensitivity.Controls)
{
if (control is FlowLayoutPanel && control.HasChildren)
{
foreach (Control ctrl in control.Controls)
{
if (ctrl is Panel && ctrl.HasChildren)
{
foreach (Control tbox in ctrl.Controls)
{
if (tbox is TextBox)
{
TextBox textbox = tbox as TextBox;
validData &= !string.IsNullOrWhiteSpace(textbox.Text);
}
}
}
}
}
}
我的问题是,是否有比上述方法更好的方法(可能通过 LINQ)来获取面板内的所有控件,包括文本框。?
最佳答案
我不知道这样更好..是否更容易阅读是一个见仁见智的问题:
var validData
= grpBxTargetSensitivity.Controls.OfType<FlowLayoutPanel>()
.SelectMany(c => c.Controls.OfType<Panel>())
.SelectMany(c => c.Controls.OfType<TextBox>())
.All(textbox => !string.IsNullOrWhiteSpace(textbox.Text));
这将抓取您的 GroupBox 中所有 FlowLayoutPanel 中所有面板内的所有 TextBox,如果 所有 这些 TextBox 中都有值,则返回 true
。 p>
关于c# - 获取组框内的子控件列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30295242/
我正在尝试将按钮和 div 底部的一些文本对齐,就像下面的示例中的价格和 checkout 按钮一样。最好的方法是什么。我制作了一个 div,对其设置了样式以获得正确的文本和图片。我只需要将按钮附加到
将内容放置在带圆 Angular 的框 div 中以使其不会重叠的正确方法是什么? 蓝框是白框父div 里面的内容div。我希望标题位于该父框内,以便它在顶部也有圆 Angular 。 当我尝试“溢出
让 SVG 内联 HTML 文档,带有一个 View 框“x y w h”。如何检查元素是否在 View 框内? 通过说元素,它可以是组内的嵌套子路径等等...... 所以我想我正在寻找 SVG 的内
有没有办法检查鼠标是否在屏幕上的某个框内。我不知道将 jQuery 变量导出为整数以在 Javascript if 语句 中使用。我知道这可以通过 div 实现,但我不想使用 div 因为我需要很多这
目前我有两个带文本的 div 框 1 和 2,在第三个 div 框内将它们包含在一起。 Sometimes text in box 1 is longer than text inside box2
我是一名优秀的程序员,十分优秀!