Delphi Can
Edit panding - Baskı Önizleme

+- Delphi Can (http://www.delphican.com)
+-- Forum: Delphi (http://www.delphican.com/forumdisplay.php?fid=3)
+--- Forum: Genel Programlama (http://www.delphican.com/forumdisplay.php?fid=6)
+--- Konu Başlığı: Edit panding (/showthread.php?tid=1036)



Edit panding - hido - 01-06-2017

Merhaba; TEdit panding özelliği yok, fakat Canvas ile panding yaratmaya çalışıyorum ama olmamdı. panding için basıl bir yol izlemeliyim?


Procedure TForm2.EditCerceveYap(Edit: TEdit);
var
  aCanvas: TControlCanvas;
begin
  aCanvas := Nil;
  try
    aCanvas := TControlCanvas.Create;
    aCanvas.Control := Edit;
    aCanvas.Pen.Width := 1;
    aCanvas.Pen.Color := clWebLime;
    aCanvas.Pen.Style := psInsideFrame;
    aCanvas.Brush.Style := bsClear;
    aCanvas.Rectangle(0, 0, Edit.Width, Edit.Height);
  finally
    aCanvas.free;
  end;
end;



Edit panding - ramazanayer - 02-06-2017

dbgrid componente sutunları filtrelemek için başlıklara edit nesnesi eklemiştim o componenetten bir kaç satır
InflateRect(rct, -1, -1); // bu satır rect içinde padding verir umarım örnek olarak işinize yarar
WriteText procedurü borland yıllar önce yayınladı rect içine yazı yazmak için kullanılır

procedure WriteText(ACanvas: TCanvas; ARect: TRect; DX, DY: integer;
  const Text: string; Alignment: TAlignment; ARightToLeft: boolean);
const
 AlignFlags: array [TAlignment] of integer = (DT_LEFT or DT_WORDBREAK or
   DT_EXPANDTABS or DT_NOPREFIX, DT_RIGHT or DT_WORDBREAK or DT_EXPANDTABS or
   DT_NOPREFIX, DT_CENTER or DT_WORDBREAK or DT_EXPANDTABS or DT_NOPREFIX);
 RTL: array [boolean] of integer = (0, DT_RTLREADING);
var
 B, R: TRect;
 Hold, Left: integer;
 I: TColorRef;
begin
 I := ColorToRGB(ACanvas.Brush.Color);
 if GetNearestColor(ACanvas.Handle, I) = I then
 begin
   if (ACanvas.CanvasOrientation = coRightToLeft) and (not ARightToLeft) then
     ChangeBiDiModeAlignment(Alignment);
   case Alignment of
     taLeftJustify:
       Left := ARect.Left + DX;
     taRightJustify:
       Left := ARect.Right - ACanvas.TextWidth(Text) - 3;
   else
     Left := ARect.Left + (ARect.Right - ARect.Left) shr 1 -
       (ACanvas.TextWidth(Text) shr 1);
   end;
   ACanvas.TextRect(ARect, Left, ARect.Top + DY, Text);
 end
 else
 begin
   DrawBitmap.Canvas.Lock;
   try
     with DrawBitmap, ARect do
     begin
       Width := Max(Width, Right - Left);
       Height := Max(Height, Bottom - Top);
       R := Rect(DX, DY, Right - Left - 1, Bottom - Top - 1);
       B := Rect(0, 0, Right - Left, Bottom - Top);
     end;
     with DrawBitmap.Canvas do
     begin
       Font := ACanvas.Font;
       Font.Color := ACanvas.Font.Color;
       Brush := ACanvas.Brush;
       Brush.Style := bsSolid;
       FillRect(B);
       SetBkMode(Handle, TRANSPARENT);
       if (ACanvas.CanvasOrientation = coRightToLeft) then
         ChangeBiDiModeAlignment(Alignment);
       DrawText(Handle, PChar(Text), Length(Text), R, AlignFlags[Alignment] or
         RTL[ARightToLeft]);
     end;
     if (ACanvas.CanvasOrientation = coRightToLeft) then
     begin
       Hold := ARect.Left;
       ARect.Left := ARect.Right;
       ARect.Right := Hold;
     end;
     ACanvas.CopyRect(ARect, DrawBitmap.Canvas, B);
   finally
     DrawBitmap.Canvas.Unlock;
   end;
 end;
end;

var
  rct: TRect;
begin
 Canvas.Brush.Color := clBtnFace;
 Canvas.Brush.Style := bsSolid;
 rct := Rect(rct.Left, rct.Top + DefaultRowHeight, rct.Right, rct.Bottom);
 Canvas.FillRect(rct);
 Canvas.Brush.Color := clWindow;
 Canvas.Brush.Style := bsSolid;
 Canvas.Font.Color := clBlue;
 InflateRect(rct, -1, -1);
 Canvas.FillRect(rct);
 WriteText(Canvas, rct, 4, 2, Text, taLeftJustify, True);
end;

rct := Edit.BoundsRect; // ile editin rect değerlerini çağırabilirsin
InflateRect(rct, -1, -1);
Canvas.Brush.Color := clWindow;
Canvas.Brush.Style := bsSolid;
Canvas.Font.Color := clBlue;
Canvas.FillRect(rct);
WriteText(Canvas, rct, 4, 2, Text, taLeftJustify, True);
gibi yapılabilir