![]() |
Selected = False wenn Click außerhalb Komponente
Hi,
also ich habe mir eine eigene Komponente gebastelt. Sind im groben Shapes. Ich habe nun noch eine Eigenschaft (selected mit boolean) hinzugefügt. sobald ein shape selected ist erscheinen vier kleine weise vierecke an den ecken um die größe zu verändern. das shape wird selected sobald ich mit der maus upclicke :) also bei onmouseup (ist auch schon in der komponente definiert) wie mache ich es jetzt am besten dass wenn ein click auf den hintergrund erfolgt das die komponente selected = false wird. mache ich das am besten im hauptprogramm oder in der komponente? (auch im hinblick darauf das später mehrere objekte mit z.b. shift gehaltener taste markiert werden sollen) merci beaucoup :) owolicious |
Re: Selected = False wenn Click außerhalb Komponente
Von wo hast du denn deine Komponente abgeleitet?
Ein TWincontrol liefert das Ergeignis onExit mit, das kannst du ja auswerten. Oder du reagierst auf die message CM_EXIT; |
Re: Selected = False wenn Click außerhalb Komponente
Delphi-Quellcode:
d.h. doch dass ich es von tShape abegeleitet habe oder??? :?:
TShape1 = class(TShape)
|
Re: Selected = False wenn Click außerhalb Komponente
Ja, das heist es.
Und Tshape ist von TGraphiccontrol, was widerum von TControl ist, usw... Demnach hast du kein onExit-Ereignis. Hmm, jetzt wirds schwieriger. TGraphiccontrol ist nicht auf Benutzerinteraktion ausgelegt. Entweder du baust um auf TWincontrol, oder du musst es irgendwie anders umgehen, indem du alle Nachrichten auf das Formular auswertest. |
Re: Selected = False wenn Click außerhalb Komponente
Hallo owolicious,
ich würde einen anderen Weg wählen und die Verwaltung der selektierten Controls auslagern. Die Komponente ![]() Gruß Hawkeye |
Re: Selected = False wenn Click außerhalb Komponente
hmmm wie kann man den TShape auf TWinControl umbauen??
|
Re: Selected = False wenn Click außerhalb Komponente
Auf die Schnelle fällt mir nur das ein (ist sicherlich verbesserungswürdig):
Delphi-Quellcode:
type tShape1=class(Twincontrol)
Shape:Tshape; procedure Exit(var msg:TMessage);message cm_exit; procedure Button(var msg:TMessage);message wm_lbuttondown; constructor create(Aowner:Tcomponent);override; destructor destroy; end; //.... constructor Tshape1.create; begin inherited create(Aowner); shape:=Tshape.Create(self); shape.Parent:=self; shape.Align:=alclient; shape.Enabled:=false; self.TabStop:=true; end; destructor Tshape1.destroy; begin shape.Free; inherited; end; procedure TShape1.Exit; begin showmessage('Exit'); end; procedure TShape1.button; begin self.SetFocus; end; |
Re: Selected = False wenn Click außerhalb Komponente
hmm aber da sagt er jetzt das er die methode paint nicht gefunden hat in der basis klasse
hier mal mein code:
Delphi-Quellcode:
unit Shape2;
interface uses SysUtils, Classes, Controls, ExtCtrls, Graphics; type TShapeType = (stRechteck, stDreieck, stProzess); TShape1 = class(TWinControl) Shape : TShape; 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; 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 Register; begin RegisterComponents('Samples', [TShape1]); end; procedure TShape1.SetShape(Value : TShapeType); begin FShape := Value; end; procedure TShape1.SetCaption(Value : String); begin FCaption := Value; end; procedure TShape1.SetSelection(Value : Boolean); begin FSelected := Value; Paint; end; procedure TShape1.Paint(); var sw, sh: Integer; begin Canvas.Brush.Color := clWhite; Canvas.FillRect(Rect(0,0,self.Width, self.Height)); sw := self.Width -1; sh := self.Height -1; Canvas.Brush.Color := self.Brush.Color; Canvas.Font.Color := $00FFFFFF; Canvas.Font.Style := [fsBold]; if Self.Shape = stRechteck then begin Canvas.Polygon([Point(4, 4), Point(Self.ClientWidth-4, 4), Point(Self.ClientWidth-4, Self.ClientHeight-4), Point(4, Self.ClientHeight-4)]); end; If Self.Shape = stDreieck then begin Canvas.Polygon([Point(4, Trunc(Self.ClientHeight / 2)-4), Point(Self.ClientWidth-4, 4), Point(Self.ClientWidth-4, Self.ClientHeight-4)]); end; If Self.Shape = stProzess then begin Canvas.Polygon([Point(4,4), Point(Trunc(0.85 * Self.Width),4), Point(Self.Width-4,Trunc(Self.Height / 2)), Point(Trunc(0.85 * Self.Width), Self.Height-4), Point(4,Self.Height-4), Point(Trunc(0.15*Self.Width),Trunc(Self.Height / 2))]); end; If Self.Selected = True then begin Canvas.Pen.Style := psDot; Canvas.Pen.Color := $00999999; Canvas.Brush.Style:= bsClear; Canvas.Polyline([ Point(0,0), Point(sw,0), Point(sw,sh), Point(0,sh), Point(0,0) ]); Canvas.Pen.Style := psSolid; Canvas.Pen.Color := $00000000; Canvas.Brush.Color := $00FFFFFF; //Ecken [] zeichnen Canvas.Rectangle(0,0,8,8); Canvas.Rectangle(self.ClientWidth-8,0,self.ClientWidth,8); Canvas.Rectangle(0,self.ClientHeight-8,8,self.ClientHeight); Canvas.Rectangle(self.ClientWidth-8,self.ClientHeight-8,self.ClientWidth,self.ClientHeight); Canvas.Rectangle(Trunc(self.Width /2)-4,0,Trunc(self.Width /2)+4,8); Canvas.Rectangle(Trunc(self.Width /2)-4,self.Height-8,Trunc(self.Width /2)+4,self.Height); Canvas.Rectangle(0,Trunc(Self.Height / 2)-4,8,Trunc(Self.Height / 2)+4); Canvas.Rectangle(self.Width-8,Trunc(Self.Height / 2)-4,self.Width,Trunc(Self.Height / 2)+4); end; Canvas.Brush.Style := bsClear; Canvas.TextOut(Trunc(self.Width / 2)-Trunc(Canvas.TextWidth(Caption) / 2), Trunc(self.Height / 2) - Trunc(Canvas.TextHeight(Caption) / 2), Self.Caption); 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 if ((ssLeft in Shift) AND (self.Selected = True)) then begin //links oben if ((rx < 9) AND (ry < 9)) then begin self.Top := Mouse.CursorPos.Y -30 - Parent.Top - ry; self.Left := Mouse.CursorPos.X -4 - Parent.Left - rx; self.Height := oH+(oT - self.Top); self.Width := oW+(oL - self.Left); //rechts oben end else if ((rx > oW-8) AND (ry < 9)) then begin self.Top := Mouse.CursorPos.Y - 30 - Parent.Top - ry; self.Height := oH+(oT - self.Top); self.Width := Mouse.CursorPos.X -4 - Parent.Left - oL + (oW-rX); //rechts unten end else if ((rx > oW-8) AND (ry > oH -8)) then begin self.Top := oT; self.Left := oL; self.Height := Mouse.CursorPos.Y - 30 - Parent.Top - oT + (oH-rY); self.Width := Mouse.CursorPos.X - 4 - Parent.Left - oL + (oW-rX); //links unten end else if ((rx < 9) AND (ry > oH -8)) then begin self.Top := oT; self.Left := Mouse.CursorPos.X -4 - Parent.Left - rx; self.Height := Mouse.CursorPos.Y - 30 - Parent.Top - oT + (oH-rY); self.Width := oW+(oL - self.Left); //mitte oben end else if ((rx > Trunc(oW / 2)-4) AND (rx < Trunc(oW / 2)+4) AND (ry < 9)) then begin self.Top := Mouse.CursorPos.Y -30 - Parent.Top - ry; self.Height := oH+(oT - self.Top); //mitte links end else if ((rx < 9) AND (ry > Trunc(oH/2) -4) AND (ry < Trunc(oH/2)+4)) then begin self.Left := Mouse.CursorPos.X -4 - Parent.Left - rx; self.Width := oW+(oL - self.Left); //mitte rechts end else if ((rx > oW-8) AND (ry > Trunc(oH/2) -4) AND (ry < Trunc(oH/2)+4)) then begin self.Width := Mouse.CursorPos.X -4 - Parent.Left - oL + (oW-rX); //mitte unten end else if ((rx > Trunc(oW / 2)-4) AND (rx < Trunc(oW / 2)+4) AND (ry > oH -8)) then begin self.Top := oT; self.Height := Mouse.CursorPos.Y - 30 - Parent.Top - oT + (oH-rY); //sonst verschiebe nur end else begin self.Top := Mouse.CursorPos.Y - Parent.Top - ry-30; self.Left := Mouse.CursorPos.X - Parent.Left - rx-4; end; end; end; procedure TShape1.MouseUp(Button: TMouseButton; Shift: TShiftState; X,Y: Integer); begin end; end. |
Re: Selected = False wenn Click außerhalb Komponente
Vielleicht solltest du eher ein Twincontrol um dein TShape1 bauen. Also du machst dein Tshape1 wie gehabt, veröffnetlichst dann aber Tmyshape:
Delphi-Quellcode:
Aber vielleicht gibts auch noch viel bessere Ideen...
type
TShape1 = class(TShape) private { Private declarations } FShape : TShapeType; FCaption : String; //... end; type TMyShape=class(Twincontrol) Shape:TShape1; procedure Exit(var msg:TMessage);message cm_exit; procedure Button(var msg:TMessage);message wm_lbuttondown; constructor create(Aowner:Tcomponent);override; destructor destroy; end; |
Re: Selected = False wenn Click außerhalb Komponente
also erstmal vielen dank für eure hilfe :)
also ich habs mal so gemacht aber leider passiert nix beim klicken :)
Delphi-Quellcode:
interface
uses SysUtils, Classes, Controls, ExtCtrls, Graphics, Messages; type TShapeType = (stRechteck, stDreieck, stProzess); TShape1 = class(TShape) 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; 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; type TMyShape = class(TWinControl) Shape : TShape1; procedure Exit(var msg:TMessage);message cm_exit; procedure Button(var msg:TMessage);message wm_lbuttondown; constructor create(Aowner:Tcomponent);override; destructor destroy; end; procedure Register; implementation constructor TMyShape.create; begin inherited create(Aowner); shape:=Tshape1.Create(self); shape.Parent:=self; shape.Enabled:=false; self.TabStop:=true; end; destructor TMyShape.destroy; begin shape.Free; inherited; end; procedure TMyShape.Exit(var msg:TMessage); begin self.Shape.Selected := false; end; procedure TMyShape.Button(var msg:TMessage); begin self.Shape.Selected := true; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 17:16 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz