Einzelnen Beitrag anzeigen

Benutzerbild von sirius
sirius

Registriert seit: 3. Jan 2007
Ort: Dresden
3.443 Beiträge
 
Delphi 7 Enterprise
 
#18

Re: Selected = False wenn Click außerhalb Komponente

  Alt 16. Feb 2007, 13:37
Also, ich bin jetzt auch in neuen Gewässern. Aber da michs interessiert probiere ich gerne weiter mit.

Die Variante TShape1 und TmyShape funktioniert bei mir mit Selecten und Exit. Das verschieben natürlich nicht, weil ich da im falschen Bereich bin.


Ich hab jetzt mal Variante2 gemacht (alles auf Tcustoncontrol):
Delphi-Quellcode:
uses
  SysUtils, Classes, Controls, ExtCtrls, Graphics, Messages, Types;

type
  TShapeType = (stRechteck, stDreieck, stProzess);

  TShape1 = class(TCustomControl) //<-- Achtung hier TcustomControl
  private
    { Private declarations }
    FShape : TShapeType;
    FCaption : String;
    FSelected : Boolean;

    rx, ry,
    oH, oW,
    oL, oT : Integer;

    procedure SetShape(Value : TShapeType);
    procedure SetCaption(Value : String);
    procedure SetSelection(Value : Boolean);
  protected
    { Protected declarations }
     protected procedure Paint();override;
     protected procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X,Y: Integer); override;
     protected procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
     protected procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X,Y: Integer); override;
     
     //Die beiden Window Message Behandlungsroutinen
     procedure onExit(var msg:TMessage);message cm_exit;
     procedure onButton(var msg:TMessage);message wm_lbuttondown;
  public
    { Public declarations }
  published
    { Published declarations }
    property Shape: TShapeType read FShape write SetShape;
    property Caption: String read FCaption write SetCaption;
    property Selected: Boolean read FSelected write SetSelection;

  end;


procedure Register;

implementation


procedure TShape1.onExit(var msg:TMessage);
begin
  self.Selected := false;
end;

procedure TShape1.onButton(var msg:TMessage);
begin
  self.Selected := true;
  self.SetFocus;
end;

procedure Register;
begin
  RegisterComponents('Samples', [TShape1]);
end;

procedure TShape1.SetShape(Value : TShapeType);
begin
  FShape := Value;
end;

procedure TShape1.SetCaption(Value : String);
begin
  FCaption := Value;
// Paint;
end;

procedure TShape1.SetSelection(Value : Boolean);
begin
  FSelected := Value;
  Paint;
end;

procedure TShape1.Paint();
var sw, sh: Integer;
begin
  //was hier halt so steht
end;

procedure TShape1.MouseDown(Button: TMouseButton; Shift: TShiftState; X,Y: Integer);
begin
  rx := X;
  ry := Y;

  oH := self.Height;
  oW := self.Width;
  oT := self.Top;
  oL := self.Left;

// Self.Selected := True;
  Paint;
end;

procedure TShape1.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
  //hier rechnest du falsch, benutze evtl. mal Screentoclient
end;

procedure TShape1.MouseUp(Button: TMouseButton; Shift: TShiftState; X,Y: Integer);
begin
end;

end.
Das Selektieren und "ab-"selektieren funktioniert wenn ich so starte:
Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
begin
  shape1:=Tshape1.Create(self);
  shape2:=tshape1.Create(self);
  with shape1 do begin
    left:=10;
    top:=10;
    width:=100;
    height:=100;
    parent:=form1;
    Shape := stProzess;
    Brush.Color := $005555FF;
  end;
  with shape2 do begin
    left:=200;
    top:=10;
    width:=100;
    height:=100;
    parent:=form1;
    Brush.Color := $005555FF;
  end;
end;
Nur beim Verschieben, rechnest du irgendwie falsch.
Dieser Beitrag ist für Jugendliche unter 18 Jahren nicht geeignet.
  Mit Zitat antworten Zitat