請問PageControl是否可以有ScrollBars的功能. |
尚未結案
|
t0288542
中階會員 發表:216 回覆:254 積分:94 註冊:2004-10-06 發送簡訊給我 |
|
RedSnow
版主 發表:79 回覆:1322 積分:845 註冊:2003-12-15 發送簡訊給我 |
|
wameng
版主 發表:31 回覆:1336 積分:1188 註冊:2004-09-16 發送簡訊給我 |
可以參考
http://groups.google.com/group/borland.public.delphi.language.objectpascal/browse_thread/thread/f57c18394fb70324/8bfc5c9272c0daf3?lnk=st&q=Delphi+TabSheet+Scrollbar&rnum=1&hl=zh-TW#8bfc5c9272c0daf3
type TTabsheet = class( ComCtrls.TTabsheet ) private Procedure WMVScroll( Var msg: TWMSCROLL ); message WM_VSCROLL; Procedure WMHScroll( Var msg: TWMSCROLL ); message WM_HSCROLL; Procedure HandleScrollbar( Var msg: TWMSCROLL; bar: Integer ); protected Procedure Loaded; override; public Procedure CreateParams( var params: TCreateParams ); override; end; TForm1 = class(TForm) .... var Form1: TForm1; implementation {$R *.DFM} { TTabsheet } procedure TTabsheet.CreateParams(var params: TCreateParams); begin inherited; params.style := params.Style or WS_VSCROLL or WS_HSCROLL; end; procedure TTabsheet.WMHScroll(var msg: TWMSCROLL); begin HandleScrollbar( msg, SB_HORZ ); end; procedure TTabsheet.WMVScroll(var msg: TWMSCROLL); begin HandleScrollbar( msg, SB_VERT ); end; procedure TTabsheet.HandleScrollbar(var msg: TWMSCROLL; bar: Integer); var si: TScrollInfo; i,oldpos, dx, dy: Integer; begin msg.result := 0; si.cbSize := Sizeof( TscrollInfo ); si.fMask := SIF_ALL; GetScrollInfo( Handle, bar, si ); oldpos := si.nPos; si.fMask := SIF_POS; { For simplicities sake we use 1 unit as the small scroll increment and 10 as large one } Case msg.ScrollCode Of SB_TOP : si.nPos := si.nMin; SB_BOTTOM : si.nPos := si.nMax; SB_LINEUP : Dec( si.nPos, 1 ); SB_LINEDOWN : Inc( si.nPos, 1 ); SB_PAGEUP : Dec( si.nPos, 10 ); SB_PAGEDOWN : Inc( si.nPos, 10 ); SB_THUMBTRACK, SB_THUMBPOSITION : si.nPos := msg.Pos; SB_ENDSCROLL: Exit; End; si.fMask := SIF_POS; If si.nPos < si.nMin Then si.nPos := si.nMin; If si.nPos > si.nMax Then si.nPos := si.nMax; SetScrollInfo( Handle, bar, si, true ); If bar = SB_VERT Then Begin dy := oldpos - si.nPos; dx := 0; End Else Begin dx := oldpos - si.nPos; dy := 0; End; For i:= 0 to Controlcount-1 Do With controls[i] Do SetBounds( Left dx, Top dy, Width, Height ); end; procedure TTabsheet.Loaded; var i, maxX, maxY: Integer; c: TControl; si: TScrollInfo; begin inherited; maxX := 0; maxY := 0; for i:= 0 to Controlcount-1 do begin c:= controls[i]; c.Align := alNone; // everything else does not work with a scollable parent if (c.Left c.width) > maxX then maxX := c.Left c.Width; if (c.Top c.Height) > maxY then maxY := c.Top c.Height; end; si.cbSize := Sizeof( TscrollInfo ); si.fMask := SIF_ALL; si.nMin := 0; si.nPage := 0; si.nPos := 0; if maxX > clientwidth then begin maxX := maxX GetSystemMetrics( SM_CXVSCROLL ); si.nMax := maxX - ClientWidth ; SetScrollInfo( handle, SB_HORZ, si, true ); end else ShowScrollbar( handle, SB_HORZ, false ); if maxY > clientheight then begin maxY := maxY GetSystemMetrics( SM_CYHSCROLL ); si.nMax := maxY - clientheight; SetScrollInfo( handle, SB_VERT, si, true ); end else ShowScrollbar( handle, SB_VERT, false ); end;~~~~~~~~~~~ 難得聰明,常常糊塗。 ~~~~~~~~~~~ |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |