Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
I have a windows form but i am unable to see the UI because of some errors.Now i want to modify the Windows Form Designer generated code but nothing is working.Even though i change the size of the button the size remains the same.Please help me with this.TIA

C#
this.btnReset.Location = new System.Drawing.Point(330, 15);
         this.btnReset.Name = "btnReset";
         this.btnReset.Size = new System.Drawing.Size(0, 23);
         this.btnReset.TabIndex = 23;
         this.btnReset.Text = "Reset";
         this.btnReset.UseVisualStyleBackColor = true;
         this.btnReset.Click += new System.EventHandler(this.btnReset_Click);


Here i set the width of the button to 0 but the width is not changed.

What I have tried:

I have tried adding some buttons and groupbox to the designer code and changed the size of the existing buttons but nothing worked.
Posted
Updated 10-Feb-16 19:09pm
v3
Comments
EliteBrain 10-Feb-16 23:41pm    
Please check thhe class name(form name) it should be same in code behind and also in designer.. Also check if all the controls tags are closed properly.
Sergey Alexandrovich Kryukov 10-Feb-16 23:45pm    
What's the point of using the designer if you want to modify auto-generated code? Of course, you can do it for research purpose, to find out what's wrong...
Anyway, your "nothing worked" is not informative; how do you imagine helping you?
—SA
chandra sekhar 10-Feb-16 23:50pm    
I cant drag and drop the controls to the UI so i want to add some controls to the designer so that i can see them in UI.But even though i add controls i cant see them in the UI.
Ralf Meier 11-Feb-16 0:25am    
I think, there is no generell advise what should be given to you. It is necessary (for us) to get more Information. Perhaps you improve your question with the designer-generated-code and some further (detailed) Information - especially what exactly is not working ...
Richard MacCutchan 11-Feb-16 4:33am    
Often the errors occur because of manual editing of the designer files. Try recreating the form from scratch.

1 solution

Well the 'Button evidently does not have its 'AutoSize Property set to 'true (the default is 'false), or its 'MinimumSize Property set (the default is 0,0).

Setting a Button 'Width to #0 in the Designer.cs file will not cause a compile-time, or run-time, error: it will just hide the Button.

And, setting 'Width to #0 to hide a Control makes no "sense:" hide a Control by setting its 'Visible Property to 'False.

So something else is going on, and the important information you need to share here is what error messages you get when try to open the Form in 'Designer View.'

A strategy I have used when something is so screwed-up that I can't access the designer view is:

First, always make a copy of the broken Project, and save it for possible future re-use.

a. open another instance of Visual Studio, create a new Project.

b. re-create the UI, use the same Names for NameSpace and Forms, UserControls, etc.

c. either

c.1. copy-and-paste code (Classes, Form Code) from the broken Project to the new Project equivalent code-behind.

c.2. after I have saved important code I don't want to lose from the original project, then go back and start deleting the various UI elements from the Designer.cs file one-at-a-time until you isolate what's broken.

However, this "dirty business" might be avoided if you can figure out what the error messages you get when you can't open the Form or UserControl, or Component, in design view.
 
Share this answer
 
Comments
chandra sekhar 11-Feb-16 3:52am    
I am getting a single error message as "Object reference not set to an instance of an object"
BillWoodruff 11-Feb-16 10:10am    
Set break-points in your code, and when you hit the break-points, single-step (F11 in Visual Studio) until you reach the line with the error. Then, if you can't figure out why it's breaking, come back here and show a sample of the code where the error occurs.
Philippe Mori 11-Feb-16 12:57pm    
You can use another instance of Visual Studio to debug the problem. If you stop on exceptions, you will see what cause the designer to crash. Usually, it is code in constructor or Load event that use some variables that are null at design time. Often, you can skip code if DesignMode is true.

Essentially, you debug the instance of Visual Studio using another instance and attach the debugger to the existing instance and then you open the designer that cannt be shown.

This is usefull only if the designer don't already tells you the problem and you cannot figure it yourself.
BillWoodruff 11-Feb-16 13:13pm    
It would be useful if the OP did tell us what the error messages are that appear in the design view. However, I have had cases where something got corrupted, like the .resx file, and had no choice but to re-build the app by copying the code over in a new project.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900