// Es werden zur Laufzeit 8 Makierungspunkte erzeugt (ähnlich wie
//
zur Entwicklungszeit). Durch Anfassen der Punkte kann das
// entsprechende Control in der Größe geändert werden.



// Getestet mit D4 unter XP

unit Unit1; 
 
interface 
 
uses 
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 
  ExtCtrls, StdCtrls; 
 
type 
  TForm1 = class(TForm) 
    Button1: TButton; 
    Panel1: TPanel; 
    Button2: TButton; 
    procedure FormCreate(Sender: TObject); 
    procedure Button1Click(Sender: TObject); 
    procedure FormDestroy(Sender: TObject); 
    procedure Button2Click(Sender: TObject); 
  private 
    procedure MyMouseDown(Sender: TObject; Button: TMouseButton; 
      Shift: TShiftState; X, Y: Integer); 
    procedure MyMouseMove(Sender: TObject; Shift: TShiftState; X, 
      Y: Integer); 
    procedure MyMouseUp(Sender: TObject; Button: TMouseButton; 
      Shift: TShiftState; X, Y: Integer); 
  public 
    procedure zeigen(tc: TControl); 
    procedure sichtbar(wie: boolean); 
    procedure festlegen(tco: TControl); 
    procedure verschieben(Punkt: TStaticText; wie: integer); 
  end; 
 
var 
  Form1: TForm1; 
 
implementation 
 
{$R *.DFM} 
 
var 
  sta: array[0..7] of TStaticText; 
  thisControl: TControl; 
  diffw, diffs: integer; 
  isdown: boolean = false; 
 
procedure TForm1.FormCreate(Sender: TObject); 
var x: integer; 
begin 
  // hier evtl. andere Objekte erstellen 
 
  for x := 0 to high(sta) do begin 
    sta[x] := TStaticText.create(self); 
    sta[x].parent := self; 
    sta[x].color := clBlack; 
    sta[x].tag := x; 
    sta[x].OnMouseDown := MyMouseDown; 
    sta[x].OnMouseMove := MyMouseMove; 
    sta[x].OnMouseUp := MyMouseUp; 
    case x of 
      0, 5: sta[x].cursor := crSizeNWSE; 
      1, 3: sta[x].cursor := crSizeNESW; 
      2, 4: sta[x].cursor := crSizeNS; 
      6, 7: sta[x].cursor := crSizeWE; 
    end; 
  end; 
  sichtbar(false); 
end; 
 
procedure TForm1.FormDestroy(Sender: TObject); 
var x: integer; 
begin 
  for x := 0 to high(sta) do sta[x].free; 
end; 
 
procedure TForm1.festlegen(tco: TControl); 
var p: TPoint; 
begin 
  getcursorpos(p); 
  diffw := p.x - tcontrol(tco).left; 
  diffs := p.y - tcontrol(tco).top; 
  isdown := true; 
end; 
 
procedure TForm1.verschieben(Punkt: TStaticText; wie: integer); 
var p: TPoint; 
  w, s, m, m2, ht, hh, hl, hw: integer; 
  procedure prfs; 
  begin 
    ht := Punkt.top + 2; 
    hh := thisControl.height - ht + m; 
    if (hh <= 11) and (s + 2 > m) then begin 
      hh := 11; 
      ht := thisControl.boundsrect.bottom - 11; 
      s := ht - 2; 
    end; 
    thisControl.top := ht; 
    thisControl.height := hh; 
  end; 
  procedure prfw; 
  begin 
    hl := Punkt.left + 2; 
    hw := thisControl.width - hl + m2; 
    if (hw <= 11) and (w + 2 > m2) then begin 
      hl := thisControl.boundsrect.right - 11; 
      hw := 11; 
      w := hl - 2; 
    end; 
    thisControl.left := hl; 
    thisControl.width := hw; 
  end; 
  procedure prfr; 
  begin 
    hw := Punkt.left + 3 - thisControl.left; 
    if (hw <= 11) and (w < thisControl.left + 8) then begin 
      hw := 11; 
      w := thisControl.left + 8; 
    end; 
    thisControl.width := hw; 
  end; 
  procedure prfu; 
  begin 
    hh := Punkt.top + 3 - thisControl.top; 
    if (hh <= 11) and (s < thisControl.top + 8) then begin 
      hh := 11; 
      s := thisControl.top + 8; 
    end; 
    thisControl.height := hh; 
  end; 
begin 
  if isdown then begin 
    getcursorpos(p); 
    case wie of 
      6: begin 
          m2 := thisControl.left; 
          w := p.x - diffw; 
          s := Punkt.top; 
          prfw; 
          sta[0].left := w; 
          sta[3].left := w; 
          sta[2].left := w + (sta[1].left - w) div 2; 
          sta[4].left := sta[2].left; 
        end; 
      7: begin 
          w := p.x - diffw; 
          s := Punkt.top; 
          prfr; 
          sta[2].left := w + (sta[0].left - w) div 2; 
          sta[1].left := w; 
          sta[4].left := sta[2].left; 
          sta[5].left := sta[1].left; 
        end; 
      4: begin 
          s := p.y - diffs; 
          w := Punkt.left; 
          prfu; 
          sta[3].top := s; 
          sta[5].top := s; 
          sta[6].top := sta[0].top + (s - sta[0].top) div 2; 
          sta[7].top := sta[6].top; 
        end; 
      2: begin 
          m := thisControl.top; 
          s := p.y - diffs; 
          w := Punkt.left; 
          prfs; 
          sta[0].top := s; 
          sta[1].top := s; 
          sta[6].top := sta[0].top + (sta[3].top - sta[0].top) div 2; 
          sta[7].top := sta[6].top; 
        end; 
      0: begin 
          m := thisControl.top; 
          m2 := thisControl.left; 
          s := p.y - diffs; 
          w := p.x - diffw; 
          prfw; 
          prfs; 
          sta[2].top := s; 
          sta[1].top := s; 
          sta[6].left := w; 
          sta[3].left := w; 
          sta[6].top := s + (sta[3].top - s) div 2; 
          sta[7].top := sta[6].top; 
          sta[2].left := w + (sta[1].left - w) div 2; 
          sta[4].left := sta[2].left; 
        end; 
      3: begin 
          m := thisControl.top; 
          m2 := thisControl.left; 
          s := p.y - diffs; 
          w := p.x - diffw; 
          prfw; 
          prfu; 
          sta[4].top := s; 
          sta[5].top := s; 
          sta[0].left := w; 
          sta[6].left := w; 
          sta[4].left := w + (sta[1].left - w) div 2; 
          sta[2].left := sta[4].left; 
          sta[6].top := s + (sta[0].top - s) div 2; 
          sta[7].top := sta[6].top; 
        end; 
      1: begin 
          m := thisControl.top; 
          s := p.y - diffs; 
          w := p.x - diffw; 
          prfs; 
          prfr; 
          sta[0].top := s; 
          sta[2].top := s; 
          sta[7].left := w; 
          sta[5].left := w; 
          sta[6].top := s + (sta[3].top - s) div 2; 
          sta[7].top := sta[6].top; 
          sta[2].left := w + (sta[0].left - w) div 2; 
          sta[4].left := sta[2].left; 
        end; 
    else begin 
        m := thisControl.top; 
        m2 := thisControl.left; 
        s := p.y - diffs; 
        w := p.x - diffw; 
        prfr; 
        prfu; 
        sta[3].top := s; 
        sta[4].top := s; 
        sta[1].left := w; 
        sta[7].left := w; 
        sta[2].left := sta[3].left + (w - sta[3].left) div 2; 
        sta[4].left := sta[2].left; 
        sta[6].top := sta[0].top + (s - sta[1].top) div 2; 
        sta[7].top := sta[6].top; 
      end; 
    end; 
    Punkt.setbounds(w, s, Punkt.width, Punkt.height); 
  end; 
end; 
 
procedure TForm1.sichtbar(wie: boolean); 
var x: integer; 
begin 
  for x := 0 to high(sta) do sta[x].visible := wie; 
end; 
 
procedure TForm1.zeigen(tc: TControl); 
begin 
  thisControl := tc; 
  sta[0].setbounds(tc.boundsrect.left - 2, tc.boundsrect.top - 2, 5, 5); 
  sta[1].setbounds(tc.boundsrect.right - 3, tc.boundsrect.top - 2, 5, 5); 
  sta[2].setbounds(tc.left - 2 + (sta[1].left - sta[0].left) div 2, 
    tc.boundsrect.top - 2, 5, 5); 
  sta[3].setbounds(sta[0].left, tc.boundsrect.bottom - 3, 5, 5); 
  sta[4].setbounds(sta[2].left, tc.boundsrect.bottom - 3, 5, 5); 
  sta[5].setbounds(sta[1].left, tc.boundsrect.bottom - 3, 5, 5); 
  sta[6].setbounds(sta[0].left, tc.top - 2 + 
    (sta[3].top - sta[0].top) div 2, 5, 5); 
  sta[7].setbounds(sta[1].left, sta[6].top, 5, 5); 
  sichtbar(thisControl.enabled and thisControl.visible); 
end; 
 
procedure TForm1.MyMouseDown(Sender: TObject; Button: TMouseButton; 
  Shift: TShiftState; X, Y: Integer); 
begin 
  if button = mbleft then festlegen(TControl(sender)); 
end; 
 
procedure TForm1.MyMouseMove(Sender: TObject; Shift: TShiftState; X, 
  Y: Integer); 
begin 
  verschieben(TStaticText(sender), TControl(sender).tag); 
end; 
 
procedure TForm1.MyMouseUp(Sender: TObject; Button: TMouseButton; 
  Shift: TShiftState; X, Y: Integer); 
begin 
  isdown := false; 
end; 
 
 
 
// Beispiel 
 
procedure TForm1.Button1Click(Sender: TObject); 
begin 
  zeigen(Panel1); 
end; 
 
 
procedure TForm1.Button2Click(Sender: TObject); 
begin 
  sichtbar(false); 
end; 
 
end.



 

Zugriffe seit 6.9.2001 auf Delphi-Ecke