全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1470
推到 Plurk!
推到 Facebook!

ComboBox裡的文字顏字...

尚未結案
andy0412
一般會員


發表:22
回覆:12
積分:11
註冊:2004-03-03

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-03-10 15:04:13 IP:61.221.xxx.xxx 未訂閱
請問我要如何將1111-2222-3333-4444 設定成不同的顏色呢?    我改了好久,都改不出來...    請各位大大的支持... 謝謝。 發表人 - andy0412 於 2005/03/10 15:08:01
pillar62
資深會員


發表:9
回覆:324
積分:271
註冊:2002-04-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-03-10 15:12:32 IP:210.64.xxx.xxx 未訂閱
你好 應該是直接設定combox的屬性font就可以了吧!! Pillar Wang
------
Pillar Wang
andy0412
一般會員


發表:22
回覆:12
積分:11
註冊:2004-03-03

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-03-10 15:15:39 IP:61.221.xxx.xxx 未訂閱
引言: 你好 應該是直接設定combox的屬性font就可以了吧!! Pillar Wang
我試了~~ 從combox裡設定,就會變成一種顏色...
pillar62
資深會員


發表:9
回覆:324
積分:271
註冊:2002-04-15

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-03-10 16:22:05 IP:210.64.xxx.xxx 未訂閱
你好 試試看
  if ComboBox1.Text = '1111-2222-3333-4444' then
    ComboBox1.Font.Color := clRed
  else
    ComboBox1.Font.Color := clGreen;
Pillar Wang
------
Pillar Wang
andy0412
一般會員


發表:22
回覆:12
積分:11
註冊:2004-03-03

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-03-10 17:04:28 IP:61.221.xxx.xxx 未訂閱
引言: 你好 試試看
  if ComboBox1.Text = '1111-2222-3333-4444' then
    ComboBox1.Font.Color := clRed
  else
    ComboBox1.Font.Color := clGreen;
Pillar Wang
Dear Pillar Wang ~ ^_^ 請問我要如何將1111-2222-3333-4444 設定成不同的顏色呢? 我指的意思是將1111-2222-3333-4444 1111(1-4位),設定成紅色 2222(6-9位),設定成藍色 3333(11-14位),設定成黃色 4444(16-19位),設定成綠色..
yorkland
高階會員


發表:2
回覆:138
積分:108
註冊:2004-12-17

發送簡訊給我
#6 引用回覆 回覆 發表時間:2005-03-10 17:05:21 IP:220.130.xxx.xxx 未訂閱
我想你是希望1,2,3,4均出現不同的顏色。 在OnDrawItem裡可以自己以Canvas的方式繪製。 包含Canvas.TextWidth, Canvas.TextHeight, Canvas.TextOut..你可以自己算位置達到你要的目的, 但是如果你是使用TComboBox.Style是可編輯的模式的話, 一旦TComboBox進入編輯模式, 裡頭的文字顯示就不是我們能控制的。
jeffreck
高階會員


發表:247
回覆:340
積分:197
註冊:2003-01-23

發送簡訊給我
#7 引用回覆 回覆 發表時間:2005-03-10 21:30:34 IP:61.70.xxx.xxx 未訂閱
http://delphi.ktop.com.tw/topic.php?topic_id=60598 http://delphi.ktop.com.tw/topic.php?topic_id=22912 http://delphi.ktop.com.tw/topic.php?topic_id=59398
jeffreck
高階會員


發表:247
回覆:340
積分:197
註冊:2003-01-23

發送簡訊給我
#8 引用回覆 回覆 發表時間:2005-03-10 21:48:31 IP:61.70.xxx.xxx 未訂閱
1. 設定 Combobox 的 style 屬性為 csOwnerDrawFixed 2. 在 onDrawItem 的事件中去畫
 
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  With ComboBox1 do
  begin
    Canvas.FillRect(Rect);
    
    Canvas.Font.Color := clLime;
    Canvas.TextOut(Rect.Left,Rect.Top,leftstr(ComboBox1.Items[Index],5));        Canvas.Font.Color := clRed;
    Canvas.TextOut(Rect.Left+70,Rect.Top,RightStr(ComboBox1.Items[Index],5));
  end;       end; 
andy0412
一般會員


發表:22
回覆:12
積分:11
註冊:2004-03-03

發送簡訊給我
#9 引用回覆 回覆 發表時間:2005-03-11 14:52:08 IP:61.221.xxx.xxx 未訂閱
引言: 1. 設定 Combobox 的 style 屬性為 csOwnerDrawFixed 2. 在 onDrawItem 的事件中去畫
 
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  With ComboBox1 do
  begin
    Canvas.FillRect(Rect);
    
    Canvas.Font.Color := clLime;
    Canvas.TextOut(Rect.Left,Rect.Top,leftstr(ComboBox1.Items[Index],5));        Canvas.Font.Color := clRed;
    Canvas.TextOut(Rect.Left+70,Rect.Top,RightStr(ComboBox1.Items[Index],5));
  end;       end; 
Canvas.TextOut(Rect.Left,Rect.Top,leftstr(ComboBox1.Items[Index],5)); 沒法用耶 要用 Canvas.TextOut(Rect.Left,Rect.Top,copy(ComboBox1.Items[Index],5));
jeffreck
高階會員


發表:247
回覆:340
積分:197
註冊:2003-01-23

發送簡訊給我
#10 引用回覆 回覆 發表時間:2005-03-11 15:03:24 IP:61.218.xxx.xxx 未訂閱
    uses StrUtils    ------    uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls ,StrUtils;  
系統時間:2024-06-29 17:13:18
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!