button visablity

starcraft

Well-known member
Joined
Jun 29, 2003
Messages
167
Location
Poway CA
i am using visablity true false cause i dont know how to link to another form in the same project :( so im trying this but its not working.
Code:
dim button as button
For Each button In me.controls
            button.Visible = False
        Next
any suggestions?
 
Try this:

[VB]
Dim ctrl As Control
For Each ctrl In Me.Controls
ctrl.Visible = Not (TypeOf ctrl Is Button)
Next
[/VB]
 
What you have should work all good, becuase it does :). What errors are you getting ? You said something about no being able to link to another form, do you want to modify buttons on another form?
 
Actually, starcrafts solution will work if the only controls in the Me reference are of the Button class; otherwise, InvalidCastException. But youre right, mutant; that may not be the problem at all.
 
sorry maybe i wasnt clear, because i dont know how to have the user click a button and it go to another form in the same project i was going to have it were it clears all objects fromt the current form and then and then set only the thing relating to that button visable. this is a hard way to do it but i dont know how to link different forms :(
 
hmm now im getting confused. I wont to have a main screen when there will be a number of buttons. i wonted to be able to have when the user click a spacific button it would link to another form in the same project. Example: we have form1 with 2 buttons in the background we also have form2 and 3 when the user click button 1 it will hide all forms and show form2 when the uer clicks button 2 it will hide all forms and show form3. *
i hope that gives u an idea as to where im going. i hope
 
The best way would be to pass the form instances in constructors. And then access them from there. You would have to modify the Sub New to accept argumets.
 
ive attached a sample project with 3 forms and 2 buttons on the main form to hide the other forms , except the form2 or form3 depending on the button , and a button on form2 and form3 to then show all forms again. give it a try and let me know if it makes sense :)
 

Attachments

yeah thats what i wont to do but for sum reason there is no visible code on any of the files. i open them an there is nothing there??? i cant see the forms or anything?? but it works
 
ok well heres the code version :
in Form1 :
Code:
    Public frm2 As New Form2()
    Public frm3 As New Form3()
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.AddOwnedForm(frm2)
        Me.AddOwnedForm(frm3)

    End Sub



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        frm2.Show()
        frm3.Hide()
        Me.Hide()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        frm3.Show()
        frm2.Hide()
        Me.Hide()
    End Sub

    Public Sub ShowAllForms()
        Me.Show()
        frm2.Show()
        frm3.Show()
    End Sub
in Form2 :
Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim frmBoss As Form1 = Me.Owner
        frmBoss.ShowAllForms()
    End Sub
in Form3 :
Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim frmBoss As Form1 = Me.Owner
        frmBoss.ShowAllForms()
    End Sub
hope it helps :)
 
np glad to have helped :) , quite an easy way to share data between forms really that , saves a lot of headaches and you can do it to pass data from one form to anothers controls also ( eg : textbox /listbox etc )
 
heh ive almost finished the project that u helped me with. but i have one more question. How do i compair 2 text boxes to see if the information entered is the same and if not to make a msg box say something like" your passwords do not match" and if the do match then continue?
 
Code:
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Select Case TextBox1.Text
            Case TextBox2.Text /// same text in textbox2 and textbox1
                MessageBox.Show("the passwords match! ")
            Case Else /// different texts
                MessageBox.Show("oops you typed the wrong password! ")
        End Select
    End Sub
hope that helps :)
 
Back
Top