Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Continuous button?

Continuous button?

Scheduled Pinned Locked Moved C#
question
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hostopolis
    wrote on last edited by
    #1

    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...

    C 1 Reply Last reply
    0
    • H hostopolis

      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...

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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 )

      H 1 Reply Last reply
      0
      • C Christian Graus

        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 )

        H Offline
        H Offline
        hostopolis
        wrote on last edited by
        #3

        Excellent! *rubbing hands together, with an evil grin on my face* Now, how do I do that?

        K 1 Reply Last reply
        0
        • H hostopolis

          Excellent! *rubbing hands together, with an evil grin on my face* Now, how do I do that?

          K Offline
          K Offline
          Kristian Sixhoj
          wrote on last edited by
          #4

          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"

          H 1 Reply Last reply
          0
          • K Kristian Sixhoj

            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"

            H Offline
            H Offline
            hostopolis
            wrote on last edited by
            #5

            There's no keyboard. This is for a touch screen.

            K A 2 Replies Last reply
            0
            • H hostopolis

              There's no keyboard. This is for a touch screen.

              K Offline
              K Offline
              Kristian Sixhoj
              wrote on last edited by
              #6

              Oh, okay :-D

              Virtual1ty


              "Any fool can learn from his own mistakes, but a wise man learns from mistakes of others"

              1 Reply Last reply
              0
              • H hostopolis

                There's no keyboard. This is for a touch screen.

                A Offline
                A Offline
                Andrew Rissing
                wrote on last edited by
                #7

                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);
                    }
                  }
                }
                
                H 1 Reply Last reply
                0
                • A Andrew Rissing

                  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);
                      }
                    }
                  }
                  
                  H Offline
                  H Offline
                  hostopolis
                  wrote on last edited by
                  #8

                  Yup...that will get me headed in the right direction. Thank you very much.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups