procedure TForm1.Button1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
form1.width := form1.width + 10;
end;
With this code, If a key is holded, the width of the form increases.
When I use the Mousedown event, this does not happen. The mouse button
has to be pressed
again. How should I solve this?
A clear example would be appreciated.
Thanks. Daniël
"Daniël Maartense" wrote:
> procedure TForm1.Button1MouseDown(Sender: TObject; Button:
> TMouseButton;
> Shift: TShiftState; X, Y: Integer);
> begin
> form1.width := form1.width + 10;
> end;
>
> procedure TForm1.Button1KeyDown(Sender: TObject; var Key: Word;
> Shift: TShiftState);
> begin
> form1.width := form1.width + 10;
> end;
>
> With this code, If a key is holded, the width of the form increases.
> When I use the Mousedown event, this does not happen. The mouse button
> has to be pressed
> again. How should I solve this?
I don't think you _should_ solve this. A keyboard has an auto-repeat
and a mouse traditionally doesn't - if the mouse has an auto-repeat
feature in your program it's going to confuse people.
..Oh, yes, this is frequently seen in Win apps. Think of the Scroll bar, something similar happens
when you drag outside the bounds of a listbox/listview, etc..
Here's an example from TNavButton used by the TDBNavigator:
procedure TNavButton.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
begin
inherited MouseDown (Button, Shift, X, Y);
if nsAllowTimer in FNavStyle then
begin
if FRepeatTimer = nil then
FRepeatTimer := TTimer.Create(Self);
FRepeatTimer.OnTimer := TimerExpired;
FRepeatTimer.Interval := InitRepeatPause;
FRepeatTimer.Enabled := True;
end;
end;
procedure TNavButton.TimerExpired(Sender: TObject);
begin
FRepeatTimer.Interval := RepeatPause;
if (FState = bsDown) and MouseCapture then
begin
try
Click;
except
FRepeatTimer.Enabled := False;
raise;
end;
end;
end;
...watch that you start off with a rather long delay (~0.5sec), while the delay is shortened to
somewhat 0.1 sec when repeating has started.
--
Bjoerge
I was very interested in your problem and decided to check it out. But
when I tried it it worked just fine both the keydown event and the mouse
down event. I mean in both cases the form widened and I didn't have to
press the mouse twice. I tried only a form, a button and your code.
That's all I can tell you for now.
Bye.
Daniėl Maartense <dmaar...@hotmail.com> wrote in message
news:37b68517...@news.demon.nl...
> procedure TForm1.Button1MouseDown(Sender: TObject; Button:
> TMouseButton;
> Shift: TShiftState; X, Y: Integer);
> begin
> form1.width := form1.width + 10;
> end;
>
> procedure TForm1.Button1KeyDown(Sender: TObject; var Key: Word;
> Shift: TShiftState);
> begin
> form1.width := form1.width + 10;
> end;
>
> With this code, If a key is holded, the width of the form increases.
> When I use the Mousedown event, this does not happen. The mouse button
> has to be pressed
> again. How should I solve this?
>
> A clear example would be appreciated.
>
> Thanks. Daniėl
>
To Krasimir:
I think the version of Delphi you are using must be different from
mine. I use Delphi 3 (Standard).
I think it is strange it does not work they way I expect it to work.
If I look at the help, there is an example where the action is
repeated, until the mouse button is released. So why shouldn't it in
my case:
The example:
Shift: TShiftState; X, Y: Integer);
begin
Canvas.TextOut(X, Y, 'Here!'); { write text at (X, Y) }
end;
Somebody there who can explain this? It beats me
may be you are right - I'm using Delphi 4. But since your next lines
puzzled me (the lines about repeating an action until mouse button is
released and the help example) I will ask you to tell me what exactly
you are trying to do and what's happening. Is that ok?
From your first letter, I gathered that you want a form to widen when a
key or a mouse button is pressed on a button. And the problem is that
you have to press the mouse button twice for the form to widen, right?
Then what's the connection of 'until a button is released and an example
in the help system'? Can you explain, please? Thanks. Regards.
"Bjørge Sæther" wrote:
> <<David C. Ullrich:
> Daniël Maartense" wrote:
> > procedure TForm1.Button1MouseDown(Sender: TObject; Button:
> > TMouseButton;
> > Shift: TShiftState; X, Y: Integer);
> > begin
> > form1.width := form1.width + 10;
> > end;
> >
> > procedure TForm1.Button1KeyDown(Sender: TObject; var Key: Word;
> > Shift: TShiftState);
> > begin
> > form1.width := form1.width + 10;
> > end;
> >
> > With this code, If a key is holded, the width of the form increases.
> > When I use the Mousedown event, this does not happen. The mouse button
> > has to be pressed
> > again. How should I solve this?
>
> I don't think you _should_ solve this. A keyboard has an auto-repeat
> and a mouse traditionally doesn't - if the mouse has an auto-repeat
> feature in your program it's going to confuse people.>>
>
> ..Oh, yes, this is frequently seen in Win apps. Think of the Scroll bar,
I lied, sorry.
> I don't think you _should_ solve this. A keyboard has an auto-repeat
>and a mouse traditionally doesn't - if the mouse has an auto-repeat
>feature in your program it's going to confuse people.
>
What, confused ? - all those people who adjust any numerical setting in MS
Word, Excel etc formats ? <g>
Alan Lloyd
alang...@aol.com