microsoft visual basic 6 (advance activex control)

28
Visual Basic Advance ActiveX Control Creating a Menu The menu gives the users access to functions that are not defined as controls (editing, formatting, etc) and also repeats certain functions that are coded as controls (Exit button, for example). Menus offer a variety of functionalities to define the application: we can include sub-menus, checked items, enabled/disabled functions. We use the Menu Editor that can be found in the Menu bar --> Tools or Press CTRL+E in design window. Menu Editor Dialog Box Options Options Description Caption Allows you to enter the menu name that you want to appear on your menu bar.If you want to create a separator bar in your menu, type a single hyphen (-) in the Caption box.To give the user keyboard access to a menu item, insert an ampersand (&) before a letter. If you need an ampersand to show in the menu, put two consecutive ampersands in the caption. Name Allows you to enter a control name for the menu item. A control name is an identifier used only to access the menu item in code. Index Allows you to assign a numeric value that determines the control's position within a control array.This position isn't related to the screen position. Shortcut Allows you to select a shortcut key for each command. Checked Allows you to have a check mark appear initially at the left of a menu item. It is generally used to indicate whether a toggle option is turned on or off. Enabled Allows you to select whether you want the menu item to respond to events, or clear if you want the item to be unavailable and appear dimmed. Visible Allows you to have the menu item appear on the menu. WindowList Determines if the menu control contains a list of open MDI child forms in an MDI application.

Upload: abdul-majeed-khan

Post on 06-Apr-2015

519 views

Category:

Documents


8 download

DESCRIPTION

[email protected]

TRANSCRIPT

Page 1: Microsoft Visual Basic 6 (Advance ActiveX Control)

Visual Basic Advance ActiveX ControlCreating a MenuThe menu gives the users access to functions that are not defined as controls (editing, formatting, etc) and also repeats certain functions that are coded as controls (Exit button, for example). Menus offer a variety of functionalities to define the application: we can include sub-menus, checked items, enabled/disabled functions. We use the Menu Editor that can be found in the Menu bar --> Tools or Press CTRL+E in design window.

Menu Editor Dialog Box OptionsOptions DescriptionCaption Allows you to enter the menu name that you want to appear on your

menu bar.If you want to create a separator bar in your menu, type a single hyphen (-) in the Caption box.To give the user keyboard access to a menu item, insert an ampersand (&) before a letter. If you need an ampersand to show in the menu, put two consecutive ampersands in the caption.

Name Allows you to enter a control name for the menu item. A control name is an identifier used only to access the menu item in code.

Index Allows you to assign a numeric value that determines the control's position within a control array.This position isn't related to the screen position.

Shortcut Allows you to select a shortcut key for each command.Checked Allows you to have a check mark appear initially at the left of a menu

item. It is generally used to indicate whether a toggle option is turned on or off.

Enabled Allows you to select whether you want the menu item to respond to events, or clear if you want the item to be unavailable and appear dimmed.

Visible Allows you to have the menu item appear on the menu.WindowList

Determines if the menu control contains a list of open MDI child forms in an MDI application.

Right Arrow

Moves the selected menu down one level each time you click it. You can create up to four levels of submenus.

Left Arrow Moves the selected menu up one level each time you click it. You can create up to four levels of submenus.

Page 2: Microsoft Visual Basic 6 (Advance ActiveX Control)

Visual Basic Advance ActiveX Control

Up Arrow Moves the selected menu item up one position within the same menu level each time you click it.

Down Arrow

Moves the selected menu item down one position within the same menu level each time you click it.

Menu List A list box that displays a hierarchical list of menu items. Submenu items are indented to indicate their hierarchical position or level.

Next Moves selection to the next line.Insert Inserts a line in the list box above the currently selected lineDelete Deletes the currently selected line.OK Closes the Menu Editor and applies all changes to the last form you

selected. Cancel Closes the Menu Editor and cancels all changes.

Creating Popup/Shortcut Menu (PopupMenu Method)

Displays a pop-up menu on an MDIForm or Form object at the current mouse location. Example-01Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbRightButton Then Form1.PopupMenu mnuedit End IfEnd Sub

The SSTab Control

The SSTab control provides a group of tabs, each of which acts as a container for other controls. Only one tab is active in the control at a time, displaying the controls it contains to the user while hiding the controls in the other tabs.

Options DescriptionCurrent Tab

Display the current tab number.

Tab Count To define the number of tabs.TabsPerRow

To define the number tabs per row.

TabCaption

Define the caption of tab.

Orientation

To allows you to locate the tabs of your tabbed dialog box on either of the four sides (top, bottom, left, right).

Page 3: Microsoft Visual Basic 6 (Advance ActiveX Control)

Visual Basic Advance ActiveX ControlExample-01

Private Sub SSTab1_Click(PreviousTab As Integer) Select Case SSTab1.Tab Case 0 MsgBox "You clicked on " & SSTab1.Caption Case 1 MsgBox "You clicked on " & SSTab1.Caption Case 2 MsgBox "You clicked on " & SSTab1.Caption End SelectEnd SubThe CommonDialog ControlThe CommonDialog control provides a standard set of dialog boxes for operations such as opening and saving files, setting print options, and selecting colors and fonts. The control also has the ability to display help by running the Windows Help engine.

The CommonDialog control can display the following dialogs using the specified method.

Method Dialog Displayed Action/Value

ShowOpen Show Open Dialog Box 1

ShowSave Show Save As Dialog Box 2

ShowColor Show Color Dialog Box 3

ShowFont Show Font Dialog Box 4

ShowPrinter

Show Print or Print Options Dialog Box 5

ShowHelp Invokes the Windows Help Engine 6

FileOpen and FileSave Common Dialog Boxes

Property DescriptionFilter A filter specifies the type of files that are displayed in the dialog box's.DefaultExt Set the default filename extension for the dialog box.FilterIndex

Set a default filter for an Open or Save As dialog box.. The index for the first defined filter is 1.

FileTitleReturns the name (without the path) of the file to open or save.

InitDir Set the initial file directory.Action Set the type of dialog box to be displayed.FileName Returns the path and filename of a selected file.DialogTitle Set the string displayed in the title bar of the dialog box.Flags Set the options for the common dialog boxes.CancelError

Returns a value indicating whether an error is generated when the user chooses the Cancel button.Cancel error number 32755

Flag constant for the file open and file save common dialog box:-

Constant Value DescriptioncdlOFAllowMultiselect &H200 Permits multiple file selection. The user can selected one

more file at run time by the pressing by Shift Key by using Up and Down arrow keys to select the desired file.

cdlOFNExplorer &H80000 Uses the explore like open a dialog box template.

Page 4: Microsoft Visual Basic 6 (Advance ActiveX Control)

Visual Basic Advance ActiveX ControlcdlOFNHelpButten &H10 Display the help button in a dialog box.cdlOFNHideReadOnly &H4 Hide the read only cdOFNReadOnly check box.cdlOFNLongName &H200000 Allows long file name.

Example-01 (File Open) Example-01 (File Save)Private Sub mnuOpen_Click() On Error GoTo ErrHandler cd.DialogTitle = "File Open Dialog Box" cd.Filter = "Text File|*.TXT|Rich Text Format|*.RTF|All Files|*.*" cd.FilterIndex = 1 cd.InitDir = App.Path cd.Flags = &H4 Or &H200000 Or &H10 cd.CancelError = True cd.ShowOpen fName = cd.FileName MsgBox fNameErrHandler: If Err.Number = 32755 Then Exit Sub End IfEnd Sub

Private Sub mnuSave_Click() cd.DialogTitle = "File Save Dialog Box" cd.Filter = "Text File|*.TXT|Rich Text Format|*.RTF" cd.FilterIndex = 1 cd.InitDir = App.Path cd.Action = 2End Sub

Flag constant for the color common dialog box:-

Constant Value

Description

cdCClFullOpen &H2 Display the full dialog box including the define custom color section.

cdlCCHelpButten &H8 Display a help button in a dialog box.cdlCCpreventFullOpen

&H4 Hides the define custom colors section (prevent the user from definig custom color).

cdCCRGBlinit &H1 Set the value of the color initially selected when the dialog box is opened.

Example-01 (Color DialogBox)Private Sub mnuColor_Click() cd.Flags = &H2 cd.ShowColor Text1.BackColor = cd.ColorEnd Sub

Flag constant for the font common dialog box:-

Constant Value DescriptioncdlCFBoth &H3 Display the both printer and screen fonts in the

dialog box. (you must also set the HDC property to specify the current printer).

cdlCFEffects &H100 Specifies that the dialog box let the user set the strike thought underline and color effect.

cdlCFForceFontExist &H10000 Specifies that an error message box appear if the user attempt to select a font or style that doesn’t exist.

cdlCFHelpButten &H4 Display a help butten in a dialog box.cdlCFLimitSize &H2000 Specifies that the dialog box display only font size

whit in the range specified by the min and max properties.

cdlCFScreenFonts &H1 Causes the dialog box to display only the screen fonts supported by the system.

Page 5: Microsoft Visual Basic 6 (Advance ActiveX Control)

Visual Basic Advance ActiveX ControlExample-01 (Font DialogBox)Private Sub mnuFont_Click() cd.Flags = &H1 cd.ShowFont Text1.FontBold = cd.FontBold Text1.FontItalic = cd.FontItalic Text1.Font = cd.FontName Text1.FontSize = cd.FontSizeEnd Sub

Flag constant for the print common dialog box:-

Constant Value DescriptioncdlPDCollacte &H10 Returns or Sets the State of the collate checkbox .cdlPDDisablePrintToFile

&H80000 Disable the print to file checkbox.

cdPDHideToPrintFile &H100000

Hides the print file to checkbox.

cdlPDNoSelection &H4 Disables the selection option butten.cdlPDNoWarning &H80 Prevent a warning message for being displayed

when there is no default printer.Example-01 (Print DialogBox)Private Sub mnuPrint_Click() On Error GoTo ErrHandler Dim BeginPage, EndPage, NumCopies, i cd.CancelError = True cd.ShowPrinter BeginPage = cd.FromPage EndPage = cd.ToPage NumCopies = cd.Copies For i = 1 To NumCopies Printer.Print Text1.Text Next i Exit SubErrHandler: Exit SubEnd Sub

Flag constant for the Help common dialog box:-

Constant Value

Description

cdlHelplContents &H3& Displays the help content. cdlHelpContext &H1& Display help for a particular context. CdlHelpContextPopup &H8& Display a particular help topic in a pop-up of windows

identified by a context number defines in a [map] section of the HPG file.

cdlHelpForceFile &H9& Insurance that win help displays the correct help file. cdlHelpHelpOnHelp &H4& Displays help for using the help application itself.cdlHelpIndex &H3& Displays the index of the specified help file.cdlHelpSetContents &H5& Determines which content’s topic will be displayed

when a user press the F1 key.

The TabStrip Control

A TabStrip control is like the dividers in a notebook or the labels on a group of file folders. By using a TabStrip control, you can define multiple pages for the same area of a window or dialog box in your application.

Page 6: Microsoft Visual Basic 6 (Advance ActiveX Control)

Visual Basic Advance ActiveX Control

Options DescriptionIndex Display the current tab number.Insert Tab To add the tab.Remove Tab

To remove the current tab.

Caption Define the caption of tab.Image To define the image for current tab from imagelist index number.Example-01Private Sub TabStrip1_Click()

If TabStrip1.Tabs(1).Selected Then MsgBox ("you click on " & TabStrip1.Tabs(1).Caption)

ElseIf TabStrip1.Tabs(2).Selected Then MsgBox ("you click on " & TabStrip1.Tabs(2).Caption)

End IfEnd Sub

Page 7: Microsoft Visual Basic 6 (Advance ActiveX Control)

Visual Basic Advance ActiveX Control

The Toolbar Control

A Toolbar control contains a collection of Button objects used to create a toolbar that is associated with an application.

Options DescriptionIndex Display the current Button index number.Caption Define the caption of Button.Key Define the key name of current button for use in coding.Style Define the button style.ToolTipText Define ToolTipText of button to display when mouse over on button.Insert Button To add the button.Remove Button

To remove the current button.

Value Define button status Pressed or Unpressed.Width Define the width for Plaseholder.Image To define the image for current tab from imagelist index number.Button Menus

Use for add more button in Dropdown style button.

Button Style Property Determines Button Behavior

An important property of the Button object is the Style property. The Style property determines how a button behaves — and the function assigned to the button can have a bearing on which style is applied to it. The five button styles are listed below, with their possible uses:

Constant Value Possible Use

tbrDefault 0 Use the Default button style when the function it represents has no dependence on other functions.

tbrCheck 1 The Check style should be used when the function it represents is a toggle of button.

tbrButtonGroup 2 Use the ButtonGroup style when a group of functions are mutually exclusive. That is, only one of the

Page 8: Microsoft Visual Basic 6 (Advance ActiveX Control)

Visual Basic Advance ActiveX Control

functions represented by the group of buttons can be on at a time.

tbrSeparator 3 Use the separator style to create a button that separates one button from another.

tbrPlaceholder 4 The placeholder style functions as a "dummy" button: use this button to create a space on the Toolbar control where you place another control.

tbrDropdown 5 To create the dropdown combo and add ButtonMenus for dropdown.

Events Description

ButtonClickOccurs when the user clicks on a Button object in a Toolbar control.

ButtonDropDownOccurs when the user clicks the dropdown arrow on a Button object.

ButtonMenuClickOccurs when the user clicks a ButtonMenu object.

Example-01Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button) Select Case Button.Index Case 1 MsgBox "You click on New button." Case 2 MsgBox "you click on Open button." End Select 'OR Select Case Button.Caption Case "Save" MsgBox "You click on Save button." End SelectEnd SubExample-02Dim tbrDropdownName As StringPrivate Sub Toolbar1_ButtonDropDown(ByVal Button As MSComctlLib.Button) tbrDropdownName = Button.CaptionEnd SubPrivate Sub Toolbar1_ButtonMenuClick(ByVal ButtonMenu As MSComctlLib.ButtonMenu) If tbrDropdownName = "Font Size" Then Select Case ButtonMenu.Index Case 1: MsgBox "You click on " & ButtonMenu.Text Case 2: MsgBox "You click on " & ButtonMenu.Text Case 3: MsgBox "You click on " & ButtonMenu.Text End Select End IfEnd Sub

Page 9: Microsoft Visual Basic 6 (Advance ActiveX Control)

Visual Basic Advance ActiveX ControlExample-03Placing Controls on the Toolbar You can easily place other controls, such as the ComboBox, TextBox, or OptionButton control, on the Toolbar control at design time.To place other controls on the Toolbar control at design time

Create Button objects and assign appropriate properties. Create a space on the toolbar where you want the other control to appear, then

add a button with the Placeholder style, and set the Width property to an appropriate value.

Draw the other control in the space occupied by the placeholder button.

The CoolBar Control

A CoolBar control contains a collection of Band objects used to create a configurable toolbar that is associated with a form.

Options DescriptionIndex Display the current toolbar index/band number.Child Define the toolbar which is associate to band.Style Define the toolbar style Fixedsize or Normal.Insert Band Add new Band in CoolBar.Remove Band Remove selected Band.

Example-01

Drag coolbar on form. Define Number of Bands Drag Toolbar on Coolbar Band. Run your application and test it.

Page 10: Microsoft Visual Basic 6 (Advance ActiveX Control)

Visual Basic Advance ActiveX Control

The StatusBar Control

A StatusBar control provides a window, usually at the bottom of a parent form, through which an application can display various kinds of status data. The StatusBar can be divided up into a maximum of sixteen Panel objects that are contained in a Panels collection.

Options DescriptionIndex Display the current panel index/panel number.Text Define the Panel caption to display in statusbar.Insert Panel Add new panel in statusbar.Remove Panel Remove selected panel.Alignment Define alignment of current panel text. (Left,Right,Center)Style Define the statusbar style.Bevel Define bevel style (Inset,Raised,Nobevel)AutoSize Define the width of panel text.

The Style Property: Automatic Status Functions

One feature of the StatusBar control is its ability to display key states, time, and date with a minimum of code.

Constant Value

Description

sbrText 0 Text and/or a bitmap. Set text with the Text property.

sbrCaps 1 Displays the letters CAPS in bold when Caps Lock is enabled, and dimmed when disabled.

sbrNum 2 Displays the letters NUM in bold when the number lock key is enabled, and dimmed when disabled.

sbrIns 3 Displays the letters INS in bold when the insert key is enabled, and dimmed when disabled.

sbrScrl 4 Displays the letters SCRL in bold when scroll lock is enabled, and dimmed when disabled.

Page 11: Microsoft Visual Basic 6 (Advance ActiveX Control)

Visual Basic Advance ActiveX Control

sbrTime/ sbrDate 5 , 6 Displays the current time/Date in the system format.

Page 12: Microsoft Visual Basic 6 (Advance ActiveX Control)

Visual Basic Advance ActiveX Control

Settings for the AutoSize property are:

Constant Value Description

sbrNoAutoSize 0 No autosizing occurs.

sbrSpring 1 When the parent form resizes and there is extra space available, all panels with this setting divide the space and grow accordingly. However, the panels' width never falls below that specified by the MinWidth property.

sbrContents 2 The panel is resized to fit its contents.

Example-01 (Accessing panel through code on click event)Private Sub StatusBar1_PanelClick(ByVal Panel As MSComctlLib.Panel) Select Case Panel.Index Case 1: MsgBox "You click on panel " & Panel.Text Case 2: MsgBox "You click on panel " & Panel.Text End SelectEnd SubExample-02 (Design Panel at Run-Time)Private Sub Form_Load() StatusBar1.Panels.Add(1).Text = "Start" StatusBar1.Panels.Add(2).Text = "" StatusBar1.Panels.Add(3).Text = "" StatusBar1.Panels.Add(4).Text = "" StatusBar1.Panels(1).Bevel = sbrRaised StatusBar1.Panels(1).AutoSize = sbrContents StatusBar1.Panels(1).Picture = LoadPicture("c:\windows\Blue Lace 16.bmp") StatusBar1.Panels(2).Bevel = sbrRaised StatusBar1.Panels(2).AutoSize = sbrSpring StatusBar1.Panels(3).Bevel = sbrInset StatusBar1.Panels(3).AutoSize = sbrContents StatusBar1.Panels(3).Style = sbrDate StatusBar1.Panels(4).Bevel = sbrInset StatusBar1.Panels(4).AutoSize = sbrContents StatusBar1.Panels(4).Style = sbrTimeEnd Sub

Page 13: Microsoft Visual Basic 6 (Advance ActiveX Control)

Visual Basic Advance ActiveX Control

The ProgressBar Control

The ProgressBar control shows the progress of a lengthy operation by filling a rectangle with chunks from left to right.Property DescriptionMax Set the maximum value.Min Set the minimum value.Orientation Sets a value that determines the orientation (horizontal or vertical)Scrolling Sets a value that progress bar appears solid or segmented.Value

Returns or sets the value of an object.

Example-01

Private Sub Command1_Click() For X = ProgressBar1.Min To ProgressBar1.Max - 1 ProgressBar1.Value = ProgressBar1.Value + 1 Next XEnd Sub

The Animation Control

The Animation control allows you to create buttons which display animations, such as .avi files, when clicked. The control can play only AVI files that have no sound.Property DescriptionOpen Opens an .avi file to play.Play Plays an .avi file in the Animation control.Stop Stops the play of an .avi file in the Animation control.AutoPlay To allow the Animation control will begin to play an .avi file when

the .avi file is loaded into the control.(True,False)Example-01Private Sub cmdLoad_Click()

Animation1.Open ("c:\windows\clock.avi") Animation1.Play 2

End SubPrivate Sub cmdStop_Click()

Animation1.StopEnd Sub

The UpDown Control

An UpDown control has a pair of arrow buttons which the user can click to increment or decrement a value, such as a scroll position or a value in an associated control, known as a buddy control.Property DescriptionMax Set the maximum value.Min Set the minimum value.BuddyControl

Sets or returns the control used as the buddy control.BuddyProperty Sets the property used to synchronize the UpDown control.Value

Returns or sets the value of an object.

Page 14: Microsoft Visual Basic 6 (Advance ActiveX Control)

Visual Basic Advance ActiveX ControlExample-01

Drag Text control on form Drag UpDown control on form Set Min and Max Property Set BuddyControl property to Text1 (text control name) Set BuddyProperty to Text (text property to display value in text control) Run application and enjoy it

The DateTimePicker Control

The DateTimePicker control enables you to provide a formatted date field that allows easy date selection.Property DescriptionCheckBox Returns or sets a value that determines if a check box is displayed to

the left of the selected date.UpDown Returns or sets a value that determines if an up-down control appears

to the right of the DateTimePicker control.Value

Returns or sets the value of an object.MaxDate

Set the Max Date.MinDate

Set Min Date.Example-01Private Sub Form_Load() DTPicker1.Value = DateEnd SubPrivate Sub Command1_Click() If DTPicker1.CheckBox = True Then If Not IsNull(DTPicker1.Value) Then MsgBox DTPicker1.Value Else MsgBox "Please first select date." End If End IfEnd Sub

The MonthView Control

The MonthView control enables you to create applications that let users view and set date information via a calendar-like interface.Property DescriptionMaxSelCount Sets the maximum number of contiguous days that can be

selected at once.MonthColumns Sets a value that the number of months to be displayed

horizontally.MonthRows Sets a value that the number of months to be displayed

vertically.MultiSelect

To allow that the multiple dates can be selected at once.(True,False)

ScrollRateSets a value that the number of months are scrolled when the user clicks one of the scroll buttons.

ShowWeekNumber Sets a value that the week numbers are displayed next to each

week.StartOfWeek

Returns or sets a value that specifies the starting day of the week.

Page 15: Microsoft Visual Basic 6 (Advance ActiveX Control)

Visual Basic Advance ActiveX ControlValue

Returns or sets the date currently displayed.SelStart (Method)

Returns the upper bounds of the date range that is selected.SelEnd (Method)

Returns the lower bounds of the date range that is selected.

Page 16: Microsoft Visual Basic 6 (Advance ActiveX Control)

Visual Basic Advance ActiveX ControlExample-01Private Sub Form_Load() MonthView1.Top = 0 MonthView1.Left = 0 MonthView1.MonthColumns = 3 MonthView1.MonthRows = 4 MonthView1.StartOfWeek = mvwMonday MonthView1.MinDate = "01/01/2010" MonthView1.MaxDate = "31/12/2010" MonthView1.ShowToday = True Form1.Width = MonthView1.Width + 120 Form1.Height = MonthView1.Height + 430End Sub

The ImageList Control

An ImageList control contains a collection of ListImage objects, each of which can be referred to by its index or key. The ImageList control is not meant to be used alone, but as a central repository to conveniently supply other controls with images.

Option DescriptionGenernal Tab Set Image size.Index Define the index number of image.Key Define the key string of image.Insert Picture Insert image in ImagelistRemove Picture Remove image from Imagelist.Overlay Draws one image from a ListImages collection over anotherExample-01

Drag ImageList control on from Select imagesize and insert images Drag Toolbar and associate imagelist Set Image index with individual toolbar button. Run application

Page 17: Microsoft Visual Basic 6 (Advance ActiveX Control)

Visual Basic Advance ActiveX ControlExample-02

Drag Image control on form Drag command button and write following code.Private Sub Command1_Click() Set Image1.Picture = ImageList1.Overlay(2, 1)End Sub

The RichTextbox Controls

The Rich Textbox control is the core of full-blown word processor. It provides all the functionally of a Textbox control it gives you the capability to mix different fonts,sizes, and attributes.The RTF LanguageRTF is a document formatting language uses simple commands to specify the formatting of a document .Rich Textbox Control`S Properties For Manipulating Selected Text.

Property DescriptionSelText The Selected text.SelStart The position of the selected text`s first character.SelLength The length of selected text. SelBold, SelItalic, SelUnderline, SelStrikeThru, Selcolor, SelFontName,SelFontSize.

Various font attributes of the selected text .

Selindent, SelRighttindent, SelHangingIndent.

The indentation of the selected text.

SelRightMargin, SelLeftMargin

The right/left margin of the selected text.

SelRTF, SelText The RTF/Text code of the selected text.SaveFile(filename) Method Saves the contents of the control to a disk file.LoadFile(filename) Method Loads the contents from a disk file.AutoVerbMenu To display popup menu when the right mouse button is

clicked.BulletIndent Set the amount of bullet indent.SelCharOffset Set the text to appear as a superscript or as a subscript.SelPrint Sends formatted text to a device for printing.SelProtected Returns or sets a value which determines if the current

selection is protected.

Tow file type recognized by the rich textbox control.

Constant Value

Type Description

rtfRTF 0 (default) RTF

The Rich TExtBox control saves its contents as an RTF file.

rtfText 1 Text The RichTextBox control saves its contents as a Text file.

Page 18: Microsoft Visual Basic 6 (Advance ActiveX Control)

Visual Basic Advance ActiveX ControlExample-01Private Sub Form_Load() RTB.Top = 0 RTB.Left = 0 RTB.Width = Form1.Width RTB.Height = Form1.Height RTB.Text = "" Form1.Caption = "WordPad Application" StatusBar1.Panels.Add (1) StatusBar1.Panels(1).Bevel = sbrInset StatusBar1.Panels(1).AutoSize = sbrSpringEnd Sub

Private Sub mnuNew_Click() RTB.Text = "" StatusBar1.Panels(1).Text = ""End SubPrivate Sub mnuOpen_Click() cd.Filter = "Text File|*.txt|Rich Text Format|*.rtf" cd.Flags = cdlOFNHideReadOnly cd.ShowOpen RTB.LoadFile (cd.FileName) StatusBar1.Panels(1).Text = cd.FileNameEnd Sub

Private Sub mnuSave_Click() cd.Filter = "Text File|*.txt|Rich Text Format|*.rtf" cd.Flags = cdlOFNHideReadOnly cd.ShowSave RTB.SaveFile (cd.FileName) StatusBar1.Panels(1).Text = cd.FileNameEnd Sub

Private Sub mnuSubScript_Click() RTB.SelCharOffset = -80End SubPrivate Sub mnuSuperScript_Click() RTB.SelCharOffset = 80End Sub

Private Sub mnuHangingIndent_Click() RTB.SelHangingIndent = 300End Sub

Private Sub mnuBullet_Click() RTB.SelBullet = TrueEnd SubPrivate Sub mnuIndent_Click() RTB.SelIndent = 300End Sub

Private Sub mnuProtected_Click() mnuProtected.Checked = Not mnuProtected.Checked RTB.SelProtected = mnuProtected.CheckedEnd SubPrivate Sub mnuBold_Click() mnuBold.Checked = Not mnuBold.Checked RTB.SelBold = mnuBold.CheckedEnd SubPrivate Sub mnuUnderLine_Click() mnuUnderLine.Checked = Not mnuUnderLine.Checked RTB.SelUnderline = mnuUnderLine.CheckedEnd Sub

Page 19: Microsoft Visual Basic 6 (Advance ActiveX Control)

Visual Basic Advance ActiveX Control

The MSFlexGrid Control

The Microsoft FlexGrid (MSFlexGrid) control displays and operates on tabular data. It allows complete flexibility to sort, merge, and format tables containing strings and pictures. When bound to a Data control, MSFlexGrid displays read-only data.Property/Method

Description

AllowBigSelection

Returns or sets a value that determines whether clicking on a column or row header should cause the entire column or row to be selected.

AllowUserResizing

Returns or sets a value that determines whether the user can use the mouse to resize rows and columns

Cols Returns or sets the total number of columnsRows Returns or sets the total number of rowsFixedCols Returns or sets the total number of fixed columns.FixedRows Returns or sets the total number of fixed rows.FormatString

Sets the column widths, alignments, fixed row text, and fixed column text of the MSHFlexGrid.

MergeCells Returns or sets a value that determines whether cells with the same contents should be grouped in a single cell spanning multiple rows or columns.

SelectionMode Returns or sets a value that determines whether an MSHFlexGrid should allow regular cell selection, selection by rows, or selection by columns.

WordWrap Returns or sets a value that determines whether a cell displays multiple lines of text or one long line of text.

Col Returns or sets the coordinates of the active cell.ColWidth Returns or sets the width of the column in the specified band.Row Returns or sets the coordinates of the active cell.RowHeight Returns or sets the height of the specified row.FixedAlignment Returns or sets the alignment of data in the fixed cells of a

column.MergeCol, MergeRow

Returns or sets a value that determines which rows and columns can have their contents merged. These properties must be True to use the MergeCells property.

MouseCol, MouseRow Returns the current mouse position, in row and column

coordinates.Text Returns or sets the text content of a cell.TextMatrix Returns or sets the text content of a specified column and row.ColSel Returns or sets the start or end column for a range of cells.RowSel Returns or sets the start or end row for a range of cells.

Page 20: Microsoft Visual Basic 6 (Advance ActiveX Control)

Visual Basic Advance ActiveX ControlExample-01Private Sub GridHeader() MSFlexGrid1.Rows = 3 MSFlexGrid1.Cols = 5 MSFlexGrid1.FixedRows = 2 MSFlexGrid1.FixedCols = 0 MSFlexGrid1.WordWrap = True MSFlexGrid1.TextMatrix(0, 0) = "Student Roll Number" MSFlexGrid1.ColWidth(0) = 1000 MSFlexGrid1.FixedAlignment(0) = flexAlignCenterCenter MSFlexGrid1.TextMatrix(0, 1) = "Student Name" MSFlexGrid1.ColWidth(1) = 1500 MSFlexGrid1.FixedAlignment(1) = flexAlignCenterCenter MSFlexGrid1.TextMatrix(0, 2) = "Student Father's Name" MSFlexGrid1.ColWidth(2) = 1500 MSFlexGrid1.FixedAlignment(2) = flexAlignCenterCenter MSFlexGrid1.TextMatrix(0, 3) = "Student Class" MSFlexGrid1.ColWidth(3) = 1000 MSFlexGrid1.FixedAlignment(3) = flexAlignCenterCenter MSFlexGrid1.TextMatrix(0, 4) = "Student Address" MSFlexGrid1.ColWidth(4) = 2000 MSFlexGrid1.FixedAlignment(4) = flexAlignCenterCenter MSFlexGrid1.TextMatrix(1, 0) = "Student Roll Number" MSFlexGrid1.TextMatrix(1, 1) = "Student Name" MSFlexGrid1.TextMatrix(1, 2) = "Student Father's Name" MSFlexGrid1.TextMatrix(1, 3) = "Student Class" MSFlexGrid1.TextMatrix(1, 4) = "Student Address" MSFlexGrid1.MergeCol(0) = True MSFlexGrid1.MergeCol(1) = True MSFlexGrid1.MergeCol(2) = True MSFlexGrid1.MergeCol(3) = True MSFlexGrid1.MergeCol(4) = True MSFlexGrid1.MergeCells = flexMergeRestrictColumnsEnd SubPrivate Sub FillGrid() MSFlexGrid1.Rows = 2 For X = 2 To 10 MSFlexGrid1.Rows = MSFlexGrid1.Rows + 1 MSFlexGrid1.TextMatrix(X, 0) = X - 1 MSFlexGrid1.TextMatrix(X, 1) = Chr(63 + X) MSFlexGrid1.TextMatrix(X, 2) = Chr(87 - X) MSFlexGrid1.TextMatrix(X, 3) = "10-" & Chr(67 + (Int(Rnd * 5))) MSFlexGrid1.TextMatrix(X, 4) = "Flat No. " & Int(Rnd * 50) & " Block # " & Chr(65 + (Int(Rnd * 5))) & " Karachi" Next XEnd SubPrivate Sub Form_Load() Call GridHeader Call FillGridEnd Sub Private Sub MSFlexGrid1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single) MSFlexGrid1.ToolTipText = MSFlexGrid1.TextMatrix(MSFlexGrid1.MouseRow, MSFlexGrid1.MouseCol)End SubExample-02 (Data Entry in Grid)Private Sub Form_Load() MSFlexGrid1.FormatString = "Sr |Student Name |Class |Marks " MSFlexGrid1.Rows = 10 MSFlexGrid1.Cols = 4

Page 21: Microsoft Visual Basic 6 (Advance ActiveX Control)

Visual Basic Advance ActiveX Control MSFlexGrid1.FixedCols = 1 MSFlexGrid1.FixedRows = 1 cboClass.Clear For x = 1 To 10 cboClass.AddItem (x) Next xEnd SubPrivate Sub MSFlexGrid1_EnterCell() If MSFlexGrid1.MouseRow = 0 Then cboClass.Visible = False txtBox.Visible = False Exit Sub ElseIf MSFlexGrid1.Col = 1 Or MSFlexGrid1.Col = 3 Then txtBox.Top = MSFlexGrid1.Top + MSFlexGrid1.CellTop txtBox.Left = MSFlexGrid1.Left + MSFlexGrid1.CellLeft txtBox.Width = MSFlexGrid1.CellWidth txtBox.Height = MSFlexGrid1.CellHeight txtBox.Text = MSFlexGrid1.Text txtBox.Visible = True txtBox.SetFocus ElseIf MSFlexGrid1.Col = 2 Then cboClass.Top = MSFlexGrid1.Top + MSFlexGrid1.CellTop cboClass.Left = MSFlexGrid1.Left + MSFlexGrid1.CellLeft cboClass.Width = MSFlexGrid1.CellWidth cboClass.Visible = True cboClass.SetFocus End IfEnd SubPrivate Sub MSFlexGrid1_LeaveCell() If MSFlexGrid1.Col = 1 Or MSFlexGrid1.Col = 3 Then MSFlexGrid1.Text = txtBox.Text ElseIf MSFlexGrid1.Col = 2 Then MSFlexGrid1.Text = cboClass.Text End IfEnd Sub

Page 22: Microsoft Visual Basic 6 (Advance ActiveX Control)

Visual Basic Advance ActiveX Control

The Clipboard Object

The Clipboard object is used to manipulate text and graphics on the Clipboard. You can use this object to enable a user to copy, cut, and paste text or graphics in your application. Method DescriptionSetData Puts a picture on the system Clipboard.GetData Returns a graphic from the system Clipboard.GetFormat Returns an integer indicating whether an item on the system

Clipboard object matches a specified format.SetText Puts a text string on the system Clipboard.GetText Returns a text string from the system Clipboard.Clear

Clears the contents of a system Clipboard.Example-01Private Sub mnuCopy_Click() Clipboard.SetText Trim(Text1.Text)End SubPrivate Sub mnuCut_Click() Clipboard.SetText Trim(Text1.Text) Text1.Text = ""End SubPrivate Sub mnuPast_Click() Text2.Text = Clipboard.GetTextEnd Sub

The MDIForm Object

An MDI (multiple-document interface) form is a window that acts as the background of an application and is the container for forms that have their MDIChild property set to True.Example-01

Add MDIForm in Project Add one or more form Set MDIChild property to True of other forms Set BorderStyle property to none of other forms (For Scrolling in MDIForm) Drag PictureBox control or create menu on MDIForm Write following code on PictureBox click event or Menu click event

Private Sub Picture1_Click() Form1.ShowEnd Sub