免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
Canvas實(shí)現(xiàn)特效

Canvas實(shí)現(xiàn)特效

時(shí)間:2011-5-26來(lái)源:yang 作者: peng點(diǎn)擊: 10次

利用Canvas可以實(shí)現(xiàn)很多特效,這里僅僅列出在Canvas上更改字體以及背景的方法。

1、DBGrid不同行/單元格顯示不同顏色
2、StatusBar上面字體的顏色顯示
3、StringGrid中文字右對(duì)齊
4、ListBox改變字體顏色
5、ComboBox顯示字體列表,同時(shí)各字體名稱使用其本身來(lái)顯示
6、TreeView改變字體顏色

==========================================
1、DBGrid不同行/單元格顯示不同顏色(注釋掉的部分為顯示前景顏色)
procedure TForm1.DBGridDrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
begin
{
  if Query1.FieldByName(‘Col1‘).AsString <> ‘‘ then
    if (gdSelected in State) and (DBGrid1.Focused = True) then
      DBGrid1.Canvas.Font.Color := clWhite
    else
      DBGrid1.Canvas.Font.Color := clTeal;
}
  if query1.FieldByName(‘Col1‘).AsString <> ‘‘ then
    dbgrid1.Canvas.Brush.Color := $00E0FFFF
  else
    dbgrid1.Canvas.Brush.Color := clWhite;

  if gdSelected in State  then
  begin
    dbgrid1.Canvas.Brush.Color := clNavy;
    dbgrid1.Canvas.Font.Color := clWhite;
  end;

  dbgrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
==========================================
2、StatusBar上面字體的顏色顯示

StatusBar1的每一個(gè)TStatusPanel的Style為psOwnerDraw,然后在OnDrawPanel中寫(xiě)代碼自己寫(xiě)畫(huà)布
procedure TForm1.StatusBar1DrawPanel(StatusBar: TStatusBar;
  Panel: TStatusPanel; const Rect: TRect);
begin
  case Panel.ID of
    0: StatusBar.Canvas.Font.Color := clred;
    1: StatusBar.Canvas.Font.Color := clBlue;
    2: StatusBar.Canvas.Font.Color := ClYellow;
  end;

  StatusBar.Canvas.TextRect(Rect, Rect.Left, Rect.Top, Panel.Text);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  StatusBar1.Panels[0].Text := ‘a(chǎn)aaaaaaaaa‘;
  StatusBar1.Panels[1].Text := ‘a(chǎn)aaaaaaaaa‘;
  StatusBar1.Panels[2].Text := ‘a(chǎn)aaaaaaaaa‘;
end;

==========================================
3、StringGrid中文字右對(duì)齊
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  l_Left, l_Top: Integer;
begin
  l_Left := (StringGrid1.Colwidths[ACol] - StringGrid1.Canvas.Textwidth(StringGrid1.Cells[ACol, ARow]) - 2); //右對(duì)齊
  l_Top := (StringGrid1.Rowheights[ARow] - StringGrid1.Canvas.Textheight(StringGrid1.Cells[ACol, ARow])) div 2;
  StringGrid1.Canvas.Textrect(Rect, Rect.Left + l_Left, Rect.Top + l_Top, StringGrid1.Cells[ACol, ARow]);
end;

=========================================
4、ListBox改變字體顏色

設(shè)置ListBox的ListBox1.Style := lbOwnerDrawVariable;
然后在他的OnDrawItem中寫(xiě)代碼:
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  if Index = 1 then
    ListBox1.Canvas.Font.Style := [fsBold];
  ListBox1.Canvas.TextRect(Rect, Rect.Left, Rect.Top, ListBox1.Items[Index]);
end;

==========================================
5、ComboBox顯示字體列表,同時(shí)各字體名稱使用其本身來(lái)顯示

Style設(shè)成csOwnerDrawFixed
FormOnShow:
  for i := 0 to Screen.Fonts.Count - 1 do
    ComboBox1.Items.Add(Screen.Fonts[i]);
ComboBox1OnDrawItem:
  ComboBox1.Canvas.Font.Name := Screen.Fonts[Index];
  ComboBox1.Canvas.FillRect(Rect);
  ComboBox1.Canvas.TextOut(Rect.Left, Rect.Top, Screen.Fonts[Index]);

==========================================
6、TreeView改變字體顏色

procedure TForm1.TreeView1AdvancedCustomDrawItem(Sender: TCustomTreeView;
  Node: TTreeNode; State: TCustomDrawState; Stage: TCustomDrawStage;
  var PaintImages, DefaultDraw: Boolean);
var
  NodeRect: TRect;
  p: integer;
  s: string;
begin
  DefaultDraw := False;
  with TreeView1.Canvas do
  begin
    NodeRect := Node.DisplayRect(True);
    p := Pos(‘ ‘, Node.Text);
    if p > 0 then
    begin
      if cdsSelected in State then
      begin
        SetTextColor(Handle, clWhite);
        TextOut(NodeRect.Left, NodeRect.Top, Node.Text);
      end
      else
      begin
        s := Copy(Node.Text, 1, p);
        SetTextColor(Handle, clBlue);
        TextOut(NodeRect.Left, NodeRect.Top, s);
        SetTextColor(Handle, clRed);
        TextOut(NodeRect.Left + TextWidth(s), NodeRect.Top, Copy(Node.Text, p + 1, Length(Node.Text) - p));
      end
    end
    else
      TextOut(NodeRect.Left, NodeRect.Top, Node.Text);
  end;
end;





procedure TForm1.TreeView1AdvancedCustomDrawItem(Sender: TCustomTreeView;
  Node: TTreeNode; State: TCustomDrawState; Stage: TCustomDrawStage;
  var PaintImages, DefaultDraw: Boolean);
const
  deltaX = 2;
  deltaY = 1;
var
  NodeRect: TRect;
  p: integer;
  s: string;
begin
  //DefaultDraw := False;
  if Stage <> cdPostPaint then exit;
  with TreeView1.Canvas do
  begin
    NodeRect := Node.DisplayRect(True);
    p := Pos(‘ ‘,Node.Text);
    if p>0 then
    begin
      s := Copy(Node.Text,1,p);
      SetTextColor(Handle,clBlue);
      TextOut(NodeRect.Left + deltaX, NodeRect.Top + deltaY, s);
      SetTextColor(Handle,clRed);
      TextOut(NodeRect.Left + deltaX + TextWidth(s), NodeRect.Top + deltaY, Copy(Node.Text,p+1,Length(Node.Text)-p));
    end;
  end;

end;  

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
StringGrid去掉第一行第一列的藍(lán)色框(失去焦點(diǎn))
轉(zhuǎn)載DBGrid和DBGridEH
delphi DBGrid簡(jiǎn)單自繪(字體顏色、背景等)
DBGrid中顯示多行的方法
StringGrid單元格對(duì)齊方式及換行
delphi中TDBGrid的使用
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服