Please feel free to modify this code in any way you please. If you make any signifigant improvements, upload the files. Suggestions: 3D effects for the Form, more tab styles, multiple focus (one for each row),
MS Sans Serif
Since this control is VB source code and freely modifiable by the user, I didn't feel it was necessary to anticipate every possible usage. Most of this kind of code would need to be removed each time it was used.. For example, the Resize code can be removed if your forms are not sizable.
MS Sans Serif
This control is Freeware. It is based on a similar control written by James Parr and uploaded to compuserve. It is 100% VB code, no DLL's, no VBX's, yet it should perform about as well. This control adds 3D effects, multiple instances, and mixed control types for pages.
MS Sans Serif
V. About this control.
MS Sans Serif
PicBox
Step 4
The tab control is generated by first drawing one tab in the proper size and orientation (invbox) and then blitting this picture to the visible picturebox (tabbox). Rescaling and StretchBlting seemed even more cumbersome than the method used. When a tab is clicked, only the tab captions and the focus line are redrawn. While the speed could be improved a little, the response of the control seems to depend more on the pages and their contents at this point than on the tab element.
MS Sans Serif
Run the project and examine the control. The code controlling the graphic appearance is in DrawTabs(). TabClick() controls the behavior of the tabs when clicked. Try resetting the tb.num and tb.cols values. Note that unused spaces are filled with unlabeled tabs; this was done because of the awkward effect produced when a partial row was moved beneath a full row, so be prepared to tackle this problem if you wish to eliminate unused tabs.
MS Sans Serif
IV. That's it!
MS Sans Serif
PicBox
Step 3
Size the first member of the page() array to the proper size. All the pages will be resized automatically to match it, and the tabbox and Form will be resized to fit it. See the other samples for examples of how to position the tabs on other types of Forms.
MS Sans Serif
If Keycode = H22 then NextPage
Courier New
If Keycode = H21 then PrevPage
Courier New
"tb.orient = 1 ' 0 = up, 1 = down
Courier New
III. Set additional properties.
MS Sans Serif
bIf you wish to handle keyboard events, add code such as the following to the Form's KeyDown event.
MS Sans Serif
sIf you want the tabs to appear below the pages, add the following line to Form_Load before calling DefineControl():
MS Sans Serif
If you wish to set the Font properties of the tab captions, set the properties of the tabbox picturebox to the desired settings.
MS Sans Serif
PicBox
Step 1
I. Creating the controls.
MS Sans Serif
4. Set the tag property of each pictuebox to the text you want to appear on the tab for this page. Add whatever controls you want on each page to the appropriate PicBox()..
MS Sans Serif
3. Create a control array of 6 pictureboxes. (Any control which can act as container can be used instead of pictureboxes.) These are the 'pages'. On this Form, they are PicBox(0) - PicBox(5).
MS Sans Serif
2. Set borderstyle=0 and scalemode=3 on both pictureboxes. Set visible=False on the child picturebox (invbox). Set the backcolor of both boxes and the Form to light grey
MS Sans Serif
x1. Create a picturebox. Create a second picturebox within the first. On this Form, they are named 'tabbox' and 'invbox'.
MS Sans Serif
PicBox
Step 2
II. Adding the code.
MS Sans Serif
33. Add the follwing line to the tabbox_Paint event:
MS Sans Serif
DrawText tabbox, page(), tb
Courier New
)TabClick Button, X, Y, tabbox, page(), tb
Courier New
53. Add the follwing line to the tabbox_MouseUp event:
MS Sans Serif
,DefineControl Me, tabbox, invbox, page(), tb
Courier New
tb.cols = 3
Courier New
-For i = 0 to 5: Set page(i) = PicBox(i): Next
Courier New
ReDim page(0 to 5)
Courier New
22. Add the following lines to the Form_Load event:
MS Sans Serif
Dim tb as TabData
Courier New
Dim page() as control
Courier New
?1. Add the following lines to the general declarations section:
MS Sans Serif
PicBox
Intro
)Several pictureboxes or frames --------->
MS Sans Serif
2 Pictureboxes --------->
MS Sans Serif
Image1
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
pwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
pwwwp
wwwwwwwwwwwwwwwwwwwwwwwwwww
pwwwpwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwwwwwwwwwww
pwwwpwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwwwwwwwwwww
pwwwpwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwwwwwwwwwww
pwwwpwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwwwwwwwwwww
pwwwpwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwwwwwwwwwww
pwwwp
wwwwwwwwwwwwwwwwwwwwwwwwwww
pwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
pwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
E The following tabs explain the steps required to create this sample.
MS Sans Serif
To handle events, add function calls to the KeyPress and Resize events of your Form, and to the MouseUp and Paint events of the tab picturebox.
MS Sans Serif
nThe tab 'control' consists of 2 picture boxes and whatever other controls are needed to implement each 'page':
MS Sans Serif
To create an instance of the tab control, you must declare a page array, a TabData structure, and create the picture boxes and page controls. You then need only call DefineControl() and pass these elements as parameters.