Results 1 to 7 of 7

Thread: Move "windows form designer generated code" to designer.vb

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2008
    Posts
    217

    Move "windows form designer generated code" to designer.vb

    I've imported a form from an older version of VB.net into VB 2010. Is it possible to create a designer.vb for a form and move the "windows form designer generated code" region to it?

  2. #2
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: Move "windows form designer generated code" to designer.vb

    It is, but you have to be very, very careful how you do it.

    The easiest way to go about it would be something like:
    1. Copy your .vb file somewhere far away from the project, where you won't ever accidentally delete it. You're going to be moving files around and this is how accidents happen.
    2. Copy it somewhere else, too, just to be safe. In fact, why not just email yourself a copy so it's there as well?
    3. Heck, just zip up your project and put that somewhere safe too, so if you screw up you can go back to how things were.
    4. Remove the file from your project in the IDE. This will delete it. You could remove it without deleting it, but when you get to the next step you'll have trouble. So delete it. See why I said to copy it somewhere else first?
    5. Create a new file with the same name in the IDE. This one will have the "whatever.vb" and "whatever.designer.vb" file.
    6. Close the designer. If the designer's open, it might muck with your .designer.vb file.
    7. Open your copied file from step 1 or 2. Find the "Windows Forms Designer Generated Code" section. You need to copy that into your .designer.vb file, but pay attention and make sure you copy things correctly. Variables need to be in the right place, methods need to be in the right place, etc. It's important you don't paste over the new class definition, it probably contains the word "Partial" and if you overwrite that things are going to break.
    8. Now open the not-designer .vb file in code view. Copy the not-designer code into it, as carefully as before.
    9. Now everything ought to work. If you got errors, you did something wrong. The error on the topmost line ought to indicate what you did wrong. Fix that, and repeat until there are no errors.


    There's another way that involves more direct work, but I think the above way's the safest. If you screw up at any point, you can always delete the new files and re-add the copied files. And if that still doesn't work, you've got that .zip file you made, just in case.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    37,863

    Re: Move "windows form designer generated code" to designer.vb

    Why would you want to do that? There's no particular advantage to having it off in a different file other than tidiness, and even tidiness isn't that big a deal because you could put the whole thing in a #Region and leave it hidden. I have a program written by a generator that works like that. The designer has no problem working with it.
    My usual boring signature: Nothing

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Dec 2008
    Posts
    217

    Re: Move "windows form designer generated code" to designer.vb

    Thanks for the responses. I just wondered. I think it's best to leave it since it's not doing any harm.

  5. #5
    New Member
    Join Date
    Mar 2015
    Posts
    5

    Re: Move "windows form designer generated code" to designer.vb

    Well, one reason you might want to do it is when you are searching for occurrences of a variable that is defined in the windows form designer generated code. You can hit "find next" for quite a while before you get to the variable that is in your code. Having the designer code in its own file eliminates that problem and makes searching for variables much easier and straight forward.

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    37,863

    Re: Move "windows form designer generated code" to designer.vb

    That can be true if the variable is found solely in that file. There is nothing special about partial classes, so it is entirely possible to spread a partial class across multiple files, and there are a few reasons a person might reasonably do that. That's all the .designer.vb file is, too. Therefore, if you are searching for all uses of some variable, you have to know whether it is sufficient to just search the current document. If you know that's all you need to do, then you can ignore partial classes. If you don't know that, then you had best be including partial classes, which will include the .designer.vb file, since it's just a partial class.
    My usual boring signature: Nothing

  7. #7
    New Member
    Join Date
    Nov 2022
    Posts
    1

    Re: Move "windows form designer generated code" to designer.vb

    Quote Originally Posted by jcvamp View Post
    I've imported a form from an older version of VB.net into VB 2010. Is it possible to create a designer.vb for a form and move the "windows form designer generated code" region to it?
    I know that this is an old thread but I have just completed this operation on a very large project and thought I would provide the following steps to accomplish the task. It really is just a clarification of the original procedure (Kudos To The Author jcvamp)
    It can be a very tedious procedure but it does clean up code and facilitates better navigation (Particularly 'Find')

    STEPS TO ELIMINATE THE "Windows Form Designer generated code" FROM YOUR VB.NET CODE MODULE
    11/27/2022


    1) Using File Manager, Copy The Desired "<MyForm>.vb" And The "<MyForm>.resx" Files And Save Them Outside The Project.

    2) Open The Project In The IDE ('Project IDE') And Delete This File From The Project.
    (Solution Explorer => Right Click => 'Delete')

    3) In The 'Project IDE', Create A New <MyForm>.vb File (With The Same Name) (Solution Explorer => Add => Windows Form).
    It Will Create A New Form Which Will Be Replaced By The Steps Which Follow
    This Will Create The New "<MyForm>.vb" As Well As The "<MyForm>.designer.vb" Files.

    4) Close The 'Project IDE'. If The IDE Remains Open, It Will Alter The New "<MyForm>.designer.vb" File.

    5) Open The Copied File (Click On The "<MyForm>.vb" File From File Manager) From Step 1
    It Will Open A New IDE ('Source IDE') With Just This File.
    Find The "Windows Forms Designer Generated Code" Section.
    Copy This Entire Section To The Clipboard (INCLUDE: 'Imports System.Windows.Forms.Form')
    Open The 'Project IDE' With The (Modified) Project From Step 3).
    Go To 'Solutions Explorer' => 'Show All Files' And Paste The Clipboard Into The New "<MyForm>.designer.vb" File.
    Do Not Paste Over The New Class Definition (It Will Contain The Specifier "Partial")

    6) In The 'Project IDE', Open The New "<MyForm>.vb" File In Code View.
    From The 'Source IDE', Copy The Form's User Code And Paste It Into The New "<MyForm>.vb" File In The 'Project IDE'
    (INCLUDE: 'Option Strict On', 'Option Explicit On', And Any 'Inherits' Specifiers)

    7) Using File Manager, Copy The "<MyForm>.resx" File And Paste Into The Project Folder

    8) In The 'Project IDE' Form Design View, Make Sure To Add ALL The Original Icons/Images To The New Form
    If The Form Uses Many Icons And Images, This Could Be The Most Tedious Portion Of The Entire Process
    Seemingly Unrelated Build Errors Can Be Caused By Missing Icons/Images
    These Build Errors Will Usually Be Cleared By Adding The Missing Elements
    If There Are No Icons/Images To Add, It Is Still Necessary To Change The Form's Icon To Some (Temporary) Icon Then
    Build The Projcet (If Desired Replace The Temporary Form Icon With The Required Icon)
    (NOTE: In 'Solution Explorer' => 'View Designer' It May Be Necessary To Override Any Build Error(s)
    To Get To The New Form's Design To Make Icon/Image Changes)

    9) Check: 'Solution Explorer' => "<MyForm>.vb" => 'Properties' => 'Build Action' => 'Compile'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width