Is there a TPanel substitute that responds to key events? lazarus / 21-General ---------------------------------------------------------------------- vfclists · 2024-10-03 14:16 Is there a TPanel substitute that responds to key events, or do such container components have to avoid reacting to keystrokes as a matter of design? I assume responding to key events might stop the controls contained from receiving them. If not can a similar panel be subclassed from TPanel's ancestors which can be designed intercept a specified set of keyboard events design time or runtime? ---------------------------------------------------------------------- mas steindorff · 2024-10-03 19:59 there is not much a panel can do with a key. it can't display it unless you are changing it's caption.  therefore the keypress are pass on to it's parent. Tabs and enter key operations that move from component to component and global key operation are handled at the form/frame level where you can modify or add stuff and/or menus hooks. what is your goal? ---------------------------------------------------------------------- vfclists · 2024-10-03 22:48 Quote from: mas steindorff on October 03, 2024, 09:59:59 pmthere is not much a panel can do with a key. it can't display it unless you are changing it's caption.  therefore the keypress are pass on to it's parent. Tabs and enter key operations that move from component to component and global key operation are handled at the form/frame level where you can modify or add stuff and/or menus hooks. what is your goal? This post gives the general idea https://forum.lazarus.freepascal.org/index.php/topic,68642.0.html I want to design a fully keystroke driven window navigation and control environment, with an intent to make it all tiled eventually, and I need container components like panels which are designed to respond to certain key combinations automatically. The container panels are supposed to follow standardized resizing (width and height), repositioning, hiding and restoring keystrokes. To implement the key stroke event handling at development time in code will be too onerous. It should all be built-in with properties to disable or enable some of these events when required. I find using the mouse when it comes to navigating and resizing containers in programs rather awkward and inefficient and unpredictable. Speaking as an Emacs and EXWM user who has seen the light. Another thing I'd like to do for instance would be to use the keyboard to hide, widen and move around the columns of a grid. Being able to do that with a keyboard would be a boon. ---------------------------------------------------------------------- mas steindorff · 2024-10-03 23:06 that sounds great!  I too prefer the keyboard over the mouse.  the TStringgrid and other grid objects do have OnKey... properties you may be able to use to this end. IIRC there are some grid examples included with the standard install under lazarus/examples/... I seem to remember 10+ years ago it had a keyboard Colum resize example but I could not tell you it's name. it also has number and text cell editing examples. resizing via the keyboard strike me as a good thing as excel forces resizing with a mouse drag at the time. ---------------------------------------------------------------------- Hansvb · 2024-10-04 13:20 Making a StringGrid column larger or smaller using keys is not that difficult. See below. Click in a cell and then ALT+E makes the column larger. ALT + C makes the column smaller. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit FormMain; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Grids; type   { TFrmMain }   TFrmMain = class(TForm)    sgFrmMain: TStringGrid;    procedure sgFrmMainKeyDown(Sender: TObject; var Key: Word;      Shift: TShiftState);  private  public   end; var  FrmMain: TFrmMain; implementation {$R *.lfm} { TFrmMain } procedure TFrmMain.sgFrmMainKeyDown(Sender: TObject; var Key: Word;  Shift: TShiftState);var  aCol: Integer;begin  aCol:= TStringGrid(Sender).Col;   if Shift = [ssAlt] then begin    case Key of      $45: begin // $45 = VK_E --> (E)xpand cell        sgFrmMain.ColWidths[aCol] := sgFrmMain.ColWidths[aCol] + 5;      end;      $43: begin  // $43 - VK_C --> (C)ollapse cell        if sgFrmMain.ColWidths[aCol] > 5 then          sgFrmMain.ColWidths[aCol] := sgFrmMain.ColWidths[aCol] - 5;      end;    end;  end;end; end. ---------------------------------------------------------------------- vfclists · 2024-10-04 21:24 Quote from: Hansvb on October 04, 2024, 03:20:00 pmMaking a StringGrid column larger or smaller using keys is not that difficult. See below. Click in a cell and then ALT+E makes the column larger. ALT + C makes the column smaller. 88 I'd prefer to build that kind of functionality into the component itself or else I would have to set it for every instance of the component. ---------------------------------------------------------------------- Sieben · 2024-10-04 21:47 TPanel is a descendant of TWinControl and should have all it's keyboard events available in a descendant of your own. It's just that the standard TPanel doesn't expose them.