Sunday, April 29, 2018

MSHFlexGrid-set Column width, Color, Font and Grid style VB6

MSHFlexGrid-set Column width, Color, Font and Grid style VB6

Whenever we want to show data in list with stylish look. There is many coding process to give attractive look to your application. And SKOTechLearn description the process to design attractive look of MSHFlexGrid. This control provide the settings of Column width, Color, Font and Grid Style in VB6.0.

This control contain settings to process on some properties to give attractive look. Just adjust column width and set attractive color to columns and design every column with different font and also design attractive Grid style.

First of all, find and add this control to Toolbox, For understanding purpose just add some record in this control.

This component provide a look that Listview control cannot provide.

Grid Style example:
Take a look of this component.
Image of MSHFlexGrid advance Look
MSHFlexGrid advance Look
There is following point of this control's advance feature.

(1) Design Text and Cell Style
(2) Column Width setting
(3) Text Alignment setting
(4) Design Background, Font and Grid Color
(5) Design Font setting in every Column

(1) Design Text and Cell Style:
If you want to design text and column style, this will done through setting on properties or through code.

Text and Cell Style through Properties Settings:
Go to "Properties Window", and find 'GridLines' and select related option which want to apply, this can design rows and cols style except Fixed rows and cols. After that find 'GridLinesFixed' and select related option. This can design fixed cols and row style.

Note: 'GridLines' and 'GridLinesFixed' will apply the style of Cols and rows or it can be apply on cell's style.


After that find 'TextStyle' and select related option, this will process on Text style except Fixed text. After that find 'TextStyleFixed' and select related option. This can process on fixed text style.
Grid and Text Settings for MshFlexGrid
GridLines and TextStyle Settings
Text and Cell Style through Code:
Write following code on command button. Suppose we drag command button from Toolbox to Form and set its Name as 'Style_Cmd'. Write on its click event as shown bellow.

We will change MSHFlexGrid1's Name as "MGrid1".

Code:
Private Sub Style_Cmd_Click()

With MGrid1

.GridLinesFixed = flexGridInset
.TextStyleFixed = flexTextRaisedLight

.TextStyle = flexTextRaised
.GridLines = flexGridRaised

End With

End Sub

(2) Column Width Setting:
Setting up to adjusting column width, just write code for it, there is no option in "Properties Window" to these settings.

Drag command button from Toolbox and set its Name as 'Change_Width_Cmd'. Write on its click event as shown bellow.

Private Sub Change_Width_Cmd_Click()

With MGrid1

.ColWidth(0) = 600
.ColWidth(1) = 2300
.ColWidth(2) = 700
.ColWidth(3) = 1500

End With

End Sub
You have to give col number (like: 0, 1, 2, 3 etc) in 'ColWidth()' property. And give width value in it.

(3) Text Alignment Setting:
Setting up to process on Text alignment of cols or Fixed columns, just write code for it, here is no way to process through "Properties Window". Now come to the event window.

Drag command button and modify its Name as 'Change_Align_Cmd' and write on its Click() event as shown bellow.

Private Sub Change_Align_Cmd_Click()

With MGrid1
'For Fixed column Alignment
.ColAlignmentFixed(0) = 3
.ColAlignmentFixed(1) = 3

'For column Alignment
.ColAlignment(1) = 3
.ColAlignment(2) = 3

End With

End Sub
Setting alignment through number. The following number describes the alignment adjustment.

0-Justify or Default Alignment
1-Left Alignment
3-Middle Alignment


(4) Design Background , Font and Grid Color :
If you want to design cols and row's back, Font and Grid color, go to "Properties Window" with following related settings.

Background:
BackColor: This is cell’s back color property.
BackColorBkg: This is background back color property.
BackColorFixed: This is Fixed cell’s back color property.
BackColorSel: This is cell’s selection back color property.
BackColorUnpopulated: This is unpopulated cell’s back color property.
Font:
ForeColor: Cell’s Font color property.
BackColorFixed: Fixed cell’s Font color property.
ForeColorSel: Cell’s selection’s Font color property.
Grid:
GridColor: For cell’s Grid Line
GridColorFixed: For Fixed cell’s Grid Line
GridColorUnpopulated: For changing unpopulated cell’s Grid Line
You can apply this settings through properties window or set back and font color through coding. Drag command button from Toolbox and set its Name as 'Change_Color_Cmd' and write code in its click event as described below.
Color Settings for MSHFlexgrid Style
Color Settings
Private Sub Change_Color_Cmd_Click()

With MGrid1
'For Back color
.BackColor = &HC0FFFF
.BackColorBkg = &HFAF1DA
.BackColorFixed = &HCC93C2
.BackColorSel = &H808000

'For Font Color
.ForeColor = &HC0&
.ForeColorFixed = &H400000
.ForeColorSel = &HFFFF&

'For Grid Line Color
.GridColor = &HFF00FF
.GridColorFixed = &HFF0000
.GridColorUnpopulated = &H80C0FF

End With

End Sub

(5) Design Font setting in every Column:
For changing Fixed cols font and Related cols font, process through "Properties Window". But if you process on every column with different font write code for it. Drag command button from Toolbox and modify its Name as 'Change_Font_Cmd' and write code on its click event as shown below.

Private Sub Change_Font_Cmd_Click()

With MGrid1
 'set font of col 1 and row 1,2,3 etc number
.Col = 1
.Row = 1
.CellFontName = "Calibri"
.CellFontSize = 11

.Row = 2
.CellFontName = "Calibri"
.CellFontSize = 11
'set  Font of col 2 and row 1,2,3 etc number
End With

End Sub
The following image describe above given 5 point.
advance feature for set MSHFlexGrid Style
Output with advance feature
There is the setting of Style through output with different style change.

Advance Feature tips to change Column's width, Color, Font, Grid style in MSHFlexGrid in vb6.0 at runtime (SKOTechLearn).

0 comments: