- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 TableLayoutPanel 和 anchor 属性来制作一个独立于屏幕分辨率或窗体大小调整而看起来不错的窗口应用程序。我提到了 this article为了设计winform。
我的表单上有 3 个 RadioButtons
。在没有 TableLayoutPanel
的情况下工作之前,RadioButtons
的行为符合我的预期。选中一个 RadioButton
,取消选中另外两个。将每个 RadioButton
添加到 TableLayoutPanel
的不同单元格后,RadioButtons
的行为发生了变化。选中一个 RadioButton
不会取消选中其他按钮。
是否有任何我可以设置的属性(组属性)让 3 个 RadioButtons
一起工作?
最佳答案
首先让我说,一个好的解决方案的关键是保持属于一个组的按钮的视觉范例;用户一定不会对 RadioButtons
感到惊讶,尽管它们彼此相距很远。但您的布局似乎可以很好地解决这一问题。
可能正是出于这个原因,没有允许随机分组 RB 的属性..
这是一个帮助器类,它独立于容器管理 RadioButtons
..:
class RadioCtl
{
private List<RadioButton> buttons { get; set; }
private bool auto = false;
public RadioCtl() { buttons = new List<RadioButton>(); }
public int RegisterRB(RadioButton rb)
{
if (!buttons.Contains(rb))
{
buttons.Add(rb);
rb.CheckedChanged += rb_CheckedChanged;
}
return buttons.IndexOf(rb);
}
void rb_CheckedChanged(object sender, EventArgs e)
{
RadioButton rbClicked = sender as RadioButton;
if (rbClicked == null || auto) return;
auto = true;
foreach (RadioButton rb in buttons)
{
if ((rb != rbClicked) && (rb.Parent != rbClicked.Parent) )
rb.Checked = false;
}
auto = false;
}
public void UnregisterRB(RadioButton rb)
{
if (buttons.Contains(rb))
{
buttons.Remove(rb);
rb.CheckedChanged -= rb_CheckedChanged;
}
}
public void Clear() { foreach(RadioButton rb in buttons) UnregisterRB(rb); }
public int IndexOfRB(RadioButton rb) { return buttons.IndexOf(rb); }
}
要使用它,您需要注册每个要加入“虚拟组”的RadioButton
..:
static RadioCtl RbCtl = new RadioCtl();
public Form1()
{
InitializeComponent();
RbCtl.RegisterRB(radioButton1);
RbCtl.RegisterRB(radioButton2);
RbCtl.RegisterRB(radioButton3);
RbCtl.RegisterRB(radioButton4);
RbCtl.RegisterRB(radioButton5);
}
您可以随时注销或重新注册任何RadioButton
或在组中查找索引。
另请注意,这仅支持一个 组RadioButtons
。如果您需要更多,请使用第二个对象或扩展该类以允许多个可能命名的组。为此,您可以将 List
替换为 Dictionary
并稍微扩展签名和代码..
关于c# - TableLayoutPanel 中的单选按钮行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37675837/
我有一个名为 tlpMaster 的 tableLayoutPanel。它有 4 列和 8 行。在 3 列和每一行中,它都有另一个 tableLayoutPanel。所以这就是 3 个内部的。在那些里
我有一些 TableLayoutPanel,其中第一个“层”有 1 列和 10 行,其中一些行包含 UserControl 或另一个具有 2 或 3 列和一些行的 TableLayoutPanel。其
我正在使用 TableLayoutPanel 将客户区域分为 3 行(只有 1 列)。顶排和底排设计为固定高度;它们将包含一个页眉和一个页脚,最初每个页脚都包含一个包含静态文本的子标签控件(只是开始)
有了 TableLayoutPanel 的所有属性,我不知道为什么这不能简单。 我有一个包含两列的 tableLayoutPanel。我试图在第一列内放置一个标签以将其用作标题。我想将它放置在相对于该
我有一个 WinForms 应用程序,它正在从 BackgroundWorker 更新 TableLayoutPanel。根据设备输入是打开 (1) 还是关闭 (0),颜色和一些文本会相应地更改。 t
如果内容高于面板本身,我希望能够在 TableLayoutPanel 内滚动。 我试过: 将 AutoScroll 设置为 true(添加 unnecessary horizontal scrollb
我有一个 TableLayoutPanel,它具有由用户确定的动态数量的列和行。我希望里面的按钮是方形的并且大小相同,但是每当我使用循环来设置列/行样式时,它们永远不会变成我想要的大小。 如何获取列/
在我的应用程序中,我有一个名为“Dashboard.cs”的 WindowsForm,其中有一个名为 dashboardTableItemsWrapper 的 TableLayoutPanel。现在,
我有几个 TableLayoutPanel,每个都在两列中显示一类名称/值信息 - 一列带有信息标签,一列带有数据标签。 在每一个中,我都将第一列设置为自动调整大小并右对齐所有标签,效果很好。但是,它
我有一个 TableLayoutPanel,它在运行时使用文本文件填充行(从文本文件中获取每一行,并将其放入新行中包含的单元格中)。代码看起来像这样: public static string Url
我想在 GUI 的固定区域中的 TableLayoutPanel 中动态添加行。所以,如果记录数量增加,那么我想要一个垂直滚动条来帮助用户查看更多记录。为此,我设置了 PropertyAutoScro
我有一个 TableLayoutPanel,我可以向其中动态添加行。 每行都有一个绝对大小。 我将 AutoScroll 设置为“true”,但是当我添加超出 TableLayoutPanel 显示范
我有一个 TableLayoutPanel,每次我将标签放入其中一个单元格时,它都会捕捉到左上角。我怎样才能到达它而不是这样做或改变它捕捉的位置。 此外,是否可以更改特定单元格的背景颜色? 谢谢! 最
我正在创建一个表格布局面板来显示字典中的值,但表格布局面板一直将我放入单元格中的标签控件截断为 14 个字符。我试图摆弄我的表格布局面板的 ColumnStyles,但没有任何选项会使 Label 控
我在 C#(窗体)中使用 TableLayoutPanel。我的表格很大,有 33 列和 8 行。所有单元格都包含 Label 对象。 我已经通过创建一个新的子类设置了我的 TableLayoutPa
是否可以让 System.Windows.Forms.TableLayoutPanel 在移动到下一列之前填充一列?无论我如何设置 RowCount、ColumnCount 和 GrowStyle,表
我正在使用 TableLayoutPanel 和 anchor 属性来制作一个独立于屏幕分辨率或窗体大小调整而看起来不错的窗口应用程序。我提到了 this article为了设计winform。 我的
我向我的用户控件添加了一个 tableLayoutPanel。 It is not docked or anchored. It has 4 columns and 4 rows. The items
我有 TableLayoutPanel 用于通过 AutoScroll = true 动态创建控件。当我添加新控件时它工作正常。但是当我删除并且所有控件都可见时,垂直滚动是可见的。这里有一些截图: 预
我可能没有使用我想要的正确控件。我正在用控件填充表格,我希望每一列的大小自动适应其中包含的控件。例如,一列文本框将比一列复选框宽。由于不同操作系统、不同 DPI、不同字体等的复杂性,我不想摆弄测量,如
我是一名优秀的程序员,十分优秀!