Solved

How to create designer.cs file (c#)

Posted on 2006-10-23
14
2,674 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

867 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now