473,803 Members | 3,758 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Designer Flaw?

I'm trying to create a ComboBox class that will present the same printout
options to users no matter where I need to use the combo box.
I extend the ComboBox class and in the constructor I add predefined print
destinations, along with setting other properties.
The problem comes when I drop the class onto the form in the designer. The
code thats gets generated automatically "scrapes" the constructor
and creates an AddRange() call for the values I use during instantiation.
This behavior is annoying. When I run the program two sets of options
appear in the drop down. On top of the AddRange() call being injected, the
values for the AddRange() call are converted from variable references to
literal values. If I use the combo box throughout my
application and then decide to change the values of the variables, I'll have
to search and replace the literal values, instead of changing the
values in the class.
Here is a sample. I used sharpDevelop, but the problem(?) occurs in
devStudio, also.
using System;
using System.Drawing;
using System.Windows. Forms;
namespace WinFormsTest {
public class MainForm : System.Windows. Forms.Form {
public MainForm() {
InitializeCompo nent();
}
[STAThread]
public static void Main(string[] args) {
Application.Run (new MainForm());
}
private void InitializeCompo nent() {
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(292, 271);
this.Name = "MainForm";
}
}
public class PrintComboBox : System.Windows. Forms.ComboBox {
public PrintComboBox() {
Items.Add( DEST_SCREEN );
Items.Add( DEST_FILE );
Items.Add( DEST_EMAIL );
DropDownStyle = ComboBoxStyle.D ropDownList;
SelectedIndex = 0;
}
private const String DEST_SCREEN = "View";
private const String DEST_FILE = "File";
private const String DEST_EMAIL = "eMail";
}

}
When you switch to design mode, the PrintComboBox will appear in the Custom
Components section of the toolbox. Add the combo box to the form, then
check the source code and you'll see this statement will have been added to
MainForm.Initia lizeComponent() .

this.printCombo Box1.Items.AddR ange(new object[] {
"View",
"File",
"eMail"});
There must be some explanation, since both devStudio and sharpDevelop
produce the same results.
Is this typical behaviour?

Am I implementing this correctly?
Thanks,
Mark


Nov 17 '05 #1
1 1183
I'm not 100% sure that this will work, but in your PrintComboBox class,
have you tried adding this:

private bool ShouldSerialize Items()
{
if (base.Items.Cou nt != 3)
{
return true;
}
if (!base.Items[0].GetType().Equa ls(typeof(strin g)) ||
(string)base.It ems[0] != DEST_SCREEN)
{
return true;
}
if (!base.Items[1].GetType().Equa ls(typeof(strin g)) ||
(string)base.It ems[1] != DEST_FILE)
{
return true;
}
if (!base.Items[2].GetType().Equa ls(typeof(strin g)) ||
(string)base.It ems[2] != DEST_EMAIL)
{
return true;
}
return false;
}

You have to tell the Designer that your combo box contains the default
items and that so long as it has those items the Designer shouldn't
serialize the Items list. Now, I have some doubts about whether this
will work, because you can't override Items in your derived class, so
the Items property is in the base ComboBox class while the derived
ShouldSerialize Items property is in your derived class. Nonetheless,
it's worth a shot.

You might also want to post this question in the newsgroup
microsoft.publi c.dotnet.window sforms.designti me group, as this is a
design time problem with your class. Someone there will surely know how
to fix you up.

Nov 17 '05 #2

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

Similar topics

19
2808
by: Christian Engström | last post by:
If you have a function that returns something by value, the gcc compiler (version 3.2.3 on Windows XP with MinGW) converts the returned value from the type you specify in the code, to the const version of that type. Is this a bug that is specific to gcc, or is it a flaw in the language specification that gcc diligently implements? For example, the below program produces the output Constant Mutable
10
2252
by: ma740988 | last post by:
I'm hoping my post here doesn't fall into the 'hard to say' category, nonetheless I've been advised that multiple uses of accessor/mutator (get/set) member functions can be viewed as a 'design flaw'. In that regard I'm trying to create an 'example' class that's an alternative to the accessor/mutator approach. To further describe the problem consider the class BAR (below) which has a member data in_use that FOO needs visibility into. ...
5
2341
by: christophe (dot) poucet (at) gmail (dot) com | last post by:
Hello, I noticed there is a flaw in the vector implementation of g++ (3.4). Basically when you erase an element from a vector, it calls the wrong destructor. In most cases this is not such a big issue, but if one were to store a class holding a resource, then the wrong resource would be freed. Here is a test case to show what I mean: (Disregard the destructors called for the temporaries).
23
1739
by: Java script Dude | last post by:
Give this a test in IE (verified in IE 6.0 sp2) Has anybody else seen this and is there a workaround besides escaping with html special chars and not using IE ;] ~ file 1 ~ <html> <head> <title>IE +n- Flaw Tester</title> </head>
8
1931
by: Matt Kruse | last post by:
http://news.zdnet.com/2100-1009_22-6121608.html Hackers claim zero-day flaw in Firefox 09 / 30 / 06 | By Joris Evers SAN DIEGO--The open-source Firefox Web browser is critically flawed in the way it handles JavaScript, two hackers said Saturday afternoon. An attacker could commandeer a computer running the browser simply by crafting a Web page that contains some malicious JavaScript code, Mischa Spiegelmock and Andrew Wbeelsoi...
2
4692
by: dejavue82 | last post by:
Does anybody know how to resolve the following errors? They were caused by the designer.cs file that was auto-generated by the LINQ to SQL designer. I am using the March 2007 Orcas CTP version of Visual Studio. Error 1 The type or namespace name 'Linq' does not exist in the namespace 'System.Data' (are you missing an assembly reference?) C: \Documents and Settings\HP_Administrator\My Documents\Visual Studio
3
1839
by: Windows | last post by:
Microsoft Windows | MSN Flaw I have found a flaw in MSN. For those that use MSN or Live.com with Windows see: http://search.msn.com/results.aspx?q=windows&FORM=www.YOFAST.org-utilizing-Google-has-much-better-results-than-MSN Imagine what can be done when from the outside someone manipulates MSN, Microsoft, XP and Windows just by modifiing the URL. By the way, the Microsoft Mission statement
4
2652
by: Goran Djuranovic | last post by:
Hi all, I am experiencing a strange thing happening with a "designer.vb" page. Controls I manually declare in this page are automatically deleted after I drop another control on a ".aspx" page. - Why is this happening? - Can I disable automatic declaration and have everything be declared manually? - Any other options to fix this? Thanks in advance. Goran Djuranovic
1
2075
by: Guy Macon | last post by:
Serious Security Flaw in Google Chrome: http://www.readwriteweb.com/archives/security_flaw_in_google_chrome.php -- Guy Macon <http://www.GuyMacon.com/>
0
9564
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10310
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
10292
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
9121
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7603
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
6841
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5498
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...
2
3796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2970
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.