Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi
I am creating an windows form application which is having a condition, if the condition is true the form shouldn't be display if not it should display.Now if the form is in hiding position then it should visible after pressed some shortcut key(like Ctrl+s,Alt+s) so please suggest me how would I do that.
 
Thanks
Prafulla
Posted 24-Sep-12 1:43am
Edited 24-Sep-12 2:09am
v2
Comments
Andrei Straut at 24-Sep-12 7:48am
   
Pst! Let me give you a tip! This is already documented on MSDN[^].
 
You didn't Google search[^] for it, did you?
_Amy at 24-Sep-12 7:50am
   
Ah! I could have given you +5 for this tip. :thumbsup:
Andrei Straut at 24-Sep-12 7:53am
   
Keep it reserved, I'll let you know when I need an upvote in the forums :))
_Amy at 24-Sep-12 8:03am
   
Sure. It is kept in CP reserve bank. :)
Prafulla Sahu at 24-Sep-12 7:58am
   
Thanks Andrei and _Amy sorry from my side I should add some more content for completing the behavior of my application.Actually now I am able to hide the application according to my condition but my requirement is when I pressed some shortcut key(like Alt+s,Shift+s) the application should display.
Andrei Straut at 24-Sep-12 8:04am
   
In this case, you can use Global Hooks. It won't matter whether or not your form has focus (which it won't while invisible anyway).
 
You can check this article[^], which explains the concept and implementation quite nicely
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You can use if conditions on form load if you have not any event behind it then you can only use in form load this.hide(); otherwise you use if condition
if(your conditions)
{
    this.hide();
} 
else
{
    this.show(); //or this.visibility = true;
}
  Permalink  
v2
Comments
Andrei Straut at 24-Sep-12 8:07am
   
Sorry, I posted this to the wrong solution. Deleted and moved here.
 
I have taken the liberty to properly format your question. I don't know whether or not you had any plans to do it yourself, but I suggest you do it in the future, if you keep posting answers.
 
It's much better to see a properly phrased and formatted answer (with code tags) for everyone that will later check or view the whole thread.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

In you form load event..
private void Form1_Load(object sender, EventArgs e)
{
    if (your_condition == false)
        this.Show();
    else
        this.Close();
}
  Permalink  
v2
Comments
Prafulla Sahu at 24-Sep-12 8:15am
   
hey ridoy thanks for your reply, but the code you have suggested is not working
ridoy at 24-Sep-12 8:18am
   
it works perfectly for me,need to see what is your condition..because it depends on it's type
Prafulla Sahu at 24-Sep-12 8:39am
   
I am just checking that a particular directory is present or not but I did it in Form1_Paint event but when I pressed my shortcut key the form should get activate but it is not activating.
ridoy at 24-Sep-12 8:51am
   
I'm not sure whether Form1_Paint method is correct to do it..but i think it will work in case of Form1_Load event.So it will be like..
 
if (Directory.Exists("C:\\Users"))
{
this.Show();
}
else
this.Close();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 mhegazy94 460
1 Sergey Alexandrovich Kryukov 450
2 Kornfeld Eliyahu Peter 305
3 Ravi Bhavnani 200
4 Shemeemsha RA 160
0 Sergey Alexandrovich Kryukov 6,890
1 OriginalGriff 6,761
2 CPallini 5,350
3 George Jonsson 3,609
4 Gihan Liyanage 2,797


Advertise | Privacy | Mobile
Web03 | 2.8.140922.1 | Last Updated 24 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100