Assuming the reason that the Label must be added to the form when the custom
TextBox is added is due to a relationship between the two controls, then you
may want to build a UserControl that contains both the TextBox and the Label
and define the relationship that way.

Signature
Tim Wilson
.NET Compact Framework MVP
> I try to create Inherit TextBox ,that when i put it on the form,
> it put also Label into the form. but how i can add the label to form
> within
> TextBox New method(constructor)?
>
> have a way to do that, for designed time or at least for runtime?
mtczx232@yahoo.com - 30 Jan 2006 22:39 GMT
>>build a UserControl that contains both the TextBox and the Label
i dont like this solution for some reasons. you are sure that not
posible
to put the label directly on the form? not at run time nor at design
time?
heare same code that i try, but is not work at all:
==============================
Imports System.Windows.Forms
Public Class Atext
Inherits TextBox
Public l As Label
<System.Diagnostics.DebuggerNonUserCode()> _
Public Sub New(ByVal Container As System.ComponentModel.IContainer)
MyClass.New()
'Required for Windows.Forms Class Composition Designer support
Container.Add(Me)
Container.Add(l)
End Sub
<System.Diagnostics.DebuggerNonUserCode()> _
Public Sub New()
MyBase.New()
l = New Label
l.Width = 600
l.Height = 50
l.Text = "llllllll"
l.Visible = True
l.Location = New Point(0, 0)
'This call is required by the Component Designer.
InitializeComponent()
End Sub
'Component overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Component Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Component
Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
components = New System.ComponentModel.Container()
End Sub
End Class
Tim Wilson - 30 Jan 2006 22:57 GMT
You can easily place a Label on the parent at runtime by overriding the
OnParentChanged method of the TextBox and adding a new Label to the parent
using the Parent property of the TextBox.

Signature
Tim Wilson
.NET Compact Framework MVP
> >>build a UserControl that contains both the TextBox and the Label
> i dont like this solution for some reasons. you are sure that not
[quoted text clipped - 57 lines]
> End Sub
> End Class