Re:Stuffing Keyboard From Listbox To Edit?
Quote
In article <6a31rg$j2...@forums.borland.com>, Andy Weed wrote:
> Can you cive me a few pointers on how to implement the above? Do I have to
> create a new listbox component or can I put the message handlers in the form
> that contains my edit control and listbox.
Andy,
if you want to have your listbox/edit combination perform as a unit from the
component users view both should be encapsulated into a single component and
that would indeed best be done with a derivative of TListbox that has handlers
for the messages i mentioned. For a quick&dirty solution one could tie a
normal TEdit and TListbox together with event handlers on the form level, but
it would be ugly stuff, something like this (untested!):
Function IsListboxKey(Key: Word): Boolean;
Begin
case Key Of
VK_UP, VK_DOWN, VK_HOME, VK_END, VK_PRIOR, VK_NEXT:
Result := True
Else
Result := False
End;
End;
//listbox OnKeyDown, OnKeyUp and OnKeyPress handlers:
Procedure TForm1.Listbox1KeyDown( Sender: TObject;
Var Key: Word; Shift: TShiftState );
Begin
If not ((Alt In Shift) or IsListboxKey(Key)) Then Begin
PostMessage( edit1.handle, WM_KEYDOWN, Key,
MakeLong( 0, MapVirtualkey( Key, 0)));
Key := 0;
End;
End;
Procedure TForm1.Listbox1KeyUp( Sender: TObject;
Var Key: Word; Shift: TShiftState );
Begin
If not ((Alt In Shift) or IsListboxKey(Key)) Then Begin
PostMessage( edit1.handle, WM_KEYDOWN, Key,
MakeLong( 1, MapVirtualkey( Key, 0) or $C000));
Key := 0;
End;
End;
Procedure TForm1.Listbox1KeyPress( Sender: TObject;
Var Key: Char; Shift: TShiftState );
Begin
If not (Alt In Shift) Then
Key := #0;
End;
Peter Below (TeamB) 100113.1...@compuserve.com)