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

C# User Controls - setting default properties

P: n/a
I have built a working user control. However, to make it work, I always have
to set certian properties using the properties sheet for the control when
using it on other forms. I want to be able to set default values for most
properties so the control will work as-is without requiring the developer to
set them.

I notice in the compment initialization code create when I drop the control
on a form that all the properties are set to null or other appropriate
'empty' values. How can I modify the control so these initial values are
correct?

Thanks!
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
private bool myBoolProperty = false;

public bool MyBoolProperty
{
get { return myBoolProperty; }
set { myBoolProperty = value; }
}

HTH

DalePres
MCAD, MCDBA, MCSE
"countd4" <co*****@discussions.microsoft.com> wrote in message
news:B7**********************************@microsof t.com...
I have built a working user control. However, to make it work, I always
have
to set certian properties using the properties sheet for the control when
using it on other forms. I want to be able to set default values for most
properties so the control will work as-is without requiring the developer
to
set them.

I notice in the compment initialization code create when I drop the
control
on a form that all the properties are set to null or other appropriate
'empty' values. How can I modify the control so these initial values are
correct?

Thanks!

Nov 16 '05 #2

P: n/a

That is how the properties are implemented. The problem is not that I can't
see them on the new project. The problem is that they are being assigned null
values by the IDE. So I am guessing that I'm not doing something correctly in
the control itself to propagate the "default" values. Here are some code
snipets from the control.

public class ProgressControl1 : System.Windows.Forms.UserControl
{
private string _spinLocation = "L" ; // 'L'eft or 'R'ight
private string _pcntLocation = "R" ; // 'L'eft or 'R'ight
..
..
}
..
..
public ProgressControl1()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();

// TODO: Add any initialization after the InitComponent call

}

..
..
..
public string PBSpinLocation
{
get {return _spinLocation;}
set {_spinLocation = value;}
}
public string PBPcntLocation
{
get {return _pcntLocation;}
set {_pcntLocation = value;}
}
..
..

Now here is what the IDE does when I drop this control on a new project form:

private void InitializeComponent()
{
..
..
//
// progressControl11
//
this.progressControl11.AccessibleRole =
System.Windows.Forms.AccessibleRole.None;
this.progressControl11.BackColor = System.Drawing.Color.Plum;
this.progressControl11.Location = new System.Drawing.Point(24, 8);
this.progressControl11.Name = "progressControl11";
this.progressControl11.PBarFillColor = System.Drawing.Color.Empty;
this.progressControl11.PBAutoMax = false;
this.progressControl11.PBPcntBackColor = System.Drawing.Color.Empty;
this.progressControl11.PBPcntDisplay = true;
this.progressControl11.PBPcntFont = null;
this.progressControl11.PBPcntFontColor = System.Drawing.Color.Empty;
this.progressControl11.PBPcntLocation = null;
this.progressControl11.PBSpinBackColor = System.Drawing.Color.Empty;
this.progressControl11.PBSpinDisplay = true;
this.progressControl11.PBSpinFont = null;
this.progressControl11.PBSpinFontColor = System.Drawing.Color.Empty;
this.progressControl11.PBSpinLocation = null;
this.progressControl11.Size = new System.Drawing.Size(280, 96);
this.progressControl11.TabIndex = 0;
//
..
..
..

So you see how it forces most of the public properties of the control to
null or empty states? This is my problem!!!

HTH!

Count


"DalePres" wrote:
private bool myBoolProperty = false;

public bool MyBoolProperty
{
get { return myBoolProperty; }
set { myBoolProperty = value; }
}

HTH

DalePres
MCAD, MCDBA, MCSE
"countd4" <co*****@discussions.microsoft.com> wrote in message
news:B7**********************************@microsof t.com...
I have built a working user control. However, to make it work, I always
have
to set certian properties using the properties sheet for the control when
using it on other forms. I want to be able to set default values for most
properties so the control will work as-is without requiring the developer
to
set them.

I notice in the compment initialization code create when I drop the
control
on a form that all the properties are set to null or other appropriate
'empty' values. How can I modify the control so these initial values are
correct?

Thanks!


Nov 16 '05 #3

P: n/a
What you're looking for is a custom ControDesigner for your control which
can, among a lot of other things, create the default properties when your
control is dropped onto a form.

Look up the System.Windows.Forms.Design.ControlDesigner class and override
the OnSetComponentDefaults() method.

HTH

DalePres
MCAD, MCDBA, MCSE
"countd4" <co*****@discussions.microsoft.com> wrote in message
news:85**********************************@microsof t.com...

That is how the properties are implemented. The problem is not that I
can't
see them on the new project. The problem is that they are being assigned
null
values by the IDE. So I am guessing that I'm not doing something correctly
in
the control itself to propagate the "default" values. Here are some code
snipets from the control.

public class ProgressControl1 : System.Windows.Forms.UserControl
{
private string _spinLocation = "L" ; // 'L'eft or
'R'ight
private string _pcntLocation = "R" ; // 'L'eft or
'R'ight
.
.
}
.
.
public ProgressControl1()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();

// TODO: Add any initialization after the InitComponent call

}

.
.
.
public string PBSpinLocation
{
get {return _spinLocation;}
set {_spinLocation = value;}
}
public string PBPcntLocation
{
get {return _pcntLocation;}
set {_pcntLocation = value;}
}
.
.

Now here is what the IDE does when I drop this control on a new project
form:

private void InitializeComponent()
{
.
.
//
// progressControl11
//
this.progressControl11.AccessibleRole =
System.Windows.Forms.AccessibleRole.None;
this.progressControl11.BackColor = System.Drawing.Color.Plum;
this.progressControl11.Location = new System.Drawing.Point(24, 8);
this.progressControl11.Name = "progressControl11";
this.progressControl11.PBarFillColor = System.Drawing.Color.Empty;
this.progressControl11.PBAutoMax = false;
this.progressControl11.PBPcntBackColor = System.Drawing.Color.Empty;
this.progressControl11.PBPcntDisplay = true;
this.progressControl11.PBPcntFont = null;
this.progressControl11.PBPcntFontColor = System.Drawing.Color.Empty;
this.progressControl11.PBPcntLocation = null;
this.progressControl11.PBSpinBackColor = System.Drawing.Color.Empty;
this.progressControl11.PBSpinDisplay = true;
this.progressControl11.PBSpinFont = null;
this.progressControl11.PBSpinFontColor = System.Drawing.Color.Empty;
this.progressControl11.PBSpinLocation = null;
this.progressControl11.Size = new System.Drawing.Size(280, 96);
this.progressControl11.TabIndex = 0;
//
.
.
.

So you see how it forces most of the public properties of the control to
null or empty states? This is my problem!!!

HTH!

Count


"DalePres" wrote:
private bool myBoolProperty = false;

public bool MyBoolProperty
{
get { return myBoolProperty; }
set { myBoolProperty = value; }
}

HTH

DalePres
MCAD, MCDBA, MCSE
"countd4" <co*****@discussions.microsoft.com> wrote in message
news:B7**********************************@microsof t.com...
>I have built a working user control. However, to make it work, I always
>have
> to set certian properties using the properties sheet for the control
> when
> using it on other forms. I want to be able to set default values for
> most
> properties so the control will work as-is without requiring the
> developer
> to
> set them.
>
> I notice in the compment initialization code create when I drop the
> control
> on a form that all the properties are set to null or other appropriate
> 'empty' values. How can I modify the control so these initial values
> are
> correct?
>
> Thanks!


Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.