Autor Beitrag
JayK
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1013



BeitragVerfasst: So 01.10.06 23:57 
Hallo Leute,

ich versuche gerade mein erstes eigenes GraphicControl, also vollständig selbst gezeichnet, hinzubekommen, hänge aber schon am Start fest :roll:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
type
  TGraphicPanel = class (TGraphicControl)
    private
      FText: WideString;
    protected
      procedure SetText(AValue: WideString);
    public
      procedure Paint; override;
      constructor Create(AOwner: TComponent);
      property Text: WideString read FText write SetText;
      property Color;
  end;

implementation

procedure TGraphicPanel.Paint;
var
  textwidth: Integer;
  textheight: Integer;
begin
  Canvas.Brush.Color := Color;
  Canvas.Rectangle(00, Width, Height);
  textwidth := Canvas.TextWidth(Text);
  textheight := Canvas.TextHeight(Text);
  Canvas.Font := self.Font;
  Canvas.TextOut(self.Width div 2 - textwidth div 2,
    Height div 2 - textheight div 2,
    Text);
end;


Problem? Das Control wird einfach nicht gezeichnet, ich hab im Paint einen Breakpoint und da kommt er nie vorbei!

im Testprojekt (verteilt auf Form.OnCreate und OnShow):

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
  HintPnl := TGraphicPanel.Create(self);
  HintPnl.Parent := self;
  HintPnl.Top := 50;
  HintPnl.Left := 50;   
  HintPnl.Text := 'viel'#13#10'viel'#13#10'Text!!!!!!';
  HintPnl.Width := 100;
  HintPnl.Height := 100;
  HintPnl.Color := clInfoBk;
  HintPnl.Visible := true;


Ich sehe das Ding wie gesagt nicht und Paint wird nicht aufgerufen... was mache ich da falsch?

Vielen Dank für eure Hilfe
Jakob
wulfskin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1349
Erhaltene Danke: 1

Win XP
D5 Pers (SSL), D2005 Pro, C, C#
BeitragVerfasst: Mo 02.10.06 00:00 
Ich kenn mich damit net wirklich aus, aber versuchs doch mal mit einem inherited OnPaint; in deiner Zeichenmethode!

Gruß Hape!

_________________
Manche antworten um ihren Beitragszähler zu erhöhen, andere um zu Helfen.
JayK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1013



BeitragVerfasst: Mo 02.10.06 00:03 
TGraphicControl hat kein OnPaint und die TGraphicControl.Paint Methode ist leer (hinter dem begin kommt gleich end;).
wulfskin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1349
Erhaltene Danke: 1

Win XP
D5 Pers (SSL), D2005 Pro, C, C#
BeitragVerfasst: Mo 02.10.06 00:43 
Hallo,

habs gerade probiert, hat wunderbar funktioniert:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TGraphicPanel.SetText(AValue: WideString);
begin
  FText := AValue;
end;

constructor TGraphicPanel.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
end;

Übrigens: Es macht keinen Sinn WideString zu verwenden, wenn du nicht auch unicodefähige Zeichenmethoden uä. benutzt .

Gruß Hape!

_________________
Manche antworten um ihren Beitragszähler zu erhöhen, andere um zu Helfen.
JayK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1013



BeitragVerfasst: Mo 02.10.06 15:54 
Hmmm.. okay es ist da merke ich gerade, aber es liegt immer unter diesem VirtualStringTree auf dem Form.
BringToFront hat nix gebracht.

Wie bekomme ich es hin, dass er es auch über anderen Controls zeichnet?

Um Unicode kümmere ich mich später.