Results 1 to 12 of 12

Thread: how to hide a form in vb7(problems)

  1. #1

    Thread Starter
    Junior Member jernej's Avatar
    Join Date
    Jul 2002
    Posts
    16

    how to hide a form in vb7(problems)

    I am trying to hide a form from user , but the form only hides itself if i add me.hide() command to a button on_click event.

    If i have me.hide() command in form_load event or right after the InitializeComponent() command, the form doesnt hides itself.

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    I know how you feel
    if you always want to hide the form when it gets loaded then put the me.hide in the ACTIVATE event.

    VB Code:
    1. Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
    2.         Me.Hide()
    3. End Sub
    this should work

    there is something that I CAN NOT SOLVE though!!! the thing is that the form will show up for a second and then it will hide.... that's pretty stupid. Dunno if there is a way to aviod that

  3. #3
    hellswraith
    Guest
    Try editing the InitializeComponent sub where it lists all the forms properties. Set the Visible to false.

  4. #4
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by hellswraith
    Try editing the InitializeComponent sub where it lists all the forms properties. Set the Visible to false.
    looks like a lovely solution, but dunno why, it aint working...

  5. #5
    hellswraith
    Guest
    Yep, I just tried it, don't know why...I will try to figure it out some more.

  6. #6
    hellswraith
    Guest
    Ok, I think I figured it out. You need to create the control without showing it.

    The easiest way I did this is create a class variable that will be the form. You need this to be a class level variable because you will be referencing it in two different subs:
    Private frm As Form2

    Then I put two buttons on Form1. The first button creates the form object and assigns it to the frm variable.

    The second button will assign one of the frm's controls text property just to show that the frm object was created, then it shows the form.

    I hope this is what you need:

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         frm = New Form2()
    3.         frm.CreateControl()
    4.     End Sub
    5.  
    6.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    7.         frm.Label1.Text = "Yep, I have been created in memory, just waiting to be shown"
    8.         frm.Show()
    9.     End Sub

  7. #7

    Thread Starter
    Junior Member jernej's Avatar
    Join Date
    Jul 2002
    Posts
    16

    hm...

    in vb7 help there is a sample , the author uses there me.hide right after the InitializeComponent() commnad.I tried to figure it out why in my case this doesnt work and the i saw that the true reason why the form gets hidden is the form.opacity property with the value 0.

  8. #8

    Thread Starter
    Junior Member jernej's Avatar
    Join Date
    Jul 2002
    Posts
    16
    Originally posted by MrPolite
    I know how you feel
    if you always want to hide the form when it gets loaded then put the me.hide in the ACTIVATE event.

    VB Code:
    1. Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
    2.         Me.Hide()
    3. End Sub
    this should work

    there is something that I CAN NOT SOLVE though!!! the thing is that the form will show up for a second and then it will hide.... that's pretty stupid. Dunno if there is a way to aviod that
    you can avoid this to set the form opacity to 0%

  9. #9
    hellswraith
    Guest
    Did you check out the way I found? It does what you want without having to set the opacity to 0%.

    Can I ask what it is your trying to do by creating a form and not showing it? I am just wondering in what ways you would use this for.

  10. #10
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by hellswraith
    Ok, I think I figured it out. You need to create the control without showing it.

    The easiest way I did this is create a class variable that will be the form. You need this to be a class level variable because you will be referencing it in two different subs:
    Private frm As Form2

    Then I put two buttons on Form1. The first button creates the form object and assigns it to the frm variable.

    The second button will assign one of the frm's controls text property just to show that the frm object was created, then it shows the form.

    I hope this is what you need:

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         frm = New Form2()
    3.         frm.CreateControl()
    4.     End Sub
    5.  
    6.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    7.         frm.Label1.Text = "Yep, I have been created in memory, just waiting to be shown"
    8.         frm.Show()
    9.     End Sub
    I'm just wondering about something. When you call the CreateControl sub, does the Form_Load event and all that stuff still run? I mean before calling the Show event, all the Load event and stuff will fire that way?

  11. #11

    Thread Starter
    Junior Member jernej's Avatar
    Join Date
    Jul 2002
    Posts
    16

    notifyicon

    i made a tray icon for my program on this form, that is why i dont want to show this form because with this form i start my program with, but it makes only a trayicon.

    hm i was wondering what is the difference between
    form.visible=false and form.hide........
    anyway thanks for your answers

  12. #12
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872

    opacity

    you could also use the property of the form: Opacity
    if you set this property to 0% the form is completly transparant

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