|
-
Jul 13th, 2002, 02:45 PM
#1
Thread Starter
Junior Member
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.
-
Jul 13th, 2002, 03:10 PM
#2
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:
Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
Me.Hide()
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
-
Jul 13th, 2002, 03:11 PM
#3
Try editing the InitializeComponent sub where it lists all the forms properties. Set the Visible to false.
-
Jul 13th, 2002, 03:13 PM
#4
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...
-
Jul 13th, 2002, 03:22 PM
#5
Yep, I just tried it, don't know why...I will try to figure it out some more.
-
Jul 13th, 2002, 03:29 PM
#6
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:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
frm = New Form2()
frm.CreateControl()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
frm.Label1.Text = "Yep, I have been created in memory, just waiting to be shown"
frm.Show()
End Sub
-
Jul 13th, 2002, 03:50 PM
#7
Thread Starter
Junior Member
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.
-
Jul 13th, 2002, 03:53 PM
#8
Thread Starter
Junior Member
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:
Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
Me.Hide()
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%
-
Jul 13th, 2002, 04:02 PM
#9
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.
-
Jul 13th, 2002, 04:28 PM
#10
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:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
frm = New Form2()
frm.CreateControl()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
frm.Label1.Text = "Yep, I have been created in memory, just waiting to be shown"
frm.Show()
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?
-
Jul 13th, 2002, 05:57 PM
#11
Thread Starter
Junior Member
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
-
Jul 14th, 2002, 02:32 AM
#12
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|