473,372 Members | 845 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,372 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 2615
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
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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...

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.