home *** CD-ROM | disk | FTP | other *** search
- unit d2split;
- { a simple way of implementing a vertical splitter in Delphi 2 }
-
- interface
-
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ExtCtrls, StdCtrls;
-
- type
- TForm1 = class(TForm)
- Panel1: TPanel;
- Memo1: TMemo;
- Memo2: TMemo;
- procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- const
- MINWIDTH = 50;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- const
- SC_DragMove = $F012; { a magic number }
- var
- BottomMargin : integer;
- begin
- Memo2.align := alNone; // turn off align during movement
- Panel1.align := alNone;
- // resize panel so that the top and bottom edges
- // don't appear if the mouse is moved vertically
- BottomMargin := Form1.ClientHeight - Y;
- Panel1.Top := -BottomMargin;
- Panel1.Height := Form1.ClientHeight * 2;
- Form1.Update; // update to ensure Memo contents are repainted
- ReleaseCapture;
- // --- Move the splitter panel ---
- panel1.perform(WM_SysCommand, SC_DragMove, 0);
- // some debugging text to show various coordinates
- Caption := Format('Form1.ClientHeight=%d, Panel1.Top=%d, Panel1.Height=%d, Y=%d, BottomMargin=%d',
- [Form1.ClientHeight, Panel1.Top, Panel1.Height, Y, BottomMargin]);
- // make sure Memos aren't resized beneath a minimum width
- if Panel1.Left <= MINWIDTH then
- Panel1.Left := MINWIDTH
- else if (Form1.ClientWidth - (Panel1.Left + Panel1.Width)) <= MINWIDTH then
- Panel1.Left := Form1.ClientWidth - (Panel1.Width+MINWIDTH);
- // restore default alignments
- Memo1.Width := Panel1.Left;
- panel1.align := alLeft;
- Memo2.align := alClient;
- Caption:= Format('Memo1.Width := %d, Memo2.Width = %d', [Memo1.Width, Memo2.Width] );
-
- end;
-
-
- end.
-