none
Unhide Event? RRS feed

  • Question

  • In my program I will hide a form.  When I wish to "unhide" it, I wish to run some code.  Which event allows to do this?

    Thanks.





    • Edited by Jeff07 Wednesday, March 14, 2018 5:07 PM
    Wednesday, March 14, 2018 4:45 PM

Answers

  • Got it.  When I want to Show the form again, I want some code to automatically run.  How can I do this?

    ISV using VB.net and SQL Server Express

    Look at the Form.VisibleChanged event if you are "hiding" the form by changing its visibility.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Marked as answer by Jeff07 Wednesday, March 14, 2018 6:10 PM
    Wednesday, March 14, 2018 5:30 PM
    Moderator

All replies

  • Hi

    Where ever you have the 'unhide' code, can't you add the code you want to run there?


    Regards Les, Livingston, Scotland

    Wednesday, March 14, 2018 4:56 PM
  • I did a poor job framing my question.

    Here is a better version:

    "In my program I will hide a form.  When I wish to "unhide" it, I wish to run some code.  Which event allows to do this?"


    ISV using VB.net and SQL Server Express

    Wednesday, March 14, 2018 5:09 PM
  • I'm not sure if I can understand your question.

    You can use "Visible" property: yourForm.Visible = True (or = False)


    Ashidacchi >> http://hokusosha.com/

    Wednesday, March 14, 2018 5:11 PM
  • Jeff,

    That is not an event. That is a method. Hide and to show it again the method is Show. 

    You can just use it without anything extra in a form. 

    (And event is something that happens and then is handled)


    Success
    Cor


    Wednesday, March 14, 2018 5:13 PM
  • Got it.  When I want to Show the form again, I want some code to automatically run.  How can I do this?

    ISV using VB.net and SQL Server Express

    Wednesday, March 14, 2018 5:16 PM
  • Hi

    Just asking the same question again doesn't help us to help you.

    Show the code that you use to hide the Form, and tell us what the user does to unhide it again - a Button perhaps?


    Regards Les, Livingston, Scotland


    • Edited by leshay Wednesday, March 14, 2018 5:25 PM
    Wednesday, March 14, 2018 5:25 PM
  • You only add some code  after yourForm.Visible = True.

    Ashidacchi >> http://hokusosha.com/

    Wednesday, March 14, 2018 5:25 PM
  • Got it.  When I want to Show the form again, I want some code to automatically run.  How can I do this?

    ISV using VB.net and SQL Server Express

    Look at the Form.VisibleChanged event if you are "hiding" the form by changing its visibility.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Marked as answer by Jeff07 Wednesday, March 14, 2018 6:10 PM
    Wednesday, March 14, 2018 5:30 PM
    Moderator
  • In addition to Les, 

    Normally that show and hide is somewhere in your code. 

    You are the programmer. If you want to give the user a way to hide it. Then you have to create somewhere a button (or something likewise) which does that. And to show it then you need again something as a button. (But of course not on the hidded form).

    In addition to Ashidachhi

    Hide and Show are methods which sets the form property Visible to True or False. 


    Success
    Cor


    Wednesday, March 14, 2018 5:32 PM
  • That is what I was looking for.  Good job.  5 stars for you.


    ISV using VB.net and SQL Server Express

    Wednesday, March 14, 2018 6:11 PM
  • That is what I was looking for.  Good job.  5 stars for you.


    ISV using VB.net and SQL Server Express

    Yes this is a direct reply on your question. I did not want to give this and Les and Ashdacchi probably as well not while they knew it too.  

    But tell me: what are you handling. How can the form be hidden if you did not made that possible?

    So you say in an anology: Close your eyes, Click off the light switch. Then open your eyes again and if it is dark, you know the light is off" 

    Yea some beginning coders do it like that but their programs have seldom a long lifetime.


    Success
    Cor




    Wednesday, March 14, 2018 6:43 PM
  • Though I am not a beginner coder, I act like one.

    I hide a form.  When I show it again I want to pull some data from another visible form.  I am sure that this is not the best approach to what I am trying to do, but it works and customers love my programs and they pay good money to use them.  All of them have been around for the last 20 years or so.

    As a coder, my rating is around 1 on a scale of 1-10.

    BTW, your replies where not helpful but thanks for trying.


    ISV using VB.net and SQL Server Express

    Wednesday, March 14, 2018 8:50 PM
  • In my program I will hide a form.  When I wish to "unhide" it, I wish to run some code.  Which event allows to do this?

    Thanks.





    Assuming that you are changing the visibility via the .Visible property...  Create a new project with two forms.

    Form1 has two buttons, Form2 has a Textbox.


    Form1 code

    Public Class Form1
    
        Private frm2 As Form2
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If frm2 Is Nothing OrElse frm2.IsDisposed Then
                frm2 = New Form2
                frm2.TextBox1.Text = "SHOWN"
                frm2.Show()
            End If
        End Sub
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            frm2.Visible = Not frm2.Visible 'toggle visibilty
        End Sub
    End Class
    

    Form2 Code

    Public Class Form2
    
        Private isShown As Boolean = False 'bypass initial visibility change
    
        Private Sub Form2_Shown(sender As Object, e As EventArgs) Handles Me.Shown
            isShown = True
            Debug.WriteLine("shown")
        End Sub
    
        Private Sub Form2_VisibleChanged(sender As Object, e As EventArgs) Handles Me.VisibleChanged
            If isShown Then
                If Me.Visible Then
                    Debug.WriteLine(TextBox1.Text)
                    TextBox1.Text = "From invis to vis"
                Else
                    TextBox1.Text = "can't see this because not visible"
                    Debug.WriteLine("From vis to invis")
                End If
            Else
                Debug.WriteLine("not shown")
            End If
        End Sub
    End Class

    This uses the VisibleChanged event.  Hope it helps.




    "Those who use Application.DoEvents() have no idea what it does and those who know what it does never use it" - MSDN User JohnWein

    Wednesday, March 14, 2018 9:33 PM
  • Though I am not a beginner coder, I act like one.

    The problem was in the question.  This would have made sense to me:
    "In my program I will hide a form.  When it gets "unhidden", I wish some code on that form to execute.  Which event allows to do this?"

    Wednesday, March 14, 2018 10:02 PM
  • Thank you.

    ISV using VB.net and SQL Server Express

    Wednesday, March 14, 2018 10:20 PM
  • Acamar,

    I tried to tell that there was no need to use an event. If you make a good program you control this kind of things. 

    Public Class Form1
        Private Frm2 As New Form2
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Frm2.TextBox1.Text = "Show"
            Frm2.Show()
        End Sub
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Frm2.TextBox1.Text = ""
            Frm2.Hide()
        End Sub
    End Class


    Success
    Cor

    Wednesday, March 14, 2018 11:17 PM
  • I tried to tell that there was no need to use an event. If you make a good program you control this kind of things.

    "Good" or "Bad" is another discussion.  I was simply pointing out a possible explanation for the delay in getting an answer.

    Wednesday, March 14, 2018 11:33 PM
  • Most useful.

    ISV using VB.net and SQL Server Express

    Thursday, March 15, 2018 12:11 AM