Free Web site hosting - Freeservers.com | Web Hosting - GlobalServers.com
Choose an ISP: NetZero High Speed Internet Dial up $14.95 or NetZero Internet Service $9.95
 
Placing Tabs to the Left, Right, or Bottom

With the introduction of IE 3 (comctrl32 version 4.70) TabControls and PageControls received support for placing the tabs at any of the sides -- left, right, bottom, as well as the top.  The new styles can be added at run-time, but the font for the tabs won't rotate for vertical placement.  It's best to override the CreateParams() method of a new component derived from TTabControl (or TPageControl) and specify the styles there.
 

KEYWORDS: CreateParams, TCS_VERTICAL, TCS_BOTTOM, TCS_RIGHT



 

//in header...
//---------------------------------------------------------------------------
#ifndef MyTabControlH
#define MyTabControlH
//---------------------------------------------------------------------------
#include <vcl\SysUtils.hpp>
#include <vcl\Controls.hpp>
#include <vcl\Classes.hpp>
#include <vcl\Forms.hpp>
#include <vcl\ComCtrls.hpp>
//---------------------------------------------------------------------------

#define TCS_VERTICAL    0x0080
#define TCS_RIGHT       0x0002
#define TCS_BOTTOM      0x0002

//---------------------------------------------------------------------------
enum TTabOrientation {toBottom, toLeft, toRight, toTop}; 

class TMyTabControl : public TTabControl
{
private:
    TTabOrientation FTabOrientation;
    void __fastcall SetTabOrientation(TTabOrientation Value);

protected:
    virtual void __fastcall CreateParams(TCreateParams &Params);
public:
    __fastcall TMyTabControl(TComponent* Owner);
__published:
    __property TTabOrientation TabOrientation = {read = FTabOrientation,
                                                 write = SetTabOrientation};
};
//---------------------------------------------------------------------------
#endif

 


 
 

//in implementation...
//---------------------------------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop

#include "MyTabControl.h"
//---------------------------------------------------------------------------
static inline TMyTabControl *ValidCtrCheck()
{
    return new TMyTabControl(NULL);
}
//---------------------------------------------------------------------------

__fastcall TMyTabControl::TMyTabControl(TComponent* Owner)
        : TTabControl(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TMyTabControl::CreateParams(TCreateParams &Params)
{
    TTabControl::CreateParams(Params);
    switch (FTabOrientation)
    {
        case toBottom:
            Params.Style = Params.Style | TCS_BOTTOM;
            break;
        case toLeft:
            Params.Style = Params.Style | TCS_VERTICAL | TCS_MULTILINE;
            MultiLine = true;
            break;
        case toRight:
            Params.Style = Params.Style | TCS_VERTICAL | TCS_MULTILINE |
                           TCS_RIGHT;
            MultiLine = true;
            break;
        }
}
//---------------------------------------------------------------------------

void __fastcall TMyTabControl::SetTabOrientation(TTabOrientation Value)
{
    if (FTabOrientation != Value)
    {
        FTabOrientation = Value;
        RecreateWnd();
    }
}
//---------------------------------------------------------------------------

namespace Mytabcontrol
{
    void __fastcall Register()
    {
        TComponentClass classes[1] = {__classid(TMyTabControl)};
        RegisterComponents("Samples", classes, 0);
    }
}