Possible Duplicate:
Best way to implement keyboard shortcuts in winforms?
I have a probleme with KeyDown or KeyPress or KeyUp. I creat a new KeyDown for the form (private void Form1_KeyDown(object sender, KeyEventArgs e)
) where I insert this code:
if (e.KeyCode == Keys.A && e.Modifiers == Keys.Control)
MessageBox.Show("yes");
If you pess Ctrl + A will show you a MessageBox with Yes message.
The probleme is this: if I create a new project (Windows form application
) will work perfectly, but if I add the code in my Windows form application (have like 4201 code lines) will not work, and I don't know what is the issues. I don't know what are the issues in this case.
Maybe is becouse the librarys:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Web.Script.Serialization;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Runtime.InteropServices;
using System.Media;
using System.Diagnostics;
using Microsoft.Win32;
using System.Net.Mail;
using System.Net;
Or the code that I add in Program.cs for let the people start only once time the app:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
namespace Programari
{
static class Program
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
[return: System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
bool createdNew = true;
using (Mutex mutex = new Mutex(true, "MyApplicationName", out createdNew))
{
if (createdNew)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
else
{
Process current = Process.GetCurrentProcess();
if(Settings1.Default.rosaueng == 0)
MessageBox.Show("smartAppointment este deja deschis, ii gasesti iconita in System Icons !","EROARE DESCHIDERE APLICATIE");
else
MessageBox.Show("smartAppointment is already open, you can find him at System Icons !", "ERROR OPEN APPLICATION");
foreach (Process process in Process.GetProcessesByName(current.ProcessName))
{
if (process.Id != current.Id)
{
SetForegroundWindow(process.MainWindowHandle);
break;
}
}
}
}
}
}
}
If you know, please tell me. Thanks !