473,413 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 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 2619
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: james | last post by:
I cannot get my UserControl's browsable properties to show up in the designer properties panel. I have then public virtual bool TestProp { {get return testProp; } set { testProp = value; } } ...
1
by: Tiago Barbutti | last post by:
I have a UserControl that execute methods in Load event, but it hapens in designMode and generate an error and the control disappear from the form. I read that i can use the DesignMode to kwnow...
3
by: Tony Maresca | last post by:
Hi. I have a class derived from a UserControl, that I want to allow others to derive controls from. I don't want them to design the base class (which is derived from a UserControl). I know that...
7
by: Fabio Cannizzo | last post by:
How can I prevent a few lines of code contained in the constructor of a Form from being executed by the Designer? Thanks, Fabio
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.