請問FileListBox如何在底部加上ScrollBar |
尚未結案
|
aredfish
一般會員 ![]() ![]() 發表:47 回覆:41 積分:17 註冊:2002-12-04 發送簡訊給我 |
|
taishyang
站務副站長 ![]() ![]() ![]() ![]() ![]() ![]() 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
|
aredfish
一般會員 ![]() ![]() 發表:47 回覆:41 積分:17 註冊:2002-12-04 發送簡訊給我 |
|
bruce0211
版主 ![]() ![]() ![]() ![]() ![]() 發表:157 回覆:668 積分:279 註冊:2002-06-13 發送簡訊給我 |
引言: aredfish您好: 若是單純讓水平的ScrollBar出現可以使用下面方式try try see ..SetScrollRange(FileListBox1->Handle, SB_HORZ, 0, 10, true);不過實際上是沒有效用的< > 您可以再等前輩們指導< > 發表人 - taishyang 於 2004/03/09 19:51:12 //讓ListBox有水平捲軸 int maxwidth =0; const int border = 3; for (int ii=0;ii |
ENIX007
高階會員 ![]() ![]() ![]() ![]() 發表:28 回覆:274 積分:185 註冊:2003-11-27 發送簡訊給我 |
aredfish您好
提供您一些想法,除非您有要用到FileListBox元件的特殊功能,如果只是單純
要Show的話,使用ListBox就能達到您的要求了,剛嚐試的結果,ListBox增加
Column屬性就會自動產生水平捲軸,FileListBox卻沒有Column屬性...
這也是頗令人百思不解之處,因為它們都繼承於TCustomListBox...
如果一定要用FileListBox的話,小弟之前的做法是使用Hint的方式來補足...
不過這是個消極的做法就是了...
------
程式迷人之處,在於邏輯思考,然而卻也是惱人之處~~ |
m8815010
版主 ![]() ![]() ![]() ![]() ![]() 發表:99 回覆:372 積分:289 註冊:2003-11-13 發送簡訊給我 |
引言: 大家好,我的程式上面有一個FileListBox元件,我用它來顯示出某個目錄下面 的檔案,但我發現一個問題,當我的檔名很長時它無法顯示出所有的檔名 也就是說這個元件的底部少了一個可以左右移動的ScrollBar,所以想請教一下 大家該如何去解決這一個問題,謝謝大家!!!aredfish你好< >: 這個問題其實很簡單,就觀念上< >! 即: 1. FileListBox沒有水平ScrollBar 2. 想要 3. 自已給一個ScrollBar 4. ScrollBar沒做用(當然) 5. 自已加程式讓它有做用 6. ScrollBar可以做用,FileListBox會跟它水平移動 範例: 1. 右邊是ListBox的範例,因為ListBox有DrawItem事件比較好處理 2. ListBox用DrawItem事件時,要先將style屬性切為lbOwnerDrawVariable 3. 左邊是FileListBox範例,FileListBox沒有DrawItem事件,所以要自已攔訊息(WM_DRAWITEM),比較麻煩 程式碼: In Unit.h ~~ class TForm1 : public TForm { __published: // IDE-managed Components TListBox *ListBox1; TScrollBar *ScrollBar1; TFileListBox *FileListBox1; TScrollBar *ScrollBar2; void __fastcall ListBox1DrawItem(TWinControl *Control, int Index, TRect &Rect, TOwnerDrawState State); void __fastcall ScrollBar1Scroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos); void __fastcall FormCreate(TObject *Sender); void __fastcall ScrollBar2Scroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos); private: // User declarations void __fastcall FormWndProc(TMessage&); <---注意WM_DRAWITEM訊息是要在Form攔 TWndMethod OldFormWndProc; public: // User declarations __fastcall TForm1(TComponent* Owner); }; ~~ In Unit.cpp [green] ~~ TForm1 *Form1; int ScrollPosition; int ScrllPos; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { OldFormWndProc=Form1->WindowProc; Form1->WindowProc=FormWndProc; } //--------------------------------------------------------------------------- void __fastcall TForm1::ListBox1DrawItem(TWinControl *Control, int Index, TRect &Rect, TOwnerDrawState State) { ListBox1->Canvas->FillRect(Rect); ListBox1->Canvas->TextOut(Rect.Left-ScrollPosition, Rect.Top+1, ListBox1->Items->Strings[Index].c_str()); } //--------------------------------------------------------------------------- void __fastcall TForm1::ScrollBar1Scroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { ScrollPosition=ScrollPos; ListBox1->Repaint(); } //--------------------------------------------------------------------------- 下面為FileListBox部份 void __fastcall TForm1::FormWndProc(TMessage& Message) { if (Message.Msg==WM_DRAWITEM) { DRAWITEMSTRUCT* drawitemstruct; drawitemstruct=(LPDRAWITEMSTRUCT)Message.LParam; if (Message.WParam==(LONG)FileListBox1->Handle) { RECT rect=drawitemstruct->rcItem; FileListBox1->Canvas->FillRect(rect); FileListBox1->Canvas->TextOutA(rect.left-ScrllPos,rect.top+1,FileListBox1->Items->Strings[drawitemstruct->itemID].c_str()); return; } } OldFormWndProc(Message); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { //注意初始的設定 FileListBox1->ApplyFilePath("c:\\test"); ScrollBar2->Max=200; } //--------------------------------------------------------------------------- void __fastcall TForm1::ScrollBar2Scroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { ScrllPos=ScrollPos; FileListBox1->Repaint(); } //---------------------------------------------------------------------------初始狀況: |
taishyang
站務副站長 ![]() ![]() ![]() ![]() ![]() ![]() 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
|
aredfish
一般會員 ![]() ![]() 發表:47 回覆:41 積分:17 註冊:2002-12-04 發送簡訊給我 |
|
m8815010
版主 ![]() ![]() ![]() ![]() ![]() 發表:99 回覆:372 積分:289 註冊:2003-11-13 發送簡訊給我 |
引言: m8815010大大您好,謝謝您的回答,我試過您的範例 不過不會動 |
aredfish
一般會員 ![]() ![]() 發表:47 回覆:41 積分:17 註冊:2002-12-04 發送簡訊給我 |
|
m8815010
版主 ![]() ![]() ![]() ![]() ![]() 發表:99 回覆:372 積分:289 註冊:2003-11-13 發送簡訊給我 |
引言: 因為我本身並不具備任何有關Windows訊息的知識 甚至常識啊呀!aredfish你這樣一講我就瞭解了,原來如此!好險我沒繼續查我的程試 |
aredfish
一般會員 ![]() ![]() 發表:47 回覆:41 積分:17 註冊:2002-12-04 發送簡訊給我 |
|
m8815010
版主 ![]() ![]() ![]() ![]() ![]() 發表:99 回覆:372 積分:289 註冊:2003-11-13 發送簡訊給我 |
引言: 謝謝m8815010大大的幫忙,所以您的意思是說我必須去找一個訊息 這個訊息是在當FileListBox重畫的時候會被觸發,然後會把這個訊息傳到 Panel去,所以我才能收的到~~~也就因為這樣,所以WM_DRAWITEM不能用 必須要再去找一個WM_xxxx的東西來用...是這樣子嗎?? |
aredfish
一般會員 ![]() ![]() 發表:47 回覆:41 積分:17 註冊:2002-12-04 發送簡訊給我 |
|
aredfish
一般會員 ![]() ![]() 發表:47 回覆:41 積分:17 註冊:2002-12-04 發送簡訊給我 |
|
m8815010
版主 ![]() ![]() ![]() ![]() ![]() 發表:99 回覆:372 積分:289 註冊:2003-11-13 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |