Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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.

VB
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


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.
Posted
Updated 30-Apr-12 8:15am
v2

1 solution

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!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900