Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Basic Custom Control Question

4 views
Skip to first unread message

C# Learner

unread,
Oct 27, 2004, 1:48:49 PM10/27/04
to
I've derived from System.Windows.Forms.TextBox. I have added a property,
whose value I'd like to set when the component is created at design-time.
How can I do so?

The following doesn't work.

class DerivedTextBox : TextBox
{
public DerivedTextBox() {
if (DesignTime) {
MyProperty = foo;
}
}
...
}

Bob Powell [MVP]

unread,
Oct 27, 2004, 7:51:48 PM10/27/04
to
The DesignMode property isn't valid in the constructor. You can detect it's
state just about anywhere else though.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml


"C# Learner" <csh...@learner.here> wrote in message
news:119a2fmn...@csharp.learner...

C# Learner

unread,
Oct 28, 2004, 2:14:40 AM10/28/04
to
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote:

> The DesignMode property isn't valid in the constructor. You can detect it's
> state just about anywhere else though.

In that case, how can I achieve what I'm trying?

I just want to set a value when the control is created at design-time. I
don't want to reset this value when it's created at run-time because that
would override any value the user has set at design-time.

Claes Bergefall

unread,
Oct 28, 2004, 2:52:18 AM10/28/04
to
Specify a new designer:

[Designer(typeof(DerivedTextBox.DerivedTextBoxDesigner))]
public class DerivedTextBox : System.Windows.Forms.TextBox
{
public DerivedTextBox ()
{
}

public class DerivedTextBoxDesigner :
System.Windows.Forms.Design.ControlDesigner
{
public override void OnSetComponentDefaults()
{
base.OnSetComponentDefaults();
((DerivedTextBox) this.Control).MyProperty = foo;
}
}
}


"C# Learner" <csh...@learner.here> wrote in message
news:119a2fmn...@csharp.learner...

0 new messages