做个打字游戏 如果连续输出正确则 连击++;但是就是不会判断 下面是按下事件
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
kysdown++;//记录按下
Keys s = e.KeyCode;
foreach (Control c in this.panel1.Controls)//便利出lable
{ if (c.Text == s.ToString())
{
zheng++;//如果相等则正确计数
this.lblzheng.Text = "正确:" + zheng.ToString();
timer2.Start();
tmrG.Start();
this.panel2.Controls.Clear();
}如果给后面打上else{ 在这里判断} 根本不行···如果正确 lianji++ 否则 lianji=0;这个否则该往哪里写? 注意些在这段代码后面根本不行!
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
kysdown++;//记录按下
Keys s = e.KeyCode;
foreach (Control c in this.panel1.Controls)//便利出lable
{ if (c.Text == s.ToString())
{
zheng++;//如果相等则正确计数
this.lblzheng.Text = "正确:" + zheng.ToString();
timer2.Start();
tmrG.Start();
this.panel2.Controls.Clear();
}如果给后面打上else{ 在这里判断} 根本不行···如果正确 lianji++ 否则 lianji=0;这个否则该往哪里写? 注意些在这段代码后面根本不行!
解决方案 »
- 高分求助AJAX 的 AutoCompleteExtender控件使用示例(与数据库联动)要求不用Webservice
- 请问 Form.showdialog(owner) 发放在多线程里怎么用?
- 关于跨线程调用
- visual studio 2005 DataGridView CellClick的问题
- vs2010如何在iis上发布网站
- 如何在httpHead 中添加值?
- 求:一条语句改写!
- 怎么使用枚举成员的常数值访问枚举成员
- 有那位大哥知道怎么让有两个窗体时只能点击其中一个?
- 如何在C3里屏蔽掉鼠标右键?
- 【我就这点分了——帮小菜鸟飞一下吧】我想应该是theCommand_.ExecuteNonQuery();怎么关闭的问题!
- 支持退格的把输入的符号变成*号的程序怎么写?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} IntPtr CurrHook; //得到钩子句柄
[DllImport("kernel32.dll")]
public static extern int GetCurrentThreadId(); //得到线程ID [DllImport("user32.dll")]
//--------开始装钩子HookType:钩子类型,backCall:回调委托,MyNull:当前实例句柄,ThreadId:线程ID
public static extern IntPtr SetWindowsHookEx(int HookType, KeyBackCall backCall, IntPtr MyNull, int ThreadId); [DllImport("user32.dll")]
public static extern IntPtr CallNextHookEx(IntPtr CurrHook, int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll")]
public static extern void UnhookWindowsHookEx(IntPtr CurrHook); //----回调的委托
public delegate IntPtr KeyBackCall(int nCode, IntPtr wParam, IntPtr lParam); //--------委托事件
public IntPtr KeyBackCallEvent(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode > 0)
{
MessageBox.Show(wParam.ToString());
return CallNextHookEx(CurrHook, nCode, wParam, lParam);
}
return CallNextHookEx(CurrHook, nCode, wParam, lParam);
}
private void button1_Click(object sender, EventArgs e)
{
CurrHook = SetWindowsHookEx(2, new KeyBackCall(KeyBackCallEvent), IntPtr.Zero, GetCurrentThreadId());
} private void button2_Click(object sender, EventArgs e)
{
UnhookWindowsHookEx(CurrHook); }
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} IntPtr CurrHook; //得到钩子句柄
[DllImport("kernel32.dll")]
public static extern int GetCurrentThreadId(); //得到线程ID [DllImport("user32.dll")]
//--------开始装钩子HookType:钩子类型,backCall:回调委托,MyNull:当前实例句柄,ThreadId:线程ID
public static extern IntPtr SetWindowsHookEx(int HookType, KeyBackCall backCall, IntPtr MyNull, int ThreadId); [DllImport("user32.dll")]
public static extern IntPtr CallNextHookEx(IntPtr CurrHook, int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll")]
public static extern void UnhookWindowsHookEx(IntPtr CurrHook);
//----回调的委托
public delegate IntPtr KeyBackCall(int nCode, IntPtr wParam, IntPtr lParam); //--------委托事件
public IntPtr KeyBackCallEvent(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode > 0)
{
MessageBox.Show(wParam.ToString());//这里得到字符asc码
return CallNextHookEx(CurrHook, nCode, wParam, lParam);
}
return CallNextHookEx(CurrHook, nCode, wParam, lParam);
}
private void button1_Click(object sender, EventArgs e)
{
CurrHook = SetWindowsHookEx(2, new KeyBackCall(KeyBackCallEvent), IntPtr.Zero, GetCurrentThreadId()); }
private void button2_Click(object sender, EventArgs e)
{
UnhookWindowsHookEx(CurrHook); }
}
}