Recent

Author Topic: Multiline TButton example  (Read 2552 times)

Ten_Mile_Hike

  • Jr. Member
  • **
  • Posts: 95
Multiline TButton example
« on: April 14, 2024, 11:18:26 pm »
Here is a working example of changing a TButton between single line and multi-line.
All you need is a form with a TButton and a Scrollbar (min=0  max=1)
Sorry for the non-standard formatting. Also; I am only a hobbyist and this
technique may be scorned by the experts here... Oh well!

Code: Pascal  [Select][+][-]
  1. Procedure TForm1.Multiline(H:HWND);
  2. var
  3.  Style: DWORD;                  
  4. begin
  5.   Style := GetWindowLongPtr(H, GWL_STYLE);
  6.   if Boolean(ScrollBar1.Position)
  7.      then Style := Style or BS_MULTILINE
  8.      else Style := Style and not BS_MULTILINE;
  9.   SetWindowLongPtr(H, GWL_STYLE, Style);
  10.   Button1.SetFocus;                
  11. end;
  12.  
  13. Procedure TForm1.Button1Click(Sender:TObject);
  14. var
  15.  x:integer;
  16.  Tot:integer=0;
  17.  T:integer=0;
  18.  S:String='';
  19. begin
  20.   Multiline(Button1.Handle);
  21.   For x:= 0 to 7 do
  22.   Begin
  23.     Tot:=Tot+Round(intpower(2,x));;
  24.     S:=S+inttostr(T) + '  ';
  25.   end;
  26.   Button1.Caption:=S + #10 + '=' + inttostr(Tot);
  27. end;
When any government, or any church for that matter, undertakes to say to its subjects, This you may not read, this you
must not see, this you are forbidden to know, the end result is tyranny and oppression no matter how holy the motives.

Robert A. Heinlein

 

TinyPortal © 2005-2018