Autor Beitrag
JRegier
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1268

Win XP Home, Prof, 2003 Server
D6 Enterprise
BeitragVerfasst: Sa 30.07.05 10:43 
Hi, ich habe eine Function geschrieben um StringLänge in Pixel zu ermitteln aber es funzt nicht richtig!
Was mache ich falsch siehe Code;

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
// String länge in Pix ermitteln
function TWhereManager.GetStrLenInPix(Text : String; Font : TFont) : Integer;
begin
   Canvas.Font := Font;  // Assign(Font) habe ich auch versucht
   Result := Canvas.TextWidth(Text);
end;


Ich will hiermit die Länge einer TEdit componente einstellen damit ganzer Text zu sehen ist! Ich addiere auch 8 dazu aber bei einer
Schriftart funzte es und bei anderer nicht!
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Sa 30.07.05 11:07 
Schonmal so versucht?:

ausblenden Delphi-Quelltext
1:
2:
Edit1.Canvas.Font := ...;
Edit1.Canvas.TextWidth(...);

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Sa 30.07.05 11:09 
user profile iconGTA-Place hat folgendes geschrieben:
Schonmal so versucht?:

ein edit hat kein canvas als eigenschaft ;-)

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Sa 30.07.05 11:19 
Oh... ^^
Naja, dann halt nicht...

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: Sa 30.07.05 11:34 
user profile iconKeldorn hat folgendes geschrieben:
user profile iconGTA-Place hat folgendes geschrieben:
Schonmal so versucht?:
ein edit hat kein canvas als eigenschaft

Das kann man ja schnell ändern:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
  with TControlCanvas.Create do
    try
      Control := Edit1;
      Font := Edit1.Font;
      Edit1.ClientWidth := TextWidth(Edit1.Text) + 4;
    finally
      Free;
    end;

_________________
Ciao, Sprint.
JRegier Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1268

Win XP Home, Prof, 2003 Server
D6 Enterprise
BeitragVerfasst: Sa 30.07.05 11:49 
Vielen Dank schonmal, Delpher! :wink: