有沒有人玩過自繪ComboBox? |
答題得分者是:william
|
lcsboy
版主 發表:87 回覆:622 積分:394 註冊:2002-06-18 發送簡訊給我 |
|
ddy
站務副站長 發表:262 回覆:2105 積分:1169 註冊:2002-07-13 發送簡訊給我 |
|
lcsboy
版主 發表:87 回覆:622 積分:394 註冊:2002-06-18 發送簡訊給我 |
|
ddy
站務副站長 發表:262 回覆:2105 積分:1169 註冊:2002-07-13 發送簡訊給我 |
|
lcsboy
版主 發表:87 回覆:622 積分:394 註冊:2002-06-18 發送簡訊給我 |
|
william
版主 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
call DrawFocusRect do cancel the rect (I think Windows is using XOR mode for the focus rect), e.g.
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); var s : string; begin s := TCombobox(Control).Items[Index]; with TCombobox(Control).Canvas do begin DrawText(Handle,PChar(s),length(s),Rect,DT_CENTER); if odFocused in State then DrawFocusRect(Rect); end; end; |
ccchen
版主 發表:61 回覆:940 積分:1394 註冊:2002-04-15 發送簡訊給我 |
William所說真的可以嗎? 我認為應該與DrawItem無關, 主要是Combobox中共有3個Windowhandle, 在cdOwnerDraw時, EditHandle沒有了故取得focus時失控
試一下, 把combobox之onPaint完全Disable, 其他不繪, 這個線框照常存在. 只要上面有東西就沒問題, 提供兩個方法, 也許有更好的吧 1. 給initial value,如果可接受,這樣最簡單 (i.e) 開始時就
combobox1.itemindex:=0;2. 要改內部, EditHandle之控制太麻煩, 自己加一個上去吧,元件create時, Create此edit, onPain時, 若為csOwnerDrawfixed且itemindex < 0則visible TCombobox=class(StdCtrls.Tcombobox) Ed:TEdit; constructor Create(AOwner: TComponent); override; procedure WMPaint(var Message: TWMPaint); message WM_PAINT; end; constructor TCombobox.Create(AOwner: TComponent); begin inherited; ed:=TEdit.create(AOwner); ED.parent:=self; ED.Visible:=False; ED.left:=GetSystemMetrics(SM_CXBORDER); ED.Width := width - 2* GetSystemMetrics(SM_CXBORDER) -GetSystemMetrics(SM_CXHTHUMB); ED.Top:=GetSystemMetrics(SM_CYBORDER); ED.height:=height-2*GetSystemMetrics(SM_CYBORDER); ED.readonly:=True; end; procedure TCombobox.WMPaint(var Message: TWMPaint); begin if (self.Style=csOwnerDrawFixed) and (itemindex<0) then ED.visible:=True else ED.visible:=False; DefaultHandler(Message); end;測試過, 應無問題 |
lcsboy
版主 發表:87 回覆:622 積分:394 註冊:2002-06-18 發送簡訊給我 |
引言: call DrawFocusRect do cancel the rect (I think Windows is using XOR mode for the focus rect), e.g.Wa.......Le............ 原來我之前都判斷odSelected, 現在試了才知道 odFocused和odSelected是有所不同的, 不然沒事有兩種設定幹嘛< > 不好意思, 自己耍了個小白吃< >, 不過同時感謝William和ccchen 因為如果要讓ComboBox也能輸入, 是要加上ccchen的作法 且default設ItemIndex=0 是可以接受的procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); var s : string; begin s := TCombobox(Control).Items[Index]; with TCombobox(Control).Canvas do begin DrawText(Handle,PChar(s),length(s),Rect,DT_CENTER); if odFocused in State then DrawFocusRect(Rect); end; end; |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |