• ¡Welcome to Square Theme!
  • This news are in header template.
  • Please ignore this message.
مهمان عزیز خوش‌آمدید. ورود عضــویت


امتیاز موضوع:
  • 21 رای - 2.43 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
Title: رنگی کردن رکوردهای استرینگ گرید در دلفی
حالت خطی
#2
درود
خوبید ؟
من چند تا نمونه سورس میزارم :[عکس: Tip273.png]

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  
dx: Integer;
begin
  with 
(Sender as TStringGrid) do
  begin
    
// Don't change color for first Column, first row
    
if (ACol = 0) or (ARow = 0) then
      
Canvas.Brush.Color := clBtnFace
    else
    begin
      case 
ACol of
        
1: Canvas.Font.Color := clBlack;
        2: Canvas.Font.Color := clBlue;
      end;
      // Draw the Band
      
if ARow mod 2 = 0 then
        
Canvas.Brush.Color := $00E1FFF9
      else
        
Canvas.Brush.Color := $00FFEBDF;
      Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2, cells[acol, arow]);
      Canvas.FrameRect(Rect);
    end;
  end;
end;



سورس کد ۲tonguerocedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);

  procedure WriteText(StringGrid: TStringGrid; ACanvas: TCanvas; const ARect: TRect;
    const Text: string; Format: Word);
  const
    DX = 2;
    DY = 2;
  var
    S: array[0..255] of Char;
    B, R: TRect;
  begin
    with Stringgrid, ACanvas, ARect do
    begin
      case Format of
        DT_LEFT: ExtTextOut(Handle, Left + DX, Top + DY,
            ETO_OPAQUE or ETO_CLIPPED, @ARect, StrPCopy(S, Text), Length(Text), nil);

        DT_RIGHT: ExtTextOut(Handle, Right - TextWidth(Text) - 3, Top + DY,
            ETO_OPAQUE or ETO_CLIPPED, @ARect, StrPCopy(S, Text),
            Length(Text), nil);

        DT_CENTER: ExtTextOut(Handle, Left + (Right - Left - TextWidth(Text)) div 2,
            Top + DY, ETO_OPAQUE or ETO_CLIPPED, @ARect,
            StrPCopy(S, Text), Length(Text), nil);
      end;
    end;
  end;

  procedure Display(StringGrid: TStringGrid; const S: string; Alignment: TAlignment);
  const
    Formats: array[TAlignment] of Word = (DT_LEFT, DT_RIGHT, DT_CENTER);
  begin
    WriteText(StringGrid, StringGrid.Canvas, Rect, S, Formats[Alignment]);
  end;
begin
  // Right-justify columns 0-2
  // Spalten 0-2 rechts ausrichten.
  if ACol in [0..2] then
    Display(StringGrid1, StringGrid1.Cells[ACol, ARow], taRightJustify)

    // Center the first row
    // Erste zeile zentrieren
    if ARow = 0 then
      Display(StringGrid1, StringGrid1.Cells[ACol, ARow], taCenter)
  end;
سورس ۳:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
const
  SelectedColor = Clblue;
begin
  if (state = [gdSelected]) then
    with TStringGrid(Sender), Canvas do
    begin
      Brush.Color := SelectedColor;
      FillRect(Rect);
      TextRect(Rect, Rect.Left + 2, Rect.Top + 2, Cells[aCol, aRow]);
    end;
end;

کدها تو دلفی کپی کنی درست میشه (بخاطر ادیتور فرومه)
گروه دور همی پارسی کدرز
https://t.me/joinchat/GxVRww3ykLynHFsdCvb7eg
 
پاسخ
  


پیام‌های این موضوع
RE: رنگی کردن رکوردهای استرینگ گرید در دلفی - توسط Amin_Mansouri - 06-10-2013، 12:47 PM

موضوعات مشابه ...
موضوع نویسنده پاسخ بازدید آخرین ارسال
  اکسترکت کردن برنامه به RAM stack 4 5,278 09-09-2016، 07:56 AM
آخرین ارسال: Amin_Mansouri
  استفاده از اسکن اثر انگشت در دلفی amir_rezaee 0 3,131 06-06-2016، 09:20 AM
آخرین ارسال: amir_rezaee
  اجرای برنامه روی سیستمی که دلفی نصب نباشد nasrinPoornejaty 8 9,860 06-19-2013، 06:59 PM
آخرین ارسال: Saeed7007
  XML در دلفی nasrinPoornejaty 15 25,228 09-03-2011، 01:03 PM
آخرین ارسال: Amin_Mansouri

پرش به انجمن:


Browsing: 2 مهمان