By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,053 Members | 1,595 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,053 IT Pros & Developers. It's quick & easy.

Composite Control font problem!

P: n/a
pnp
I have created a coposite user control of a text box and a label. I have
exposed the font of the textbox property through a property of the
control but every time I try to change that through the property grid of
the designer when I use the composite control in a form, after a rebuild
the changes seem to get lost! I don't see the Font property anywhere in
the inner code... What am I doing wrong?
Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Can you post the code for the custom property that exposes the inner TextBox
Font property?

--
Tim Wilson
..Net Compact Framework MVP

"pnp" <pnp.@.softlab.ntua.gr> wrote in message
news:uA**************@TK2MSFTNGP09.phx.gbl...
I have created a coposite user control of a text box and a label. I have
exposed the font of the textbox property through a property of the
control but every time I try to change that through the property grid of
the designer when I use the composite control in a form, after a rebuild
the changes seem to get lost! I don't see the Font property anywhere in
the inner code... What am I doing wrong?

Nov 17 '05 #2

P: n/a
pnp
Tim Wilson wrote:
Can you post the code for the custom property that exposes the inner TextBox
Font property?

[Category("InputBox"), Browsable(true),
RefreshProperties(RefreshProperties.None)]
public override Font Font
{
get
{
return this.textbox.Font ;
}
set
{
this.textbox.Font = value;
}
}
Nov 17 '05 #3

P: n/a
You should be blowing the stack in your get accessor. When the child TextBox
Font property is queried it will attempt to return the Parent Font property
value - this is due to the Font property being an ambient property. So when
you get the TextBox Font property from within the Parent Font property, the
child attempts to get the parents value, but the parent is getting the
childs value -- stack overflow. Another way to do this is to set the Label
Font in the constructor.

public UserControl1()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
this.label1.Font = this.Font;
}

Now, since the Label Font has been explicitly set, the Label will not pick
up the Font of the parent and so the Font property will affect the TextBox
only.

If you want to override the attributes for the Font property, just make sure
that you're using the base Font to get and set.

[Category("InputBox")]
public override Font Font
{
get
{
return base.Font;
}
set
{
base.Font = value;
}
}

--
Tim Wilson
..Net Compact Framework MVP

"pnp" <pnp.@.softlab.ntua.gr> wrote in message
news:OR**************@TK2MSFTNGP09.phx.gbl...
Tim Wilson wrote:
Can you post the code for the custom property that exposes the inner TextBox Font property?

[Category("InputBox"), Browsable(true),
RefreshProperties(RefreshProperties.None)]
public override Font Font
{
get
{
return this.textbox.Font ;
}
set
{
this.textbox.Font = value;
}
}

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.