作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们使用派生的表单类,为我们的软件提供一个基本表单类。
在派生表单上,我们广泛使用 DataBinding 来处理我们的 BusinessObjects,所有这些都实现了 IDataErrorInfo,通过 ErrorProviders 在 GUI 的错误输入上抛出自定义错误消息。
我现在正在寻找一种方法来在基本表单类中实现一个函数,以获取表单上的所有 ErrorProvider 组件,并将表单上每个控件的 IconAlignment 设置为左侧(因为右侧是间距问题) .
欢迎任何提示...
设置图标对齐的代码:
private void SetErrorProviderIconAlignment(ErrorProvider errorProvider, Control control)
{
errorProvider.SetIconAlignment(control, ErrorIconAlignment.MiddleLeft);
foreach (Control subControl in control.Controls)
{
SetErrorProviderIcon(errorProvider, subControl);
}
}
最佳答案
我们使用继承的 ErrorProvider
组件来强制设置/返回 IconAlignment 扩展属性的默认值。
例如
[ToolboxBitmap(typeof(ErrorProvider))]
[ProvideProperty("IconAlignment", typeof(Control))]
public class MyErrorProvider : ErrorProvider
{
#region Base functionality overrides
// We need to have a default that is explicitly different to
// what we actually want so that the designer generates calls
// to our SetIconAlignment method so that we can then change
// the base value. If the base class made the GetIconAlignment
// method virtual we wouldn't have to waste our time.
[DefaultValue(ErrorIconAlignment.MiddleRight)]
public new ErrorIconAlignment GetIconAlignment(Control control)
{
return ErrorIconAlignment.MiddleLeft;
}
public new void SetIconAlignment(Control control, ErrorIconAlignment value)
{
base.SetIconAlignment(control, ErrorIconAlignment.MiddleLeft);
}
#endregion
}
然后您可以轻松地搜索/替换 new ErrorProvider()
并替换为 new MyErrorProvider()
。
我记不清了,但您可能会发现您可能需要打开窗体的设计器才能让它重新序列化传递给 form.designer.cs 中的
文件...SetIconAlignment
的值
关于c# - 如何以编程方式为所有控件设置 ErrorProvider Icon,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2864638/
在 Rails 中,您可以使用嵌套路由为 has_one 和 has_many 关系创建 RESTful 路由。可以在 Rails Guides 上找到示例 请问有没有什么好的方法可以为habtm关系
我是一名优秀的程序员,十分优秀!