473,624 Members | 2,346 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Designer serialization of non-default values

Imagine I subclass Panel into MyPanel and set a few property values to my
own defaults as shown below. Eg. I set BackColor to by LightYellow.

When I add MyPanel to a form, it will write the non-default property values
into the InitializeCompo nent of the form. So it will explicitily set
myPanel1.BackCo lor = Color.LightYell ow. If I later change the MyPanel
BackColor default from LightYellow to LightRed, it will not reflect this in
my form since the panel on the form is explicitely set to LightYellow.

I hope that makes sense.

Now, I know I can override BackColor and use the [DefaultValue ... ] option
to define new defaults in MyPanel, but if I'm modifying a dozen properties
then do I really need to this for every modified property?

public class MyPanel : Panel
{
public MyPanel()
{
InitializeCompo nent();
}

private void InitializeCompo nent()
{
this.SuspendLay out();
//
// MyPanel
//
this.AutoSize = true;
this.AutoSizeMo de =
System.Windows. Forms.AutoSizeM ode.GrowAndShri nk;
this.BackColor = System.Drawing. Color.LightYell ow;
this.BorderStyl e = System.Windows. Forms.BorderSty le.FixedSingle;
this.ResumeLayo ut(false);
}
}

--Charlie
Nov 30 '06 #1
3 4754
Hi Charlie,
Now, I know I can override BackColor and use the [DefaultValue ... ]
option to define new defaults in MyPanel, but if I'm modifying a dozen
properties then do I really need to this for every modified property?
DefaultValueAtt ribute is the simplest way. Yes, it has to be added to each
property that you want to modify.

In some cases you may have to create a ShouldSerialize[Property] method
instead, but if you're using a default value that can be expressed in a
constant expression then DefaultValueAtt ribute will work.

"Defining Default Values with the ShouldSerialize and Reset Methods"
http://msdn2.microsoft.com/en-us/library/53b8022e.aspx

--
Dave Sexton

"Charlie" <null@nullwro te in message
news:uM******** ******@TK2MSFTN GP03.phx.gbl...
Imagine I subclass Panel into MyPanel and set a few property values to my
own defaults as shown below. Eg. I set BackColor to by LightYellow.

When I add MyPanel to a form, it will write the non-default property
values into the InitializeCompo nent of the form. So it will explicitily
set myPanel1.BackCo lor = Color.LightYell ow. If I later change the MyPanel
BackColor default from LightYellow to LightRed, it will not reflect this
in my form since the panel on the form is explicitely set to LightYellow.

I hope that makes sense.

Now, I know I can override BackColor and use the [DefaultValue ... ]
option to define new defaults in MyPanel, but if I'm modifying a dozen
properties then do I really need to this for every modified property?

public class MyPanel : Panel
{
public MyPanel()
{
InitializeCompo nent();
}

private void InitializeCompo nent()
{
this.SuspendLay out();
//
// MyPanel
//
this.AutoSize = true;
this.AutoSizeMo de =
System.Windows. Forms.AutoSizeM ode.GrowAndShri nk;
this.BackColor = System.Drawing. Color.LightYell ow;
this.BorderStyl e =
System.Windows. Forms.BorderSty le.FixedSingle;
this.ResumeLayo ut(false);
}
}

--Charlie

Nov 30 '06 #2
I was afraid you would say that. Allow me to explain the actual problem I am
having. The control I am trying to subclass is a 3rd party Infragistics
UltraWinGrid control.

In my subclass, I set the this.DisplayLay out.Override.Al lowGroupBy property
to false (just an example), and InitializeCompo nent looks like this:

private void InitializeCompo nent()
{
((System.Compon entModel.ISuppo rtInitialize)(t his)).BeginInit ();
this.SuspendLay out();
//
// MyUltraGrid
//
this.DisplayLay out.Override.Al lowGroupBy =
Infragistics.Wi n.DefaultableBo olean.False;
((System.Compon entModel.ISuppo rtInitialize)(t his)).EndInit() ;
this.ResumeLayo ut(false);
}

Looks fine so far. When I add this control to a form, the AllowGroupBy =
False line also appears in the InitializeCompo nent of the form. This is a
problem because if I later decide to change the default value to True, the
grid on the form will still use the False value!

Furthermore, I cannot override any of these properties
(DefaultValueAt tribute, Reset..., ShouldSerialize ... do not work) since
AllowGroupBy is a property of the Override property which is a property of
DisplayLayout, etc.

At the end of the day, I have about 50 lines of code which is placed into
InitializeCompo nent for every grid within my application. Furthermore, if I
change any of these defaults in the subclass, I am forced to manually clean
up the dozens of places where this code has been unnecessarily written.

Is there a solution to this?

--Charlie
Nov 30 '06 #3
Hi Charlie,
>I was afraid you would say that
How did you know that I was going to answer your question? :p
Allow me to explain the actual problem I am having. The control I am
trying to subclass is a 3rd party Infragistics UltraWinGrid control.

In my subclass, I set the this.DisplayLay out.Override.Al lowGroupBy
property to false (just an example), and InitializeCompo nent looks like
this:

private void InitializeCompo nent()
{
((System.Compon entModel.ISuppo rtInitialize)(t his)).BeginInit ();
this.SuspendLay out();
//
// MyUltraGrid
//
this.DisplayLay out.Override.Al lowGroupBy =
Infragistics.Wi n.DefaultableBo olean.False;
((System.Compon entModel.ISuppo rtInitialize)(t his)).EndInit() ;
this.ResumeLayo ut(false);
}

Looks fine so far. When I add this control to a form, the AllowGroupBy =
False line also appears in the InitializeCompo nent of the form. This is a
problem because if I later decide to change the default value to True, the
grid on the form will still use the False value!

Furthermore, I cannot override any of these properties
(DefaultValueAt tribute, Reset..., ShouldSerialize ... do not work) since
AllowGroupBy is a property of the Override property which is a property of
DisplayLayout, etc.

At the end of the day, I have about 50 lines of code which is placed into
InitializeCompo nent for every grid within my application. Furthermore, if
I change any of these defaults in the subclass, I am forced to manually
clean up the dozens of places where this code has been unnecessarily
written.

Is there a solution to this?
If you can live with the designer not showing your default values and if you
are sure that you won't even attempt to override the default values using
the designer, then you may be able to use the following code in your derived
Control to set default values only at runtime when the control is becoming
visible:

protected override void OnCreateControl ()
{
if (Site == null || !Site.DesignMod e)
{
this.DisplayLay out.Override.Al lowGroupBy =
Infragistics.Wi n.DefaultableBo olean.False;
}

base.OnCreateCo ntrol();
}

Since you're not dealing with a FCL control I can't test this myself, but I
assume it will work. Let us know :)

Another solution might be creating a custom designer, but you'll have to
derive from Infragistics designer if you want to retain the expected
design-time behavior, which might not be possible and probably wouldn't be
an easy task anyway. If it comes down to that it's probably not worth your
time, but searching or posting in Infragistics forums might help you to find
a better solution.

--
Dave Sexton
Nov 30 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
6563
by: Daniel Billingsley | last post by:
I've got a project I've been working on for a few weeks. I've been using the BindingSource control - I've got four of them on this particular form. This morning I went to view the report in the designer and got: Could not find type 'LandarcBL.Budget'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built....
1
1990
by: Lucien Dol | last post by:
Hi all, Can someone help me with this, please? I've got a user control that (amongst other controls) contains a textbox. The textbox has its Anchor property set to "Left, Top, Right", meaning that it will stretch automatically when the control is resized on a form or other user control. When in design mode I look at the control by itself (rather than dropped on a form) the control has a certain size (let's call this SizeA).
2
10765
by: Richard Bysouth | last post by:
Hi When attempting to view inherited forms in design mode I have been getting the message "The path is not of a legal form" and am unable to view the designer. I can't seem to find any further information on this error - does anyone know what the problem and resolution might be? thanks
0
1374
by: Adam Right | last post by:
Hi, I am using contextmenustrip in my usercontrol in which there is a grid control associated with it. I added the rows below in the designer code, to create contextmenustrip with its constructor which takes the "IContainer" parameter. "this.m_Components" is defined in my base usercontrol as a protected member. My code is below in my designer:
0
1256
by: Bruce HS | last post by:
In VS2005, VB 2005, I suddenly can't get at a winform design view. The application still runs OK, but I can't see the designer. I'ver rebuilt the solution with no success. I'm looking for a general strategy for dealing with this problem. Here is the error text: Object reference not set to an instance of an object.
1
4678
by: dusanv | last post by:
Hi, I have a class (say O1) that overrides System::Windows::Forms::UserControl and then another one that overrides O1 (call it O2). O2 used to work with the Designer as it was inheriting directly from UserControl (and was created using the wizard) but since I inserted O1 into inheritance tree (without resx, straight override) I get the error pasted at the bottom when trying to open O2 in Designer. I deleted the NCB file to no avail....
5
2928
by: Alan T | last post by:
I got this kind of error recently: When I tried to open a form I got error something like this: One of more errors encountered while loading the designer. The errors are listed below. Some errors can be fixed by rebuilding your project, while others may require code changes. Look at the lines all are referencing the system things such as at System.Reflection.Module.GetTypesInternal(StackCrawlMark& stackMark)
4
5812
by: ThunderMusic | last post by:
Hi, I have a custom form that works fine when I debug it or run it in release mode but cannot be loaded in the designer... Actually, it can be loaded in the designer when no control is on it, but the resizing tool (in the designer) is offset both horizontally and vertically and when I put a control on it, as soon as I save, the designer throws an exception (but cannot be reproduced everytime) and the form cannot be loaded anymore unless...
1
3293
by: =?Utf-8?B?RjVGNUY1?= | last post by:
I have created a control by inheriting ToolStripMenuItem that has an image property called LargeImage. ------ public class EventSubMenuItem : ToolStripMenuItem { private Image _largeImage = null;
3
2249
by: steve | last post by:
VS designer has started to complain about the following errors : Object reference not set to an instance of an object. Instances of this error (2) and Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index Instances of this error (12)
0
8233
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
8675
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...
1
8334
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
8474
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...
0
4078
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
4173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2604
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
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.