I have a C# app where one of my Form icons is visible in the designer but reverts to the default icon at runtime. The form in question is a derived form, with no .designer.cs file of its own, and the derived form .cs file is empty. The form icon displays in the designer correctly, but at runtime the icon is missing.
The derived form is in a different project from the base form. The base form icon was added via the designer, and no modifications were made to the base .designer.cs file.
Any ideas what might be causing this?
After mucking about for a bit, I think my problem is related to this bug in VS: https://connect.microsoft.com/VisualStudio/feedback/details/106264/mdi-form-icon-formborderstyle-windowstate-maximized#tabs
I got around my issue by re-adding the Icon to the derived form (using the designer), and then also had to add a _Load handler with the following
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MyForm));
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
Does the job, though I don't enjoy hacky workarounds!
Related
I have an old C# winforms project I have support for several years now. In this project there is a main form that is an mdiparent and each other form is a child that fits inside the blank area of the parent. This has never been a problem.
Now I am trying to make modifications to this app again, but I do have a newer version of Visual Studio (2015) than I used to. So there is only ONE child form in this app that is giving me trouble. If I revert all my code, open the project, build, that form will appear/scale correctly. If I revert all my code, open the project, open the UI of the form, build, it will shrink the child to a smaller area inside the parent. It only happens on this ONE form, the rest work fine.
I have tried messing with all forms of autosizing, scaling, window size settings, etc but I think its something in VS that is causing just that one form to auto scale incorrectly and I'm not sure what it is. If I look at the auto generated code and compare it to the other forms it will set AutoScaleBaseSize to (6,15) but other forms are at (5,13). If I do like I mentioned above and revert the code but do NOT open the form, the autogenerated code for that form is (5,13) like the other forms.
What is happening in Visual Studio to change this AutoScaleBaseSize property and how can I find the culprit?
I had a Form "ParentForm" Designed in C# VS2010 with two buttons.
I wanted five forms to have the same two buttons, so i decided to write five *.cs files(subForm1.cs,subForm2.cs...subForm5.cs) derived from the "ParentForm" as base class.
Now VS2010 shows these derived classes with a form icon(ie recognizes as Forms), but does not generate a .designer.cs file for it. So the problem I am facing is that, whenever I drag a
Control into derived class form say subForm1.cs , VS2010 puts the auto-generated code into my subForm1.cs instead of subForm1.Designer.cs. Although I tried manually creating a file named subForm1.Designer.cs (which also gets detected and is put under the hierarchy of the Form icon in solution explorer) but, still the auto-generated code goes to the subForm1.cs file. How do
I tell VS2010 to patch subForm1.cs+subForm1.Designer.cs+subForm1.resx as one form subForm1.
If you want to have the designer file, Add new Windows Forms.
Then replace the inheritance from Form class to your ParentForm class.
This way any new controls you add to your child form should get added in the designer file.
Also please go through this link on Visual Inheritance
I'm using Visual Studio 2010 and when I create a form, I get a FormName.Designer.cs file with all the auto generated code.
This is exactly what I want, however, when I do the following:
Created an empty class.
Subclass System.Windows.Forms.Control
Add a System.Windows.Forms.ImageList to the designer.
Add images to the ImageList in the designer.
All of the auto generated code gets dropped in my class file and I don't get a *.Designer.cs file.
How do I get VS to always use a *.Designer.cs file?
Update
Declaring a class partial and subclassing UserControl is not sufficient. I had to select "UserControl" when I created a new Item, then I got a designer.cs file.
This is normal and the way the designer worked in versions of Visual Studio before VS2005, versions that did not yet support partial classes. You only get the separate Designer.cs file for a class that's derived from Form or UserControl and you declared them with the partial keyword.
Not 100% sure what's the underlying reason, but surely it has something to do with the very simple designer for the Control class. The designers for Form and UserControl are much fancier.
Nothing actually goes wrong so this is not a real problem. There is very little bang for the buck, especially since it is so uncommon to actually need another component or control when you create a custom control. Getting the Properties window to work is a convenience but, in my personal experience, isn't worth the considerable annoyance of getting the designer page by default when you double-click the class in the Solution Explorer window. I lost count of the number of times I shouted "crud!" at the machine.
I've converted a Windows Form into a Windows Control (by changing the code's parent from Form to Control, removing a few minor/irrelevant Form property assignments, and changing the project settings to "Class Library" instead of Windows Form Application). The Control works great in my application, but when I open it up in Visual Studio Designer there is nothing there except the labels for the items it isn't showing me (panel1, button1, etc.).
How do I get designer working again? It gives no errors.
You'll get the wrong designer when you do this. The default designer for the Control class is not a DocumentDesigner, the kind of designer that supports editing nested controls. The simplest fix is to change the base class of your class from Control to UserControl.
I have a base form BaseForm which I use for saving settings. This form have no controls in it and it's opened in the designer as an empty form. However, when I inherit this form, the designer refuses to open the newly created form in the designer (there's no button View in Designer). What may be the problem ? Thanks
The problem is with the .csproj file.
Every form has a signature in the file like this
<Compile Include="Opers\MyForm.cs">
<SubType>Form</SubType>
</Compile>
The SubType element says that this is actually a form and in my file this was deleted for some reason.
I would highly recommend to avoid inheriting forms whenever possible. For saving settings, this is surely avoidable: make yourself an FormSettingsSaver class or something like that and pass it the form as argument when loading/closing, etc.
Inheriting forms can make a lot of headaches and MS isnĀ“t really putting any work in WindowsForms and/or the Designer.
edit: if you want to stick with inheriting forms, check the link from rene in the comment. Most designer problems can be avoided with checking for DesignMode. You could also try to comment out statements until you find the culprit. All code in the constructor and (i think) OnLoad is executed when the form is displayed in the Designer, so there would be a good place to start.