Link to home
Start Free TrialLog in
Avatar of joyrider
joyrider

asked on

disable check/combo boxes losing focus in frames on key up / down

Hi,

i got this form with a frame in it and i use it to let it scroll in 3 times so it seems like it's a new page everytime.
anyway if one uses the mouse only everything works fine
but if u select one checkbox and the press the up or down key the next / previous control gets focus and this is irritating since it messes with my scrolling
so i want to know how i can disable this.

I noticed there's no onkey down on frames, i tried onkeydown on each control in the frame and setting key to 0 didn't work
setted also the tabstops to false didn't work either

got any idea's ? thanks
ASKER CERTIFIED SOLUTION
Avatar of freshman3k
freshman3k

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of freshman3k
freshman3k

Hello!

I assumed that the name of your Scroll Box was ScrollBox1 so you could replace everywhere with your Scroll Box name

The Following should work:

private
    { Private declarations }
    procedure OnMessage(var Msg: tagMSG; var Handled: Boolean);
  public
    { Public declarations }
  end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnMessage := OnMessage;
end;

procedure TForm1.OnMessage(var Msg: tagMSG; var Handled: Boolean);
var
  hi,vi,hp,vp: Integer;
begin
 if (Msg.message= WM_KEYDOWN) and
    (Msg.wParam=VK_LEFT or Msg.wParam=VK_UP or
    Msg.wParam=VK_RIGHT or Msg.wParam=VK_DOWN) then begin
 
   hi:=ScrollBox1.HorzScrollBar.Increment;
   vi:=ScrollBox1.VertScrollBar.Increment;
   hp:=ScrollBox1.HorzScrollBar.Position;
   vp:=ScrollBox1.VertScrollBar.Position;
   Handled:=True;
 
   if Msg.wParam=VK_LEFT then begin
   ScrollBox1.HorzScrollBar.Position=hp-hi;  end;
   if Msg.wParam=VK_UP then begin
   ScrollBox1.VertScrollBar.Position=vp-vi;  end;
   if Msg.wParam=VK_RIGHT then begin
   ScrollBox1.HorzScrollBar.Position=hp+hi;  end;
   if Msg.wParam=VK_DOWN then begin
   ScrollBox1.VertScrollBar.Position=vp+vi;
     end;  
  end
  else begin
  Handled:=False;
  end;
end;

Took me about 3 hours  :(

Good Luck!
Hello!

I assumed that the name of your Scroll Box was ScrollBox1 so you could replace everywhere with your Scroll Box name

The Following should work:

private
    { Private declarations }
    procedure OnMessage(var Msg: tagMSG; var Handled: Boolean);
  public
    { Public declarations }
  end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnMessage := OnMessage;
end;

procedure TForm1.OnMessage(var Msg: tagMSG; var Handled: Boolean);
var
  hi,vi,hp,vp: Integer;
begin
 if (Msg.message= WM_KEYDOWN) and
    (Msg.wParam=VK_LEFT or Msg.wParam=VK_UP or
    Msg.wParam=VK_RIGHT or Msg.wParam=VK_DOWN) then begin
 
   hi:=ScrollBox1.HorzScrollBar.Increment;
   vi:=ScrollBox1.VertScrollBar.Increment;
   hp:=ScrollBox1.HorzScrollBar.Position;
   vp:=ScrollBox1.VertScrollBar.Position;
   Handled:=True;
 
   if Msg.wParam=VK_LEFT then begin
   ScrollBox1.HorzScrollBar.Position=hp-hi;  end;
   if Msg.wParam=VK_UP then begin
   ScrollBox1.VertScrollBar.Position=vp-vi;  end;
   if Msg.wParam=VK_RIGHT then begin
   ScrollBox1.HorzScrollBar.Position=hp+hi;  end;
   if Msg.wParam=VK_DOWN then begin
   ScrollBox1.VertScrollBar.Position=vp+vi;
     end;  
  end
  else begin
  Handled:=False;
  end;
end;

Took me about 3 hours  :(

Good Luck!
Avatar of joyrider

ASKER

i'm goana tried it out immeadiatly =)
Works like a charm !