Solved

How to create designer.cs file (c#)

Posted on 2006-10-23
14
2,835 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

630 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