Results 1 to 13 of 13

Thread: Form1 went blank after debugging

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2013
    Posts
    77

    Form1 went blank after debugging

    Hello there,
    Merry Christmas to everyone!

    Today I went to add some more codes in my application (Around 600 lines form1, and 12 more forms)

    When I finished adding these codes (and 4 buttons) and I tried to debug it. But, surprisingly the form was empty. Everything disappeared for some reason. The properties, codes, etc still exist. But not the buttons, textboxes, etc. (Controls - Items)

    Do you know how can I fix this? I would really appreciate if you could help me.

    P.S: I'm using a custom theme in case this helps
    P.S2: No warnings/errors

    Thank you in advance,
    N1nj4Styl3.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    35,238

    Re: Form1 went blank after debugging

    Which version of VS are you using? Somebody just posted a similar issue within the last month, so I'm wondering if there isn't some issue with a recent release.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2013
    Posts
    77

    Re: Form1 went blank after debugging

    Quote Originally Posted by Shaggy Hiker View Post
    Which version of VS are you using? Somebody just posted a similar issue within the last month, so I'm wondering if there isn't some issue with a recent release.
    Hello, thanks for replying.

    Here's a screenshot:

    Attached Images Attached Images  

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2013
    Posts
    77

    Re: Form1 went blank after debugging

    Found the solution. Thanks to EternalDarkness from HF.

    The problem comes from Form1Designer(obvious)

    The theme I use, has a bad way of 'storing' controls which resulted in losing all of them.

    I'll post the solution below:

    Code:
    >Open Form1Designer
    >Search for: "Me.Controls.Add(Me.Form1)" (Form1 = Name of theme or form) (In case you don't find it, just type: "Me.Controls.Add(Me. and you will find it)
    >Add below Me.Controls.Add(Me.Form1) the following code:
    
    Form1.Controls.Add(button1) -> It will show button1 in your form
    
    So you do the same for the rest. 
    
    In case you've everything on a tabcontrol you're lucky, because adding tabcontrol will show everything.
    
    Just by doing this: Form1.Controls.Add(tabcontrol1) (you type this below as I said above)
    
    This is the fix.
    
    Thanks for the reply Shaggy! Merry Christmas!

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    35,238

    Re: Form1 went blank after debugging

    That's really weird. After all, the 'solution' is to add back in a bunch of lines that would normally appear in the .designer.vb file associated with the form. Every control has to be in some Controls collection. If the controls are directly on the form, then they are in the forms Controls collection (which is exactly what you are seeing in the first part). If they are on something like a tab page, GroupBox, Panel, or any other container, then they are in the Controls collection for that container, which is what the final part is saying.

    So, this is certainly a fix, but it's a pretty weird one because it shouldn't be necessary. That's what the form designer does, so you are left with the question: Why is the form designer not doing what it is supposed to do, and which it does correctly for everyone else? I have no answer for that. It could be a corrupted installation, it could be something else. There is a method called InitializeComponents. Normally, this is found in the .designer.vb file for the form (you can see this file with Show All Files in the Solution Explorer). It doesn't HAVE to be found there, but it will be if you let the designer create the .designer.vb file. That method creates the controls, sets the properties for the controls (the same ones you have set in the designer, such as location, text, fonts, and so forth), and adds them to the correct .Controls collection. From the sound of it, you have managed to get part of that removed from the InitializeComponents method. It sounds like the properties such as text, location, fonts, and so forth are retained, so those will still be found in InitializeComponents (unless you are setting those properties elsewhere), but the lines that add the controls to the .Controls collection have been removed. So, the question remains: How did that happen?

    Note that nothing about the designer is magic in any way. The result of anything done in the designer is just .NET code that looks and works just like any other code. You don't need to use the designer to add or manage forms. All of it could be done by code, which could be written in Notepad as far as the compiler is concerned. The designer is convenient, as it gives you a visual way to design the forms, but it just results in code like any other code. Yours is doing something wrong.
    My usual boring signature: Nothing

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Aug 2013
    Posts
    77

    Re: Form1 went blank after debugging

    Hello.

    This is EternalDarkness's reply in another thread:

    So on first look through I am seeing a distinct lack of "StRForm1.Controls.Add()" statements...
    I am assuming that the form control is a container control (not the smartest decision so I will test it for non container control as well)...

    Right before you see this line "Me.Controls.Add(Me.StRForm1)" (towards the bottom)
    Try adding "StRForm1.Controls.Add(TabControl1)", and if that does not work "Me.Controls.Add(TabControl1)"
    If one of these lines of code works, then tell me which...

    That will not fix everything, just is a possible starting point... xD

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Aug 2013
    Posts
    77

    Re: Form1 went blank after debugging

    Here's the theme that was used by the other guy (where EternalDarkness replied with the quote above)

    Theme.vb: http://pastebin.com/2MMJYKCn

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    35,238

    Re: Form1 went blank after debugging

    Technically, ALL controls are container controls, since they all have a Controls collection that you can add other controls to. It is just that it makes a whole lot more sense to add controls to a tab page than to a radioButton, so some controls are thought of as containers while others are not. They all are capable of being containers, though.

    The issue I have is that you are treating the symptoms and not the disease. The only time you should need to be manually adding .Controls.Add statements is when you are creating controls dynamically rather than using the form designer. It sounds like you were using the designer, in which case you shouldn't normally need to write .Controls.Add statements because the designer should have written them for you. If they are missing, then that certainly is a problem and you can fix it as ED suggested, but why are they missing in the first place? If you know why they are missing, such as if you did something that would remove them, then that's fine. If you didn't do anything that should have removed them, then I'd be wondering what happened to them.
    My usual boring signature: Nothing

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Aug 2013
    Posts
    77

    Re: Form1 went blank after debugging

    Quote Originally Posted by Shaggy Hiker View Post
    Technically, ALL controls are container controls, since they all have a Controls collection that you can add other controls to. It is just that it makes a whole lot more sense to add controls to a tab page than to a radioButton, so some controls are thought of as containers while others are not. They all are capable of being containers, though.

    The issue I have is that you are treating the symptoms and not the disease. The only time you should need to be manually adding .Controls.Add statements is when you are creating controls dynamically rather than using the form designer. It sounds like you were using the designer, in which case you shouldn't normally need to write .Controls.Add statements because the designer should have written them for you. If they are missing, then that certainly is a problem and you can fix it as ED suggested, but why are they missing in the first place? If you know why they are missing, such as if you did something that would remove them, then that's fine. If you didn't do anything that should have removed them, then I'd be wondering what happened to them.
    Well, that's a good statement.

    I just remembered that I used the same theme in an old - abandoned project (I used it last year)

    So, the result is this:

    Code:
     Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.ClientSize = New System.Drawing.Size(633, 288)
            Me.Controls.Add(Me.FormSkin1)
            Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
            Me.MaximizeBox = False
            Me.MinimizeBox = False
            Me.Name = "Form1"
            Me.ShowIcon = False
            Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
            Me.Text = "Personal Bank"
            Me.TransparencyKey = System.Drawing.Color.Fuchsia
            Me.FormSkin1.ResumeLayout(False)
            Me.FormSkin1.PerformLayout()
            Me.ResumeLayout(False)
    There are no .Contros.Add statements anywhere. Although, the controls still display in the form.

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    35,238

    Re: Form1 went blank after debugging

    I see a Controls.Add statement as the fourth line down in that snippet.
    My usual boring signature: Nothing

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Aug 2013
    Posts
    77

    Re: Form1 went blank after debugging

    Quote Originally Posted by Shaggy Hiker View Post
    I see a Controls.Add statement as the fourth line down in that snippet.
    It's the only one.

    I had the same Controls.Add statement in the form which became blank.

    So, it's even more weird.

  12. #12
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    35,238

    Re: Form1 went blank after debugging

    Do you have a .designer.vb file associated with that form?
    My usual boring signature: Nothing

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Aug 2013
    Posts
    77

    Re: Form1 went blank after debugging

    Nope, just Form1.Designer.vb (This is where I showed you the codes from)

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