Click here to Skip to main content
15,918,333 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Quote:
I use this code to make to print screen my screen, its working but my problem is when I minimize the application I can not use the shortcut key , any help?


private void button1_Click(object sender, EventArgs e)
        {
                       
            Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                                  Screen.PrimaryScreen.Bounds.Height);
            Graphics graphics = Graphics.FromImage(bitmap as Image);
            graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size);
            var date = DateTime.Now.ToString("MMddyyHmmss");
            bitmap.Save(@"C:\Users\Public\Pictures" + date + ".jpg");
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F12)
            {
                button1.PerformClick();
    
            }
        }


What I have tried:

I tried to change the shortcut to ctrl+k still the same problem.
Posted
Updated 4-Jun-20 18:35pm
v3

1 solution

You need to handle the key event from the global application level.
You may refer to this thread on stack overflow.
.net - Global keyboard capture in C# application - Stack Overflow[^]
 
Share this answer
 

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



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