我创建了一个用户控件。它基本上是一个具有一些自定义属性的按钮。更改自定义控件在设计时的默认文本属性
public partial class CustomButton : Button {
// My custom properties, constructor and events
}
每次我添加此CustomButton
一个形式,它的默认Text
值设置为 “customButtonX”,其中X是1,2,3,...
我怎样才能改变这种值?我希望它是“buttonX”(X = 1,2,3 ...)。
编辑:当我通过设计视图在表单上添加一个按钮时,我还想使用这个技巧(或者其他任何我必须做的)。当我从工具箱中将CustomButton
拖放到表单时,其含义应该是“buttonX”。
这似乎是正确的路要走。尽管如此,我无法使用OnComponentAdded事件。当我有'aBtn.Text = aBtn.Name.Replace(“customButton”,“button”);'事件中的代码时,什么都不会发生。 – Otiel 2012-08-06 12:18:03
我使用了ComponentChanged,因为组件是第一次添加的,它的Text属性只有在执行OnComponentAdded之后才会改变。你可以看到发生了什么,在附加到不同事件的方法中添加一些MessageBoxes。 – 2012-08-06 12:37:25
你知道是否可以改变'Name'属性吗? – Otiel 2012-08-06 12:57:42