Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
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
Updated 24-Sep-12 2:09am
v2
Comments
Andrei Straut 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 24-Sep-12 7:50am    
Ah! I could have given you +5 for this tip. :thumbsup:
Andrei Straut 24-Sep-12 7:53am    
Keep it reserved, I'll let you know when I need an upvote in the forums :))
_Amy 24-Sep-12 8:03am    
Sure. It is kept in CP reserve bank. :)
Prafulla Sahu 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.

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
C#
if(your conditions)
{
    this.hide();
} 
else
{
    this.show(); //or this.visibility = true;
}
 
Share this answer
 
v2
Comments
Andrei Straut 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.
In you form load event..
C#
private void Form1_Load(object sender, EventArgs e)
{
    if (your_condition == false)
        this.Show();
    else
        this.Close();
}
 
Share this answer
 
v2
Comments
Prafulla Sahu 24-Sep-12 8:15am    
hey ridoy thanks for your reply, but the code you have suggested is not working
ridoy 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 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 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
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900