Designer中的自定义控件范围 [英] Custom Control Bounds in Designer

查看:141
本文介绍了Designer中的自定义控件范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个自定义控件,该控件本质上是一个TextBox,但还包含一个标签.

我主要对设计器中的TextBox属性感兴趣,所以我继承自TextBox.

I am creating a custom control which is essentially a TextBox, but also includes a label.

I am mainly interested in the TextBox properties in the designer, so I am inheriting from TextBox.

Public Class LabelTextBox : Inherits System.Windows.Forms.TextBox

    Protected m_lblLabel As System.Windows.Forms.Label

    Public Sub New()
        m_lblLabel = New System.Windows.Forms.Label()
    End Sub

    Private Sub LabelTextBox_HandleCreated(sender As Object, e As System.EventArgs) Handles Me.HandleCreated
        m_lblLabel.Name = Me.Name + "_Label"
        m_lblLabel.Text = "Default text..."
        m_lblLabel.Left = Me.Left
        m_lblLabel.Top = Me.Top - m_lblLabel.Height
        Me.Parent.Controls.Add(m_lblLabel)
    End Sub

    Private Sub LabelTextBox_HandleDestroyed(sender As Object, e As System.EventArgs) Handles Me.HandleDestroyed
        Me.Parent.Controls.Remove(m_lblLabel)
    End Sub

End Class



我的问题是我希望设计器中的焦点矩形"包围文本框和标签.我试图覆盖WIDTH和HEIGHT以及BOUNDS属性,但似乎无济于事.

请查看以下图片以获得更好的理解:

图片1

图片2

我需要重写哪些属性才能使设计器中的焦点矩形"变大?另外,焦点矩形"的正确术语是什么?

我已经搜索了整个互联网,但找不到答案,我衷心希望有人能帮助我.谢谢.



My problem is that I want the "focus rectangle" in the designer to surround the textbox AND the label. I have tried to override the WIDTH and the HEIGHT and the BOUNDS properties, but nothing seems to work.

Please see the following images for a better understanding:

Image 1

Image 2

Which properties do I need to override to make the "focus rectangle" in the designer bigger? Also, what is the correct term for the "focus rectangle"?

I have searched the entire internet and could not find an answer, I sincerely hope someone can help me. Thank you.

推荐答案

我相信最好的方法是从UserControl继承.
从TextBox继承时,控件的大小为TextBox,如果将其放大,则表示正在放大TextBox.如果您创建一个从UserControl继承的控件,则它可以包含所需的任何内容,并且可以将焦点矩形设置为所需的大小.当然,您将不得不处理很多鼠标移动,例如您自己!
I believe the best way to do this would be to inherit from UserControl.
When you inherit from TextBox the size of the control is the TextBox and if you enlarge it you are enlarging the TextBox. If you make a control that inherits from UserControl it can contain whatever you want and you can make the focus rectangle as large as you want. Of course you will have to handle a lot of mouse movements and such yourself!


这篇关于Designer中的自定义控件范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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