Grega
Well, TTabsheet does not derive from TScrollingWinControl, so it has no
support for your requirements. But Windows basically supports scrollbars on
*any* control, you just have to write all the code for scrolling etc.
yourself.
Here is a starter pack <g>. The controls are all on the tabsheet.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls;
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)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
RadioGroup1: TRadioGroup;
GroupBox1: TGroupBox;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
ComboBox1: TComboBox;
private
{ Private declarations }
public
{ Public declarations }
end;
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;
--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be
SNIP
> I know I could use scrollbox on tab sheet but is out of the question as I
> need controls right on the tab sheet because of the streaming I will be
> using.
Whoa...back up. Why is that a problem?
John Elrick
Grega
"John Elrick" <jel...@adelphia.net> wrote in message
news:3ec007e4$1...@newsgroups.borland.com...
Grega
"Peter Below (TeamB)" <10011...@compuXXserve.com> wrote in message
news:VA.00009e3...@antispam.compuserve.com...
SNIP
> scrollbox as well. So, just problems.
Yea...that's the least of it. I think you are taking some serious shortcuts
here that will end up biting you in the butt.
First, _everything_ you put on the form will by default have the Form as an
Owner. Even if you create them at runtime, when you stream them back
in...guess who the owner is.
So, freeing the PageControl probably won't free all the controls on the
tabsheets. Simple solution (of course there is one)...create a Frame which
is embedded into the TabSheet. You can pretty much guarantee that the Frame
will own everything dropped on it, you can easily and safely Free the Frame
and it's pretty durn easy to save and load it and its contents from a
stream.
As a plus, Frame supports scroll bars.
The downside is that you won't just be able to stream the entire control,
you'll have to do it a page at a time...but that's a lot more flexible
anyhow.
John
You can put it into a unit of its own and add that to your Interface-section
Uses clause. It has to appear *after* ComCtrls.
Grega
"John Elrick" <jel...@adelphia.net> wrote in message
news:3ec0ed41$1...@newsgroups.borland.com...
Depends on what you are attempting to do. In theory, you shouldn't have any
problem with streaming the ScrollBox either, since it is Parented to the
TabSheet.
John
If things are working now because all your controls are created at run-time
without
the form as the owner, then why not just create the ScrollBox as run-time
also? Either
this or set the scrollbox's owner to the TabPanel? Then your streaming
should work as
it does before.
Thanks,
Brett
"Grega Loboda" <grega....@email.si> wrote in message
news:3ec20b53$1...@newsgroups.borland.com...
Grega
"Brett Watters" <bwat...@geometrix.bc.ca> wrote in message
news:3ec2...@newsgroups.borland.com...
Right...you have to free it first or you'll get the error.
Same thing with anything else you stream in. Easy way to handle it. Put
PageControl on a Panel and set the PageControl to alClient.
procedure TForm1.LoadStuff(const aStream: TStream);
var
localIsLocked : boolean;
begin
localIsLocked := LockWindowUpdate(Self.Handle);
if not localIsLocked then
Exit;
try
PageControl1.Free;
...load your stuff onto the panel. Don't remember exact syntax off the
top of my head
finally
LockWindowUpdate(0);
end;
end;