How to prevent UserControl property Auto code generate

G

Guest

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?
 
G

Guest

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

Any idea?
 
D

D. Yates

What information is automatically being generated for the property you
specified?

I ask because Marc's suggestion should have worked.


Dave
 
J

jmcgrew

Try this:

using System.ComponentModel;

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

Jesse
 
G

Guest

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(DesignerSerializationVisibility.Hidden),
Browsable(false)]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top