471,627 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,627 software developers and data experts.

How to prevent UserControl property Auto code generate

I'm writing my own control that derived from the UserControl.
In my control I have some public properties (with get and set) that I do not
want them to be shown on the designer properties window and I also do not
want the Windows Form Designer to generate code automatically on the user
Form for them.

To block the properties from being shown on the designer properties window I
use:
[System.ComponentModel.Browsable(false)]
public int MyProp
{
get { return m_int; }
get { m_int = value; }
}

But I could not find how to prevent the Windows Form Designer from
generating code automatically on the user Form.

Can anybody help me with that?
--------
Thanks
Sharon
Nov 30 '05 #1
7 2535
You could try adding a System.ComponentModel.DefaultValueAttribute - i.e.
[DefaultValue(0)]; according to
http://msdn.microsoft.com/library/de...lasstopic.asp:

"A visual designer can use the default value to reset the member's value.
Code generators can use the default values also to determine whether code
should be generated for the member."

Marc

"Sharon" <Sh*****@newsgroups.nospam> wrote in message
news:E9**********************************@microsof t.com...
I'm writing my own control that derived from the UserControl.
In my control I have some public properties (with get and set) that I do
not
want them to be shown on the designer properties window and I also do not
want the Windows Form Designer to generate code automatically on the user
Form for them.

To block the properties from being shown on the designer properties window
I
use:
[System.ComponentModel.Browsable(false)]
public int MyProp
{
get { return m_int; }
get { m_int = value; }
}

But I could not find how to prevent the Windows Form Designer from
generating code automatically on the user Form.

Can anybody help me with that?
--------
Thanks
Sharon

Nov 30 '05 #2
No, it's does not work, at least not for properties that are of class/struct
types.

Any idea?

--
Thanks
Sharon
Nov 30 '05 #3
(throws open the floor to other takers...)

"Sharon" <Sh*****@newsgroups.nospam> wrote in message
news:30**********************************@microsof t.com...
No, it's does not work, at least not for properties that are of
class/struct
types.

Any idea?

--
Thanks
Sharon

Nov 30 '05 #4
What information is automatically being generated for the property you
specified?

I ask because Marc's suggestion should have worked.
Dave
Nov 30 '05 #5
Try this:

using System.ComponentModel;

[DesignerSerializationVisibility(DesignerSerializat ionVisibility.Hidden),
Browsable(false)]
public int MyProp
{
get { return m_int; }
get { m_int = value; }
}

Jesse

Nov 30 '05 #6
Ok, I have a field:
private Point m_imgOrigin = Point.Empty

And a property for it:
[Browsable(false), DefaultValue(null)]
public Point ImageOrigin
{
get { return m_imgOrigin; }
set { m_imgOrigin = value; }
}

And the Windows Form Designer generates the following code automatically:
this.m_map.ImageOrigin = new System.Drawing.Point(0, 0);

But I do not want the Form designer to generate any code for it.

But Jesse suggestion is working:
[DesignerSerializationVisibility(DesignerSerializat ionVisibility.Hidden),
Browsable(false)]
------
Thanks
Sharon
Dec 1 '05 #7
Thank Jesse, thais is the one.

It works!

------
Thanks
Sharon
Dec 1 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.