AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Right-align

Ein Thema von sdean · begonnen am 31. Dez 2009 · letzter Beitrag vom 1. Jan 2010
Antwort Antwort
sdean

Registriert seit: 5. Dez 2009
64 Beiträge
 
#1

Right-align

  Alt 31. Dez 2009, 20:55
Hi i use the following Function to Left-align the whole MyListBox , please see the attached PIC .

my Question is how could i Right-align the Whole MyListBox ?



Delphi-Quellcode:
function TMyListBox.DrawItemHeight( AObject : TInfoObject; ACanvas : TCanvas; ARect : TRect; AState : TItemDrawState; GetHeight : Boolean ) : Integer;
var
  BM1, BM2 : Graphics.TBitmap;
  Text1, Text2 : string;
  H1, H2 : Integer;
  MaxWidth, IcoWidth, IcoHeight : Integer;

  function TextHeigh( ACanvas : TCanvas; AText : string; ARect : TRect; CanDraw : Boolean = False ) : Integer;
  const
      DrawOrNot : array[ Boolean ] of LongWord = ( DT_CALCRECT, 0 );
  var
    Flags : LongInt;
  begin // TextHeigh
    ARect.Bottom := 1;
    Flags := DrawTextBiDiModeFlags( DT_LEFT or DT_TOP or DT_NOPREFIX or
       DT_NOCLIP or DT_WORDBREAK or DT_END_ELLIPSIS or DrawOrNot[ CanDraw ] );

    Result := DrawText( ACanvas.Handle, PChar( AText ), Length( AText ),
       ARect, Flags );
  end; // TextHeigh

    {======================================================================}

begin // TMyListBox.DrawItemHeight
  MaxWidth := Abs( ARect.Right - ARect.Left );
  IcoWidth := 0;
  IcoHeight := 0;

  if AObject.Title <> 'then
    Text1 := AObject.Title // 1st string line in the List the above ONE
  else
    Text1 := ' ';

  Text2 := AObject.Text; // 2nd String line in the List the bellow One

  if ( AObject.Icon <> nil ) and not AObject.Icon.Empty then
    begin
    IcoWidth := AObject.Icon.Width;
    IcoHeight := AObject.Icon.Height;
    end; // if ( AObject.Icon <> nil ) and not AObject.Icon.Empty

  BM1 := Graphics.TBitmap.Create;
  BM1.Width := Abs( MaxWidth - IcoWidth - FSpacer );
  BM1.Height := 16;
  BM2 := Graphics.TBitmap.Create;
  BM2.Width := MaxWidth;
  BM2.Height := 16;

  with BM1.Canvas do
    begin
    Font.Assign( FTitleFont );

    if ( AState = idSelected ) or ( AState = idSelFocused ) then
      Font.Assign( FTitleSelected );

    H1 := TextHeigh( BM1.Canvas, Text1, Rect( 0, 0, BM1.Width - 4, 0 ), True );
    end; // with BM1.Canvas

  if Text2 <> 'then
    with BM2.Canvas do
      begin
      Font.Assign( FTextFont );

      if ( AState = idSelected ) or ( AState = idSelFocused ) then
        Font.Assign( FTextFontSelected );

      H2 := TextHeigh( BM2.Canvas, Text2, Rect( 2, 0, BM2.Width - 2, 0 ), True );
      end // with BM2.Canvas
  else
    H2 := 0;

    if not GetHeight then
      begin
      with ACanvas do
        begin
        Lock;
        SetBkMode( Handle, Transparent );

        if ( IcoWidth > 0 ) and ( IcoHeight > 0 ) then
          begin
          if IcoHeight > H1 then
            begin
            Draw( 2, 2, AObject.Icon );
            Font.Assign( FTitleFont );

            if ( AState = idSelected ) or ( AState = idSelFocused ) then
              Font.Assign( FTitleFontSelected );

            TextHeigh( ACanvas, Text1, Rect( 2 + IcoWidth + FSpacer,
               2 +( IcoHeight - H1 ) div 2,
               IcoWidth + BM1.Width - FSpacer - 6, 0 ), True );
            end // if IcoHeight > H1
          else
            begin
            Draw( 2, 2 +( H1 - IcoHeight ) div 2, AObject.Icon );
            Font.Assign( FTitleFont );

            if ( AState = idSelected ) or ( AState = idSelFocused ) then
              Font.Assign( FTitleFontSelected );

            TextHeigh( ACanvas, Text1, Rect( 2 + IcoWidth + FSpacer, 2,
               IcoWidth + BM1.Width - FSpacer - 6, 0 ), True );
            end; // else of if IcoHeight > H1
          end // if ( IcoWidth > 0 ) and ( IcoHeight > 0 )
        else
          begin
          Font.Assign( FTitleFont );

          if ( AState = idSelected ) or ( AState = idSelFocused ) then
            Font.Assign( FTitleFontSelected );

          TextHeigh( ACanvas, Text1, Rect( 2, 2, BM1.Width - 2, 0 ), True );
          end; // else of if ( IcoWidth > 0 ) and ( IcoHeight > 0 )

        if ( AObject.Text <> '' ) and FText then
          begin
          Font.Assign( FTextFont );

          if ( AState = idSelected ) or ( AState = idSelFocused ) then
            Font.Assign( FTextFontSelected );

          if IcoHeight > H1 then
            TextHeigh( ACanvas, Text2, Rect( 0, 2 + IcoHeight, BM2.Width, 0 ),
               True )
          else
            TextHeigh( ACanvas, Text2, Rect( 0, 2 + H1, BM2.Width, 0 ), True );
          end; // if ( AObject.Text <> '' ) and FText

        SetBkMode( Handle, OPAQUE );
        Unlock;
        end; // with ACanvas
      end; // if not GetHeight

    if FText then
      begin
      if IcoHeight > H1 then
        Result := IcoHeight + H2 + 4
      else
        Result := H1 + H2 + 4;
      end // if FText
    else
      if IcoHeight > H1 then
        Result := IcoHeight + 4
      else
        Result := H1 + 4;

    BM1.FreeImage;
    BM1.Free;
    BM2.FreeImage;
    BM2.Free;
  end; // TMyListBox.DrawItemHeight
Miniaturansicht angehängter Grafiken
lst_648.png  
  Mit Zitat antworten Zitat
VT

Registriert seit: 9. Dez 2002
11 Beiträge
 
#2

Re: Right-align

  Alt 1. Jan 2010, 15:59
your method has a parameter called ARect which states the clipping rectangle for your item which gives you the horizontal dimension of the current entry. so the calculation has to be:

ARect.Right - %TextWidth%
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:06 Uhr.
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