Delphi-PRAXiS
Seite 3 von 3     123   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Delphi Formulare in hohen DPI korrekt anzeigen (https://www.delphipraxis.net/190598-formulare-hohen-dpi-korrekt-anzeigen.html)

Aviator 20. Okt 2016 22:54

AW: Formulare in hohen DPI korrekt anzeigen
 
Zitat:

Zitat von himitsu (Beitrag 1351542)
Delphi-Quellcode:
Format('%s.*', [' ', BlankCount]);
, aber sicher, daß es nach dem "s" stehen soll?

Ne. War nur mal so dahin geschrieben weil ich nicht genau wusste, ob Format auf das Auffüllen von Leerzeichen unterstützt. Habe deine Zeile auch nicht ausgeführt und weiß dementsprechend immer noch nicht ob es geht.

himitsu 21. Okt 2016 09:43

AW: Formulare in hohen DPI korrekt anzeigen
 
Nja, grundsätzlich meinte ich auch nur, dass die "Format-Formatierungen" zwischen "%" und Typ stehen.

Im Wiki steht nur was vom Abschneiden, also ob auch aufgefüllt wird, könnte man einfach mal probieren.
http://docwiki.embarcadero.com/Libra...Format-Strings

Delphi-Quellcode:
ShowMessage(Format('a#%.8s#', ['x']) + sLineBreak
  + Format('b#%.8s#', ['xxxxxxxxxxxxxxxxxxxxxxx']) + sLineBreak
  + Format('c#%8.s#', ['x']) + sLineBreak
//+ Format('d#%.-8s#', ['x']) + sLineBreak // gibt's net
  + Format('e#%-8.s#', ['x']) + sLineBreak
  + Format('f#%8.8s#', ['x']) + sLineBreak
//+ Format('g#%8.-8s#', ['x']) + sLineBreak
  + Format('h#%-8.8s#', ['x']) + sLineBreak);

Jim Carrey 21. Okt 2016 12:02

AW: Formulare in hohen DPI korrekt anzeigen
 
Meine aktuelle Lösung ist die folgende, für alle die, die es interessiert.
Mein Einsatzzweck ist eine multilinguale Software, wo ich die Edits und ComboBoxen nicht am Ende eines Satzes (CheckBox) haben sollte sondern grammatikalisch korrekt mittendrin.

So war es vorher:
Delphi-Quellcode:
LabelX.Caption := 'Das hier ist ein ganz langer Satz mit gefühlt....................völlig nutzlosen Zeichen!'; // statt den Punkten natürlich Leerzeichen
Edit1.Left := 123;
So ist es jetzt:
Delphi-Quellcode:
LabelX.Caption := 'Das hier ist ein ganz langer Satz mit gefühlt ' + calcSpacesNeeded(Edit1) + ' völlig nutzlosen Zeichen!';
setControlToPosition(Edit1, LabelX);
Delphi-Quellcode:
function getTextWidth(const aString: string; aForm: TForm): Integer;
var
 iRes: Integer;
 // Canvas: TCanvas;
begin
 iRes := 0;

 if aString <> '' then
  begin
   // Canvas := TCanvas.Create;

   // try
   // Canvas.Handle := GetDC(0);

   // try
   // Canvas.Font := aForm.Font;
   iRes := aForm.Canvas.TextWidth(aString); // nur diese Zeile wird benötigt, da aForm schon ein Canvas hat
   // finally
   // ReleaseDC(0, Canvas.Handle);
   // end;
   // finally
   // Canvas.Free;
   // end;
  end;

 Result := iRes;
end;

function calcSpacesNeeded(aControl: TControl): string;
var
 i, iTmpWidth, iSpaceWidth: Integer;
 sTmp: string;
begin
 iSpaceWidth := getTextWidth(' ', TForm(GetParentForm(aControl)));

 sTmp := '';
 iTmpWidth := aControl.Width div iSpaceWidth;

 for i := 0 to iTmpWidth do
  begin
   sTmp := sTmp + ' ';
  end;

 if aControl.ClassType = TEdit then
  sTmp := sTmp + '     ' // 6
 else if aControl.ClassType = TComboBox then
  sTmp := sTmp + '  ' // 4
 else
  sTmp := sTmp + ' '; // 2

 Result := sTmp;
end;

procedure setControlToPosition(aControlToSet, aControlSource: TControl);
var
 iSpacePosition, iCaptionWidth, iTmp: Integer;
 sCaption, sTmp: string;
begin
 if aControlSource.ClassType = TEdit then
  sCaption := (aControlSource as TEdit).Text
 else if (aControlSource.ClassType = TCheckBox) or (aControlSource.ClassType = TRadioButton) then
  sCaption := (aControlSource as TCheckBox).Caption
 else if (aControlSource.ClassType = TLabel) then
  sCaption := (aControlSource as TLabel).Caption;

 iSpacePosition := PosEx(' ', sCaption, 1) + 2;

 if iSpacePosition > 0 then
  begin
   sTmp := Copy(sCaption, 1, iSpacePosition);

   iCaptionWidth := getTextWidth(sTmp, TForm(GetParentForm(aControlToSet)));

   iTmp := aControlToSet.Width;
   if aControlSource.ClassType = TLabel then
    iTmp := aControlToSet.Width div 2;

   if aControlToSet.ClassType = TEdit then
    iTmp := iTmp + 2
   else if aControlToSet.ClassType = TComboBox then
    iTmp := iTmp - 4
   else
    iTmp := iTmp - 6;

   aControlToSet.Left := iCaptionWidth + iTmp;
  end;
end;
Das Resultat ist, dass Edit1 immer korrekt bei jeglicher DPI genau da im darunterliegenden Text-Control angezeigt wird, wo die Leerzeichen sind.


Alle Zeitangaben in WEZ +1. Es ist jetzt 02:19 Uhr.
Seite 3 von 3     123   

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz