Solved

How to create designer.cs file (c#)

Posted on 2006-10-23
14
2,638 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Can you post code here? Maybe without unnecessary event handlers and functions in MainScreen.cs. Something that I can reproduce and test.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 48

Expert Comment

by:AlexFM
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I think the question is answered.
0
 
LVL 48

Expert Comment

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

Author Comment

by:pmrenaud
Comment Utility
thks for answers... sorry for delay...
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

7 Experts available now in Live!

Get 1:1 Help Now