473,785 Members | 2,506 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Componen tModel.Browsabl e(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 2640
You could try adding a System.Componen tModel.DefaultV alueAttribute - 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*****@newsgr oups.nospam> wrote in message
news:E9******** *************** ***********@mic rosoft.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.Componen tModel.Browsabl e(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*****@newsgr oups.nospam> wrote in message
news:30******** *************** ***********@mic rosoft.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.Componen tModel;

[DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.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(nu ll)]
public Point ImageOrigin
{
get { return m_imgOrigin; }
set { m_imgOrigin = value; }
}

And the Windows Form Designer generates the following code automatically:
this.m_map.Imag eOrigin = 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:
[DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.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
9383
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; } } but it doesn't show up in the designer. By the way, this used to work in the 2002 version, now in 2003 I am getting all kinds of problems like this
1
4930
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 when my control is in design or Runtime mode, it´s work, but when this usercontrol is put in another usercontrol the DesignMode property always return false. How can I do to stop the methods to execute in designMode when my usercontrol is in...
3
1695
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 I can prevent the control from being designed by making it not the first class in the code file, but is there another more 'official' way to do this via attributes.
7
8826
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
9647
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10161
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9958
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7506
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5523
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4058
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.