I have a form that inherits from another from. In the designer, whenever I adjust something like control size or location, VS auto-generates a resx file for that form. The resx just contains some KeyValuePairs for comboboxes, w/c are unnecessary really since these values are already defined in the parent class.
Aside from this, the designer.cs also gets update w/ inherited properties such as Text, NumericUpDown.Value, DisplayMember, ValueMember, etc, w/c again are already defined in the parent class.
I know the designer.cs is supposed to be update w/ the new location and size, but I don't want it to update other stuff that's inherited from parent class.
Is there a way to prevent this, and just let the designer update the location and size?
UPDATE:
I found that the ComboBox.Items.AddRange() gets added to the Designer.cs and .resx file due to binding logic that I have in OnLoad(). This is primarily preventing the designer to load properly when the form is reloaded on the Designer.
I modified OnLoad to run the binding logic only when DesignMode is false.
The form no longer throws errors when reloading the designer, but some of the control properties are still unnecessarily added back to the Designer.cs whenever I change any property via the property dialog.
UPDATE2:
Totally prevented the designer from generating unnecessary control properties by applying suggestion here.
Now all that's generated are control location and size.
Related
I'm trying to get a resize event working, and I tried just adding "this.Reszie += whatever" and that worked fine, but whenever I make other changes to the Form through the editor, it completely erases that line (as well as anything else in the Form1.Designer.cs class). My questions is, how can I edit this as intentioned, like how double clicking on a button or text box will automatically do this all? Thanks
You can select event handlers in the properties window. You must click on the flash symbol, to switch form properties to events view.
Also, before you do manual changes to ".designer.cs", close the form designer (because saving the form overwrites the ".designer.cs" file).
Usually, you should avoid doing changes in the ".designer.cs" file, but there are rare occasions where this is helpful. E.g., you have used a TextBox and want to replace it by a custom textbox or third-party textbox. Then changing the type manually will allow you to do it without removing and re-adding these controls.
When I add a control to a form through the designer, not all properties of the control appear in the designer code. For example, when I add a ListBox the UseWaitCursor property does not appear in the designer code unless it is set to True. When I change it to False it disappears from the designer code, which makes me think that the properties somehow have defaults and don't appear in the designer code if left at default.
Can someone please help me understand how the designer works and where all this is tracked. The reason I ask is I am currently writing a class that extends a third party ActiveX control which I plan to initialize dynamically at run time. I was going through the designer code (when the third party control is added through the designer) and a lot of its properties do not appear there.
This is done with the [DefaultValue] attribute. The Control.UseWaitCursor property looks similar to this:
[DefaultValue(false)]
public bool UseWaitCursor
{
// etc..
}
So if you leave the value at False in the Properties window then the designer knows that it should not display the value in Bold and that it is not necessary to put the property assignment in the InitializeComponent() method since the default is already good. An ActiveX control will certainly have a lot of properties set at its default value as well.
I have a custom control, MyControl, that inherits from UserControl.
If i change MyControl graphic proprerties(like ForeColor, backgroundImage, etc) i aspect this will be applied to all my instances of MyControl, but is not.
Why?
EDIT
I think the problem is that image are stored inside resx file of Control that contains MyControl (example a Form).
When this line is called, the old image is applied.
resources.ApplyResources(this.myControl1, "myControl1");
So when i make changes in MyControl designer class, this are not applied to myControl1 instance.
Unfortunately this line was autogenerated in designer of Form.
Thanks
You should make your settings (eg. change background image and stuff) in a constructor of MyControl or in the designer of the control, not Form.
Well of course it doesn't.
When you add the control to a form, it grabs the properties and adds code in form.designer.cs, setting them. Change them in the form designer, those chamges get persisted in .designer.cs
If you then change the control itself, to pick up those changes you'd have to remove and add it again.
The only way round that is for the properties not to be configurable in the designer.
This must be a FAQ, but I can’t find a duplicate question!
There are lot of different attributes that control what the WinForm Designer does with properties on a custom control, I am never clear on the one I should use in this case.
I am looking for:
Designer does not show property in grid
Designer does not read value of property
Designer does not set property to default value
E.g. Designer behaves as if the property was not there.
Designer does not complain if it has already done one of the above before the attributes were added (hard!)
Background.
The code that is giving me the problem is:
this.eventListControl.FilterSets =
((SystList<FilterSet>)(resources.GetObject("eventListControl.FilterSets")));
The FilterSets property should never have been touched by the winforms designer; it is now not Serializable and MsDev falls over every time a form that used the eventListControl is changed!
I think you can use [Browsable (false)] and [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
The second attribute prevents the property from appearing in InitializeComponent
I am having some issues with the form designer in VS2010.
Everytime I open this project VS modifies certain form values, specifically related to splitter distances. If I undo changes via Pending Changes tab it reloads then instantly makes the modification again!
What has gone wrong?
The SplitterDistance property setter overrides the value you give it, based on the panels' MinSize property. This will happen at design time as well as runtime. Adjust the Panel1 and Panel2 MinSize property as necessary.
Something else you want to keep an eye on is the AutoScaleDimensions assignment in the form's InitializeComponents() method as written in the form's Designer.cs file. Compare it to the value you see when you create a new project from scratch. If there's a mismatch then the form was originally designed on a machine with a different video adapter DPI setting. The form's AutoScaleMode tries to correct for that, at design time as well as runtime. Which can have lots of side effects, including the SplitterDistance property setter behavior.