Solved

How to create designer.cs file (c#)

Posted on 2006-10-23
14
2,697 Views
Last Modified: 2007-12-19
Hi experts,

I converted a C# .net 2003 application to .net 2005... but the conversion has not created the *.Designer.cs file for the forms. Now i would like to export the "generated codes" to that designer file. There is any tools (or else) which let me do that?!?!

Any help would be appreciate.

Mart.
0
Comment
Question by:pmrenaud
  • 6
  • 6
14 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 125 total points
ID: 17788716
You can do this manually: create *.Designer.cs file and add it to the project. Move all designer-generated code there. Declare class as partial in both files. You can create new Windows application program to see what is *.Designer.cs file structure. It contains the following parts:
components variable declaration,
Dispose method,
InitializeComponent function in the "Windows Form Designer generated code" region,
Control members.

namespace WindowsApplication1
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            //
            // button1
            //
            this.button1.Location = new System.Drawing.Point(78, 85);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(130, 33);
            this.button1.TabIndex = 0;
            this.button1.Text = "button1";
            this.button1.UseVisualStyleBackColor = true;
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Controls.Add(this.button1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.Button button1;
    }
}

There are no hidden features in *.Designer.cs file, if you create it as designer expects, it will work.
0
 

Author Comment

by:pmrenaud
ID: 17789159
I created the Dispose routine and i got this error:
Error      1      'src.com.laubrass.stataudit.view.MainScreen.Dispose(bool)': no suitable method found to override

what's wrong?!?

thks
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 17789310
Is class derived from Form class? In Wizard-generated application we can see:

Form1.cs:

    public partial class Form1 : Form
    {
    }

Form1.Designer.cs:

    partial class Form1
    {
    }

Can you post here code in both files?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:pmrenaud
ID: 17789361
Hi again,

in fact, we have now two classes: one for the form.cs and an other one for form.designer.cs. In the View class diagram, i see two diagrams, not only one. And obviously, during the debugging, i have errors... because each of them are not able to see the other one.

thks
0
 

Author Comment

by:pmrenaud
ID: 17789387
Here is what i have..

MainScreen.cs:

public partial class MainScreen: Form
{
}

MainScreen.Designer.cs:

 partial class MainScreen
{
}
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 17789435
Can you post code here? Maybe without unnecessary event handlers and functions in MainScreen.cs. Something that I can reproduce and test.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 17789465
I made small test: created Windows Forms application and removed Form1 from it. Then I added new empty Form1.cs and Form1.Designer.cs files to the project, and pasted code from other application. It works OK. Your code has some syntax error. Maybe two classes belong to different namespaces?
0
 

Author Comment

by:pmrenaud
ID: 17789996
Well...

the forms have been created in C# .Net 2003 and have been "converted" into C# .Net 2005. The convertion has not create the *.Designer.cs file...

i'm going to try the creation of the designer file one more time... and i get back!

thks
0
 

Author Comment

by:pmrenaud
ID: 17790477
We've found the problem, there was a typo in one of the two namespace definitions.

(shame on me!!!)

0
 
LVL 48

Expert Comment

by:AlexFM
ID: 17964511
I think the question is answered.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 18034783
Again, I think that question is answered and questioner followed my solution.
0
 

Author Comment

by:pmrenaud
ID: 18036341
thks for answers... sorry for delay...
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Server Error 11 58
Install Problem 13 31
Call windows 10 virtual keyboard from windows forms app 2 35
Release Dynamically Allocated Memory in C# 3 25
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question