Click here to Skip to main content
15,912,082 members
Home / Discussions / C#
   

C#

 
GeneralRe: Registry Permissions Pin
Zach.Saunders29-Aug-11 9:04
Zach.Saunders29-Aug-11 9:04 
GeneralRe: Registry Permissions Pin
Anthony Mushrow29-Aug-11 9:24
professionalAnthony Mushrow29-Aug-11 9:24 
GeneralRe: Registry Permissions Pin
Zach.Saunders29-Aug-11 10:47
Zach.Saunders29-Aug-11 10:47 
QuestionC# Button Click - Press and Release Pin
asterix529-Aug-11 1:33
asterix529-Aug-11 1:33 
AnswerRe: C# Button Click - Press and Release Pin
Shameel29-Aug-11 2:02
professionalShameel29-Aug-11 2:02 
GeneralRe: C# Button Click - Press and Release Pin
asterix529-Aug-11 4:06
asterix529-Aug-11 4:06 
GeneralRe: C# Button Click - Press and Release Pin
Shameel29-Aug-11 5:42
professionalShameel29-Aug-11 5:42 
AnswerRe: C# Button Click - Press and Release PinPopular
Wayne Gaylard29-Aug-11 2:52
professionalWayne Gaylard29-Aug-11 2:52 
I would use a BackGroundWorker to handle the work while the button is pressed. I created a test app that adds the letter a to a textbox every second while the button is pressed, and stops when button is lifted. Here is the code for the form (assumes the form contains a button(button1) and a textbox(textBox1, with multiline set to true)). I am sure you can convert this to do what you require:

C#
bool isPressed = false;
        BackgroundWorker bgw = new BackgroundWorker();//declare form level worker

        public Form1()
        {
            InitializeComponent();
            button1.MouseDown += new MouseEventHandler(button1_MouseDown);//add mouse down event handler
            button1.MouseUp += new MouseEventHandler(button1_MouseUp);//add mouse up event handler
            bgw.DoWork+=new DoWorkEventHandler(bgw_DoWork);//add handler for bg worker Do Work
            bgw.WorkerSupportsCancellation = true;//ensure you can cancel bg worker
        }

        //This is where bg worker does it's thing
        void  bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            while (isPressed)
            {
                DoWork();//add a to textbox
                Thread.Sleep(1000);//sleep for a second
            }
        }

        void button1_MouseUp(object sender, MouseEventArgs e)
        {
            bgw.CancelAsync();//stop bg worker
            isPressed = false;//set isPressed to false for next time
        }

        void button1_MouseDown(object sender, MouseEventArgs e)
        {
            isPressed = true;//set trigger to true
            bgw.RunWorkerAsync();
        }

        //create delegate for multi task control update
        delegate void doWork();
        void DoWork()
        {
            if (this.InvokeRequired)
            {
                doWork d = new doWork(DoWork);
                this.Invoke(d);
            }
            else
            {
                this.textBox1.Text += "a";
            }
        }


Hope this helps
Live for today. Plan for tomorrow. Party tonight!

Question2D FFT / DFT + NxN Convolution (image processing) [SOLVED] [modified] Pin
Dusan Paulovic29-Aug-11 1:10
Dusan Paulovic29-Aug-11 1:10 
AnswerRe: 2D FFT / DFT + NxN Convolution (image processing) Pin
share_holder29-Aug-11 1:54
share_holder29-Aug-11 1:54 
GeneralRe: 2D FFT / DFT + NxN Convolution (image processing) Pin
Dusan Paulovic29-Aug-11 5:13
Dusan Paulovic29-Aug-11 5:13 
GeneralRe: 2D FFT / DFT + NxN Convolution (image processing) Pin
MicroVirus29-Aug-11 2:00
MicroVirus29-Aug-11 2:00 
GeneralRe: 2D FFT / DFT + NxN Convolution (image processing) Pin
Dusan Paulovic29-Aug-11 5:11
Dusan Paulovic29-Aug-11 5:11 
AnswerMessage Removed Pin
29-Aug-11 5:37
professionalN_tro_P29-Aug-11 5:37 
GeneralRe: 2D FFT / DFT + NxN Convolution (image processing) Pin
Dusan Paulovic29-Aug-11 7:10
Dusan Paulovic29-Aug-11 7:10 
GeneralMessage Removed Pin
29-Aug-11 7:32
professionalN_tro_P29-Aug-11 7:32 
GeneralRe: 2D FFT / DFT + NxN Convolution (image processing) [modified] Pin
Dusan Paulovic29-Aug-11 8:57
Dusan Paulovic29-Aug-11 8:57 
AnswerRe: 2D FFT / DFT + NxN Convolution (image processing) Pin
Chris Losinger29-Aug-11 7:14
professionalChris Losinger29-Aug-11 7:14 
GeneralRe: 2D FFT / DFT + NxN Convolution (image processing) Pin
Dusan Paulovic29-Aug-11 8:59
Dusan Paulovic29-Aug-11 8:59 
GeneralRe: 2D FFT / DFT + NxN Convolution (image processing) Pin
Chris Losinger29-Aug-11 9:04
professionalChris Losinger29-Aug-11 9:04 
GeneralRe: 2D FFT / DFT + NxN Convolution (image processing) Pin
Dusan Paulovic29-Aug-11 9:28
Dusan Paulovic29-Aug-11 9:28 
GeneralRe: 2D FFT / DFT + NxN Convolution (image processing) Pin
Chris Losinger29-Aug-11 9:38
professionalChris Losinger29-Aug-11 9:38 
QuestionUnmanaged memory issue [modified] Pin
c4tchm4tt29-Aug-11 0:10
c4tchm4tt29-Aug-11 0:10 
AnswerRe: Unmanaged memory issue Pin
MicroVirus29-Aug-11 1:51
MicroVirus29-Aug-11 1:51 
GeneralRe: Unmanaged memory issue Pin
c4tchm4tt1-Sep-11 5:04
c4tchm4tt1-Sep-11 5:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.