我有一个Windows应用程序,其中我有两个按钮用于在GridView中上下移动项目。按钮应该像滚动向上和向下
But the problem is:
click事件,当我松开按键只调用。当我按下
What I need:
click事件应激发和保持的关键,当我松开按键应该停止。意味着像上下滚动按钮。
我有一个Windows应用程序,其中我有两个按钮用于在GridView中上下移动项目。按钮应该像滚动向上和向下
But the problem is:
click事件,当我松开按键只调用。当我按下
What I need:
click事件应激发和保持的关键,当我松开按键应该停止。意味着像上下滚动按钮。
在按钮的MouseDown事件改变一些类级别成员例如
blnButtonPressed = ture;
在按钮改变
blnButtonPressed = false;
的MouseUp事件而你在这两种状态之间做什么都....
请勿使用click事件。使用MouseDown和MouseUp事件。或者,如果您想处理按键操作,请使用KeyDown和KeyUp事件。
但是我想在按下按键时做任务 – 2012-04-17 06:31:16
您可以创建自定义按钮,该按钮会在按下按钮时引发Click evens。这是简单的方法:
public class PressableButton : Button
{
private Timer _timer = new Timer() { Interval = 10 };
public PressableButton()
{
_timer.Tick += new EventHandler(Timer_Tick);
}
private void Timer_Tick(object sender, EventArgs e)
{
OnClick(EventArgs.Empty);
}
protected override void OnMouseDown(MouseEventArgs mevent)
{
base.OnMouseDown(mevent);
_timer.Start();
}
protected override void OnMouseUp(MouseEventArgs mevent)
{
base.OnMouseUp(mevent);
_timer.Stop();
}
}
按下按钮后,计时器每10毫秒开始计时(您可以更改间隔)。在计时器滴答事件处理程序中,此按钮引发Clieck事件。
要使用它只需编译项目并从工具箱中拖动PressedButton到您的窗体。
我应该在哪里执行任务之间..? – 2012-04-17 06:31:42
您可以为您的任务启动一个新线程,或者为您的任务开始后台工作,这可以帮助您了解http://msdn.microsoft.com/en-us/library/cc221403(v=vs.95).aspx – Adil 2012-04-17 06:40:46
谢谢..我为我工作... – 2012-04-17 07:23:00