我定义了如下类型:
type
  TTextStyle =(DT_BOTTOM,DT_CALCRECT,DT_CENTER,DT_EDITCONTROL,DT_END_ELLIPSIS,
                DT_EXPANDTABS,DT_EXTERNALLEADING,DT_LEFT,DT_MODIFYSTRING,
                DT_NOCLIP,DT_NOPREFIX,DT_RIGHT,DT_RTLREADING,DT_SINGLELINE,
                DT_TABSTOP,DT_TOP,DT_VCENTER,DT_WORDBREAK);FTextStyle:=DT_RIGHT;
//Self是TStringGrid的一个子类DrawText(Self.Canvas.Handle,PChar(Self.Cells[ACol,ARow]),Length(Self.Cells[ACol,ARow]),ARect,Integer(FTextStyle));
为什么显示出来的字不是右对齐的呢?

解决方案 »

  1.   

    怎么没人呢?我想让DrawText的uFormat参数可以在属性里设置去组合,怎么做呢?
      

  2.   

    我做了测试,可以对应一部分,但不是标准!
    procedure TForm1.Button1Click(Sender: TObject);
    var
      FTextStyle: TTextStyle;
      ARect: TRect;
      sTemp: String;
      i: Integer;
    begin
      sTemp := '中华人民共和国';
      //DrawText(Self.Canvas.Handle,PChar(Self.Cells[ACol,ARow]),Length(Self.Cells[ACol,ARow]),ARect,Integer(FTextStyle));
      FTextStyle := DT_BOTTOM;
      FTextStyle := DT_CALCRECT;
      FTextStyle := DT_CENTER;
      FTextStyle := DT_EDITCONTROL;
      FTextStyle := DT_END_ELLIPSIS;
      FTextStyle := DT_EXPANDTABS;
      FTextStyle := DT_EXTERNALLEADING;
      FTextStyle := DT_LEFT;
      FTextStyle := DT_MODIFYSTRING;
      FTextStyle := DT_NOCLIP;
      FTextStyle := DT_NOPREFIX;
      FTextStyle := DT_RIGHT;
      FTextStyle := DT_RTLREADING;
      FTextStyle := DT_SINGLELINE;
      FTextStyle := DT_TABSTOP;
      FTextStyle := DT_TOP;
      FTextStyle := DT_VCENTER;
      FTextStyle := DT_WORDBREAK;
      ARect.Left := 0;
      ARect.Top := 0;
      ARect.Right := Self.Width;
      ARect.Bottom := Self.Height;
      DrawText(Self.Canvas.Handle,PChar(sTemp),length(sTemp),ARect,Integer(FTextStyle));
      for i := 0 to 10000 do
      begin
        DrawText(Self.Canvas.Handle,PChar(IntToStr(i) + sTemp),length(sTemp) + 3,ARect,i);
        Sleep(500);
      end;
    end;
      

  3.   

    改一下,那样看不到下面的。
    把改进去
      ARect.Right := Self.Width div 2;
      ARect.Bottom := Self.Height div 2;
    4个角落都对应起来了!