Continuous button?
-
I have an app that moves a window left, right, up or down by clicking the appropriate button. At this time, I have to repetitively click the button to move it. How can I make the button continuous, so I only have to hold the button down, and it continues to move until I let off? In addition to that, I still want the ability to move it one click at a time, as well. I searched everywhere, but haven't found anything that gives me what I'm looking for. Thanks...
-
I have an app that moves a window left, right, up or down by clicking the appropriate button. At this time, I have to repetitively click the button to move it. How can I make the button continuous, so I only have to hold the button down, and it continues to move until I let off? In addition to that, I still want the ability to move it one click at a time, as well. I searched everywhere, but haven't found anything that gives me what I'm looking for. Thanks...
You need to override the button class, and you need to fire a timer when the mouse is down to generate click events.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
You need to override the button class, and you need to fire a timer when the mouse is down to generate click events.
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
Excellent! *rubbing hands together, with an evil grin on my face* Now, how do I do that?
-
Excellent! *rubbing hands together, with an evil grin on my face* Now, how do I do that?
You could also just do it the easy way: Click once on the button, and then keep holding down the Enter-key on your keyboard.
Virtual1ty
"Any fool can learn from his own mistakes, but a wise man learns from mistakes of others"
-
You could also just do it the easy way: Click once on the button, and then keep holding down the Enter-key on your keyboard.
Virtual1ty
"Any fool can learn from his own mistakes, but a wise man learns from mistakes of others"
There's no keyboard. This is for a touch screen.
-
There's no keyboard. This is for a touch screen.
Oh, okay :-D
Virtual1ty
"Any fool can learn from his own mistakes, but a wise man learns from mistakes of others"
-
There's no keyboard. This is for a touch screen.
I created a new windows form with a button and a rich text box. The following code produces the effect you want. Granted, you'll need to add more logic in there, but it should be enough to get your started:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); this.m_Timer = new Timer(); this.m_Timer.Interval = 100; this.m_Timer.Tick += new EventHandler(m_Timer_Tick); } private Timer m_Timer; private void button1_MouseDown(object sender, MouseEventArgs e) { // Kick off the timer to spawn the clicks. lock (this.m_Timer) { if (!this.m_Timer.Enabled) this.m_Timer.Start(); } } private void button1_MouseUp(object sender, MouseEventArgs e) { // Stop the timer. lock (this.m_Timer) { if (this.m_Timer.Enabled) this.m_Timer.Stop(); } } private void button1_Click(object sender, EventArgs e) { this.richTextBox1.Text += string.Format("Clicked - {0}{1}", DateTime.Now.ToLongTimeString(), Environment.NewLine); } private void m_Timer_Tick(object sender, EventArgs e) { this.button1_Click(this.button1, EventArgs.Empty); } } }
-
I created a new windows form with a button and a rich text box. The following code produces the effect you want. Granted, you'll need to add more logic in there, but it should be enough to get your started:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); this.m_Timer = new Timer(); this.m_Timer.Interval = 100; this.m_Timer.Tick += new EventHandler(m_Timer_Tick); } private Timer m_Timer; private void button1_MouseDown(object sender, MouseEventArgs e) { // Kick off the timer to spawn the clicks. lock (this.m_Timer) { if (!this.m_Timer.Enabled) this.m_Timer.Start(); } } private void button1_MouseUp(object sender, MouseEventArgs e) { // Stop the timer. lock (this.m_Timer) { if (this.m_Timer.Enabled) this.m_Timer.Stop(); } } private void button1_Click(object sender, EventArgs e) { this.richTextBox1.Text += string.Format("Clicked - {0}{1}", DateTime.Now.ToLongTimeString(), Environment.NewLine); } private void m_Timer_Tick(object sender, EventArgs e) { this.button1_Click(this.button1, EventArgs.Empty); } } }
Yup...that will get me headed in the right direction. Thank you very much.