[C#]KeyEvent Problem

07/02/2012 21:09 Naworia#1
What is wrong about this script?
Code:
private void Form1_KeyDown(object sender, KeyEventArgs e)
        { 
            if (e.KeyData == Keys.F6)
            {
                MessageBox.Show("Succesful");
            }
        }
There is no error but when i pressed F6, happens nothing...
Note : Form KeyPreview = true
07/02/2012 21:13 ЙôČhěάŧĪмPĞM-hacked#2
IDK I work with vb.net 10
But google is your friend ;:)
07/02/2012 21:21 Naworia#3
I searched much time but i can't find my answer...
07/02/2012 21:29 ЙôČhěάŧĪмPĞM-hacked#4
You can change this program in c# in vb.net ?
Maybe I can help you ;)
07/02/2012 22:38 Naworia#5
sry i must do it for c#
07/03/2012 12:31 Kraizy​#6
PHP Code:
public Form1()
{
     
InitializeComponent();
     
this.KeyDown += new KeyEventHandler(OnKeyDown)
}

private 
void OnKeyDown(object senderKeyEventArgs e)
{
     if (
e.KeyData == Keys.F6)
     {
          
MessageBox.Show("abc");
     }

07/04/2012 01:32 ЙôČhěάŧĪмPĞM-hacked#7
Sorry but very small correction

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {}
            public Form1() 
{ 
     InitializeComponent(); 
     this.KeyDown += new KeyEventHandler(OnKeyDown);
} 

private void OnKeyDown(object sender, KeyEventArgs e) 
{ 
     if (e.KeyData == Keys.F6) 
     { 
          MessageBox.Show("abc"); 
     } 
} 
        }
    }
07/04/2012 14:30 MoepMeep#8
Quote:
Originally Posted by ЙôČhěάŧĪмPĞM-hacked View Post
Sorry but very small correction

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {}
            public Form1() 
{ 
     InitializeComponent(); 
     this.KeyDown += new KeyEventHandler(OnKeyDown);
} 

private void OnKeyDown(object sender, KeyEventArgs e) 
{ 
     if (e.KeyData == Keys.F6) 
     { 
          MessageBox.Show("abc"); 
     } 
} 
        }
    }
Great correction! 2 Constructors with the same name and an unused event, you must be an awesome coder! Not to mention you fucked up the formatting.
07/04/2012 14:49 boxxiebabee#9
Die Formatierung in Visual Studio zu versauen ist schon ne Kunst... ^^