Hide and unhide

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • traewathen
    New Member
    • Jun 2007
    • 3

    Hide and unhide

    Hello all i am rather new to the whole c # and .net language. my question is in regards to the c# portion of the matter. this is my code block which i have for hiding and unhiding::

    Code:
            private void Form1_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.Alt && e.KeyCode.ToString() == "F")
                {
                    // When the user presses both the 'Alt' key and 'F' key,
                    // KeyPreview is set to False, and a message appears.
                    // This message is only displayed when KeyPreview is set to True.
                    this.Visible = false;
                    MessageBox.Show("KeyPreview is True, and this is from the FORM.");
                }
            }
            private void textBox1_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.Alt && e.KeyCode.ToString() == "F")
                {
                    // When the user presses both the 'Alt' key and 'F' key,
                    // KeyPreview is set to False, and a message appears.
                    // This message is only displayed when KeyPreview is set to False.
                    this.KeyPreview = true;
                    MessageBox.Show("KeyPreview is False, and this is from the CONTROL.");
                }
            }

    now what my main question is how do i call to a form after it hidden per a keyboard shortcut... i do not want a system tray icon to show or anything this a key combination to bring it back. what it appears is that i may have to use another method due to the fact that i can't input to the form directly if it is hidden. any help is greatly appreciated.

    Trae Wathen
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    You need to create what I believe is refered to as a "global hook", your program will monitor keyboard events even when it does not have the focus.
    I cannot remember how to do this (it might require a dllimport) but google "global hook in c#" or something.
    They are not natively supported in .NET
    See: http://support.microsoft.com/kb/318804
    And : http://msdn2.microsoft.com/en-us/library/ms644959.aspx

    Comment

    Working...