从工具箱中拖动用户控件时如何设置默认文本 [英] How to set the default text when dragging a user control from the toolbox

查看:65
本文介绍了从工具箱中拖动用户控件时如何设置默认文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过继承按钮基础控件并将其命名为myButton并将按钮文本设置为"ABC"来制作了一个简单的用户控件.

当我将myButton从工具箱拖到窗体上时,按钮文本变为"myButton1".

有没有办法保留原始文本,并且MAYBE也可以控制名称?

JP

I have made a simple user control by inheriting the button base control and named it myButton and have set the button text to ''ABC''.

When I drag the myButton from the toolbox onto a form, the button text becomes ''myButton1''.

Is there a way to keep the original text and MAYBE also control the name?

JP

推荐答案

是的,您可以使用 ^ ]

样本:
Yes, you can control it using ToolboxData Attribute[^]

Sample:
[ToolboxData("<{0}:MyLabel Text=''MyLabel'' BorderColor=''Yellow'' runat=\''server\''>")]


或者,如果它是Windows Form应用程序,则按如下所示覆盖OnPaint事件

Alternatively If it is a Windows Form application then override the OnPaint event as below

protected override void OnPaint(System.Windows.Forms.PaintEventArgs pevent)
{
    this.Text = "ABC";
    base.OnPaint(pevent);
}


这篇关于从工具箱中拖动用户控件时如何设置默认文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆