Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 829985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:58:09+00:00 2026-05-15T03:58:09+00:00

I wrote a bunch of code in the .cs file in c# for a

  • 0

I wrote a bunch of code in the .cs file in c# for a winforms application. The application runs fine, and everything is in it’s place.

Something like this:

using..

namespace Temp
{
  public class Temp : Form
  {
    Button b1;
    TextBox t1;

    Temp()
    {
       b1.Text = "Some Text";
       b1.Size = new Size(50,20);
       ...
    }

    void function1()
    {
       // stuff
    }

    static void Main()
    {
       Application.Run(new Temp());
    }
  }
}

How can I modify my code (or fix it somehow) so that the design view displays the elements in their correct positions and view so that I can visually edit them instead of having to trial/error everything.

Edit for Clarification

My application runs fine. The problem is, that I didn’t use designer to create the application and so in the designer view, the app is empty. But not empty when I run it, since everything is positioned programmatically in the .cs file. My question is, how can I fix this, so that the designer shows the objects correctly.

There is no quick fix other than to redesign everything?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T03:58:10+00:00Added an answer on May 15, 2026 at 3:58 am

    So to get this shown within the designer you have to know how the designer works.

    For every MyForm.cs there will automatically be a file called MyForm.Designer.cs be created. Within this Designer file there will be only one function called InitializeComponents(). This function will be called within the constructor of your MyForm.cs file.

    The design viewer itself is responsible for the Designer file, so any change to this file while the design view is open would normally be discarded. Also if you put some code into the designer file that is not needed be the designer will be truncated.

    So the next question is, when will this truncation happen? When you freshly open the design viewer of a form, it will read in everything from the Designer.cs file without making any changes. If you make any changes onto the form by the designer the complete file will be rewritten with all the settings already read in including your latest changes.

    This behaviour can be monitored if you open the designer file also as source code view, make some little changes in design mode and afterwards take a close look at the left of the source file. There will be the changes marked with a yellow or a green marker.

    Now after all this stuff of informations, you can try the following procedure to get your code into the designer:

    • Open the design view and put some simple control onto your form (e.g. TextBox)
    • Save and close the design view and open the Designer.cs file as source file
    • Copy all your variables name of your controls at the end of the file, right below the textBox1 line
    • Copy all your control property settings within the InitializeComponent() function right below the property settings of the TextBox
    • Copy all your control constructors to the top of the file, right below the constructor of the TextBox
    • Save the file and open your form in design view
    • Select the dummy TextBox on the design view and delete it
      • This change within the DesignView leads to a complete rewrite of the designer.cs file, ordering all your manually added stuff the right way.

    So this is the way to go. Last but not least another little trick:
    Every programmer uses the using-statement to not write the whole path to every class (like System.Windows.Forms.TextBox), but the designer writes always the whole path. To make it a little easier for your copy and paste session you can also add a using statement at the top of the file. After saving and changing something in Design View all this stuff will be re-written automatically. So you don’t need to add all this paths manually while your adding your stuff to the Designer.cs file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote an application that currently runs against a local instance of MySql. I
I've got a bunch of legacy code that I need to write unit tests
I'd like to write a script/batch that will bunch up my daily IIS logs
I wrote a simple batch file as a PowerShell script, and I am getting
I wrote a windows service using VB that read some legacy data from Visual
I wrote myself a little downloading application so that I could easily grab a
I wrote a simple tool to generate a DBUnit XML dataset using queries that
I've got a bunch of properties which I am going to use read/write locks
Wrote the following in PowersHell as a quick iTunes demonstration: $iTunes = New-Object -ComObject
I wrote a component that displays a filename, a thumbnail and has a button

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.