Board index » cppbuilder » Repeat mouseDown event while mouse button is down

Repeat mouseDown event while mouse button is down

Hi
I have a SpeedButton and I want to update a value in a TStringGrid
when user push left mouse button on it. Ok... this is simple ;-)
 I write SpeedButton OnMouseDown event.
But I want to update continuously this value while user push left
mouse button and stop update when user release the button.

How can I do this?
THANKS a lot :-)

 

Re:Repeat mouseDown event while mouse button is down


What about starting a thread in the onmousedown event and terminating the
thread in the onmouseup event.

Kind regards,
De Bodt Lieven

Quote
"Calippofrizz" <calippofr...@hotmail.com> wrote in message

news:3bc7f29b.3736881@news.libero.it...
Quote
> Hi
> I have a SpeedButton and I want to update a value in a TStringGrid
> when user push left mouse button on it. Ok... this is simple ;-)
>  I write SpeedButton OnMouseDown event.
> But I want to update continuously this value while user push left
> mouse button and stop update when user release the button.

> How can I do this?
> THANKS a lot :-)

Re:Repeat mouseDown event while mouse button is down


can you explain me how to do please :-)
thanks
Quote
>What about starting a thread in the onmousedown event and terminating the
>thread in the onmouseup event.

>Kind regards,
>De Bodt Lieven

>"Calippofrizz" <calippofr...@hotmail.com> wrote in message
>news:3bc7f29b.3736881@news.libero.it...
>> Hi
>> I have a SpeedButton and I want to update a value in a TStringGrid
>> when user push left mouse button on it. Ok... this is simple ;-)
>>  I write SpeedButton OnMouseDown event.
>> But I want to update continuously this value while user push left
>> mouse button and stop update when user release the button.

>> How can I do this?
>> THANKS a lot :-)

Re:Repeat mouseDown event while mouse button is down


Hello,

An example:

//-- in the form source file --//

TThreadForm *ThreadForm;
TMyThread* Thread;

__fastcall TThreadForm::TThreadForm(TComponent* ) : TForm(Owner)
{
   Thread = new TMyThread(true);
   if(!Thread)
   {
      ShowMessage("Error! Cannot create thread.");
      Application->Terminate();
   }

Quote
}

void __fastcall TThreadForm::ButtonMouseDown(TObject *Sender, TMouseButton
Button, TShiftState Shift, int X, int Y)
{
   Thread->Resume();

Quote
}

void __fastcall TThreadForm::ButtonMouseUp(TObject *Sender, TMouseButton
Button, TShiftState Shift, int X, int Y)
{
   Thread->Terminate();

Quote
}

//-- in the thread source file --//

__fastcall TMyThread::TMyThread(bool CreateSuspended) :
TThread(CreateSuspended)
{
   // the thread constructor, do any initialising here

Quote
}

void __fastcall TRandomThread::Execute()
{
   FreeOnTerminate = true;
   if (Terminated)
      break;

         // access mainform with synchronize to do any actions on the vcl in
the main thread
        Synchronize(Label1->Caption = "Updated");
         // or use lock and unlock to draw on the screen
   }

Quote
}

Kind regards,
De Bodt Lieven
Quote
"Calippofrizz" <calippofr...@hotmail.com> wrote in message

news:3bcb3206.1987967@news.libero.it...
Quote
> can you explain me how to do please :-)
> thanks

> >What about starting a thread in the onmousedown event and terminating the
> >thread in the onmouseup event.

> >Kind regards,
> >De Bodt Lieven

> >"Calippofrizz" <calippofr...@hotmail.com> wrote in message
> >news:3bc7f29b.3736881@news.libero.it...
> >> Hi
> >> I have a SpeedButton and I want to update a value in a TStringGrid
> >> when user push left mouse button on it. Ok... this is simple ;-)
> >>  I write SpeedButton OnMouseDown event.
> >> But I want to update continuously this value while user push left
> >> mouse button and stop update when user release the button.

> >> How can I do this?
> >> THANKS a lot :-)

Re:Repeat mouseDown event while mouse button is down


Hi
I have a SpeedButton and I want to update a value in a TStringGrid
when user push left mouse button on it. Ok... this is simple ;-)
 I write SpeedButton OnMouseDown event.
But I want to update continuously this value while user push left
mouse button and stop update when user release the button.

De Bodt Lieven told me to try with THREAD:

Quote
>What about starting a thread in the onmousedown event and terminating the
>thread in the onmouseup event.
>Kind regards,
>De Bodt Lieven

How can I do this?
THANKS a lot :-)

Other Threads