Forum > LCL

Distinguish between a form resize through code and a user-initiated resize

<< < (2/3) > >>

trab10:
> jamie:

This is very educational.  I try to avoid going to the Windows SDK, but this definitely shows the value of doing so upon occasion.  It does exactly what I want in a single if-then statement (and about half a dozen additional units).

As you say, this is probably not very portable, but for this prog, it's fine.  I do like the portability of Handoko's solution, too, though it is a bit more involved.

Thank you both!

b

jamie:
Everything there is supposed to be cross platform with the exception of the missing defines, that is what the Windows unit is doing.

 The other added units are cross platform targeted.

I think the missing defines maybe an oversight because that same code is used throughout and hit testing is common.

Have fun.


KodeZwerg:
Crossplatform:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Memo1: TMemo;    Timer1: TTimer;    procedure Button1Click(Sender: TObject);    procedure FormCreate(Sender: TObject);    procedure FormResize(Sender: TObject);    procedure FormShow(Sender: TObject);    procedure Timer1Timer(Sender: TObject);  private    // this variable informs you if its executed by code    FResize: Boolean;  public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject);begin  // example how code must look to distinguish between user and code  // set code flag  FResize := True;  // resize and fire OnResize  Self.Width := 200 + Random(100);  // give messages a time to be processed  Timer1.Enabled := True;end; procedure TForm1.FormCreate(Sender: TObject);begin  // just used for Random() in example  Randomize;  // setup timer, 1000 is default (1 second)  Timer1.Interval := 1000; // can be tweaked down but a second is fairplay  // to swallow first event  Timer1.Enabled := True;end; procedure TForm1.FormResize(Sender: TObject);begin  // nothing much to say  if FResize then    Memo1.Lines.Add('Code resized')  else    Memo1.Lines.Add('User resized');end; procedure TForm1.FormShow(Sender: TObject);begin  // initialize to code  FResize := True;end; procedure TForm1.Timer1Timer(Sender: TObject);begin  // remove timer event  Timer1.Enabled := False;  // remove code flag  FResize := False;end; end.updated comments and fixed starting issue.

trab10:
>KodeZwerg:

This one gives me yet something else to think about.  The flag and timer approach is interesting, and it certainly does work.  Thanks for your help.

b

egsuh:
Doesn't following work?


   Self.OnResize := nil;

   // do your own resizing by program

   Self.OnResize := @FormResize;

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version