Hi Larry,
Thanks for your reply. This event worked fine for me, however the newly
created control behaves a bit different than I had expected.
This is the sub as well as the event I use for calling the sub:
Protected Overrides Sub OnParentChanged(ByVal e As System.EventArgs)
MyBase.OnParentChanged(e)
CreateCaption()
End Sub
Private Sub CreateCaption()
If pvtCaption <> "" Then
If pvtLabelObject Is Nothing Then
pvtLabelObject = New EntryCaption
pvtLabelObject.Anchor = AnchorStyles.None
pvtLabelObject.AutoSize = False
pvtLabelObject.BackColor = Color.Transparent
pvtLabelObject.BorderStyle = Windows.Forms.BorderStyle.None
pvtLabelObject.ForeColor = Color.Black
pvtLabelObject.Text = pvtCaption
pvtLabelObject.TextAlign = ContentAlignment.TopRight
pvtLabelObject.BoxObject = Me
pvtLabelObject.Visible = True
'RelocateCaption()
Me.Parent.Controls.Add(pvtLabelObject)
Else
pvtLabelObject.Text = pvtCaption
End If
End If
End Sub
The class EntryCaption is merely a Label with an additional property
'BoxObject'
In order to link the label with the Textbox I store the object reference of
the Textbox in the "BoxObject" property of the label, and vice versa.
After creating the EntryCaption (Label) I set a couple of properties, such
as:
pvtLabelObject.Anchor = AnchorStyles.None
However, the label seems to be anchored anyway.
It get's even weirder when I execute the ''RelocateCaption' sub (as you see
in the code above that call is commented out. When I uncomment it, the whole
label object seems to disappear.
When I ask the visible property in the debugger it tells me 'False' (even
before the relocate is executed).
I'm wondering, about the variable I use to store the object reference in
(pvtLabelObject) is declared as an EntryCaption (subclass of Label). Does
the object reference change after I have added this to the parent's controls
collection? In other words, after the adding, does pvtLabelObject still
contain a proper reference to the newly created object?
Hope you can help me out here, i'm really puzzled
Martin
"Larry Lard" <la*******@hotmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
Martin wrote: I have created a subclass of a textbox. In this subclass I have a
property
called 'Caption'. If this property contains a value then I want to create
a
Label object and add it to the controls collection of the parent of the
Textbox. So, basically both objects exist next to eachother on the same
parent.
Originally I tried the object creation inside the Property-Set, but this
seems that this is too early, because the textbox itself isn't added to
the
controls collection of the parent yet.
So, I'm looking for an event, which comes after the textbox is completely
created and added to the controls collection of its parent. Judging by
the
name I would think 'Finalize' would be a good one, but... The description
of
this event in the help documentation sounds very mysterious, more like
something that happens when the object is being destroyed.
No, not Finalize. That is, as you have guessed, what happens when the
object is being destroyed by the garbage collector.
What would be a good event?
ParentChanged. And you might know this, but for anyone else reading,
the recommended thing to do to change event-response behaviour in a
subclassed control is to override OnParentChanged (remembering to call
MyBase.OnParentChanged), rather than Handles Me.ParentChanged.
--
Larry Lard
Replies to group please