home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161b.iso / handson / archive / Issue152 / delphi / copydelp.exe / D2Splitter / d2split.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-02-16  |  2.1 KB  |  70 lines

  1. unit d2split;
  2. { a simple way of implementing a vertical splitter in Delphi 2 }
  3.  
  4. interface
  5.  
  6.  
  7. uses
  8.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  9.   ExtCtrls, StdCtrls;
  10.  
  11. type
  12.   TForm1 = class(TForm)
  13.     Panel1: TPanel;
  14.     Memo1: TMemo;
  15.     Memo2: TMemo;
  16.     procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  17.       Shift: TShiftState; X, Y: Integer);
  18.   private
  19.     { Private declarations }
  20.   public
  21.     { Public declarations }
  22.   end;
  23.  
  24. const
  25.   MINWIDTH = 50;
  26.  
  27. var
  28.   Form1: TForm1;
  29.  
  30. implementation
  31.  
  32. {$R *.DFM}
  33.  
  34. procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  35.   Shift: TShiftState; X, Y: Integer);
  36. const
  37.   SC_DragMove = $F012; { a magic number }
  38. var
  39.   BottomMargin : integer;
  40. begin
  41.   Memo2.align := alNone; // turn off align during movement
  42.   Panel1.align := alNone;
  43.                        // resize panel so that the top and bottom edges
  44.                        // don't appear if the mouse is moved vertically
  45.   BottomMargin := Form1.ClientHeight - Y;
  46.   Panel1.Top := -BottomMargin;
  47.   Panel1.Height := Form1.ClientHeight * 2;
  48.   Form1.Update;        // update to ensure Memo contents are repainted
  49.   ReleaseCapture;
  50.                        // --- Move the splitter panel ---
  51.   panel1.perform(WM_SysCommand, SC_DragMove, 0);
  52.                        // some debugging text to show various coordinates
  53.   Caption := Format('Form1.ClientHeight=%d, Panel1.Top=%d, Panel1.Height=%d, Y=%d, BottomMargin=%d',
  54.        [Form1.ClientHeight, Panel1.Top, Panel1.Height, Y, BottomMargin]);
  55.                        // make sure Memos aren't resized beneath a minimum width
  56.   if Panel1.Left <= MINWIDTH then
  57.      Panel1.Left := MINWIDTH
  58.   else if (Form1.ClientWidth - (Panel1.Left + Panel1.Width)) <= MINWIDTH then
  59.      Panel1.Left := Form1.ClientWidth - (Panel1.Width+MINWIDTH);
  60.                        // restore default alignments
  61.   Memo1.Width := Panel1.Left;
  62.   panel1.align := alLeft;
  63.   Memo2.align := alClient;
  64.   Caption:= Format('Memo1.Width := %d, Memo2.Width = %d', [Memo1.Width, Memo2.Width] );
  65.  
  66. end;
  67.  
  68.  
  69. end.
  70.