小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

vb中msflexgrid的使用舉例

 悟靜 2009-07-28
 
1月28日

vb中msflexgrid的使用舉例(轉(zhuǎn))

1、 將文本賦值給MsFlexGrid的單元格
MsFlexGrid.TextMatrix(3,1)=”Hello”

2、 在MsFlexGrid控件單元格中插入背景圖形
Set MsFlexGrid.CellPicture=LoadPicture(“C:\temp\1.bmp”)

3、選中某個(gè)單元
MsFlexGrid.Row=1
MsFlexGrid.Col=1

4、用粗體格式化當(dāng)前選中單元
MsFlexGrid.CellFontBold=True

5、 添加新的一行
使用AddItem方法,用Tab字符分開不同單元格的內(nèi)容
dim row as string
row=”AAA”&vbtab&”bbb”
MsFlexFrid1.addItem row


6、怎樣來(lái)實(shí)現(xiàn)MSFlexGrid控件單數(shù)行背景為白色,雙數(shù)的行背景為藍(lán)色?
    Dim i As Integer
    With MSFlexGrid1
         .AllowBigSelection = True    ’ 設(shè)置網(wǎng)格樣式
         .FillStyle = flexFillRepeat
         For i = 0 To .Rows - 1
             .Row = i: .Col = .FixedCols
             .ColSel = .Cols() - .FixedCols - 1
             If i Mod 2 = 0 Then
                .CellBackColor = &HC0C0C0    ’ 淺灰
             Else
                .CellBackColor = vbBlue ’ 蘭色
             End If
         Next i
     End With

7、MSFlexGrid控件如何移到最后一行
MSFlexGrid1.TopRow = MSFlexGrid1.Rows – 1

8、如何判斷msflexgrid有無(wú)滾動(dòng)條
Declare Function GetScrollRange Lib "user32" (ByVal hWnd As Long, ByVal nBar As Long, lpMinPos As Long, lpMaxPos As Long) As Long
Public Const SB_HORZ = &H0
Public Const SB_VERT = &H1

Public Function VsScroll(MshGrid As MSHFlexGrid) As Boolean           ’判斷水平滾動(dòng)條的可見性
Dim i As Long
VsScroll = False
i = GetScrollRange(MshGrid.hWnd, SB_HORZ, lpMinPos, lpMaxPos)
If lpMaxPos <> lpMinPos Then VsScroll = True
End Function

Public Function HeScroll(MshGrid As MSHFlexGrid) As Boolean           ’判斷垂直滾動(dòng)條的可見性
Dim i As Long
HeScroll = False
i = GetScrollRange(MshGrid.hWnd, SB_VERT, lpMinPos, lpMaxPos)
If lpMaxPos <> lpMinPos Then HeScroll = True
End Function

9、程序運(yùn)行時(shí),想動(dòng)態(tài)增加MSFlexgrid的列數(shù)
在第2列后插入一列:
Private Sub Form_Load()
Me.MSHFlexGrid1.Cols = 5
MSHFlexGrid1.Rows = 2
For i = 0 To Me.MSHFlexGrid1.Cols - 1
Me.MSHFlexGrid1.TextMatrix(0, i) = i
Me.MSHFlexGrid1.TextMatrix(1, i) = i
Next
End Sub

Private Sub Command1_Click()
Me.MSHFlexGrid1.Cols = Me.MSHFlexGrid1.Cols + 1
Me.MSHFlexGrid1.ColPosition(5) = 3
End Sub

10、 MSFlexGrid中的對(duì)齊功能的使用
設(shè)置MSFlexGrid1.ColAlignment(index)=n


11、得到MSFlexGrid控件中當(dāng)前選中的一行
msflexgrid1.rowsel就是當(dāng)前選中行

12、 如何通過(guò)代碼調(diào)節(jié)列寬度
msflexgrid1.colwidth(i)=4000
增加 MsFlexGrid 的編輯功能 [轉(zhuǎn)帖]
概述
MsFlexGrid 控件沒有提供文本編輯的功能,下面的例子演示了如何利用一個(gè)TextBox 實(shí)現(xiàn)編輯當(dāng)前網(wǎng)格的功能。

在按下一個(gè)鍵后, 就把TextBox 移動(dòng)到當(dāng)前的位置, 并激活。 在鍵入回車或移動(dòng)到其他網(wǎng)格時(shí), 就把TextBox 中的內(nèi)容放到網(wǎng)格中。

實(shí)現(xiàn)步驟
1 打開 VB5, 開啟一個(gè)新的工程。

2 在菜單“工程” 中選擇 “部件”, 在列表中選中 “Microsoft FlexGrid Control ..”

3 放一個(gè) MsFlexGrid 控件和一個(gè)TextBox 控件(Text1)到 Form1。 修改MsFlexGrid 控件的名稱為 Grid1, 設(shè)置Grid1 的行,列 為 4, 固定行,列為 0。 設(shè)置 Text1 的 Visiable 為 False, BorderStyle 為 None(0)。

4 在Form1 的代碼中增加聲明:

Const ASC_ENTER = 13 '回車
Dim gRow As Integer
Dim gCol As Integer

5 增加代碼到 Grid_KeyPress 過(guò)程:

Private Sub Grid1_KeyPress(KeyAscii As Integer)
' Move the text box to the current grid cell:
Text1.Top = Grid1.CellTop + Grid1.Top
Text1.Left = Grid1.CellLeft + Grid1.Left
' Save the position of the grids Row and Col for later:
gRow = Grid1.Row
gCol = Grid1.Col
' Make text box same size as current grid cell:
Text1.Width = Grid1.CellWidth - 2 * Screen.TwipsPerPixelX
Text1.Height = Grid1.CellHeight - 2 * Screen.TwipsPerPixelY
' Transfer the grid cell text:
Text1.Text = Grid1.Text
' Show the text box:
Text1.Visible = True
Text1.ZOrder 0 ' 把 Text1 放到最前面!
Text1.SetFocus
' Redirect this KeyPress event to the text box:
If KeyAscii <> ASC_ENTER Then
SendKeys Chr$(KeyAscii)
End If
End Sub

6 增加代碼到 Text1_KeyPress 過(guò)程:

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = ASC_ENTER Then
Grid1.SetFocus ' Set focus back to grid, see Text_LostFocus.
KeyAscii = 0 ' Ignore this KeyPress.
End If
End Sub

7 增加代碼到 Text1_LostFocus 過(guò)程:

Private Sub Text1_LostFocus()
Dim tmpRow As Integer
Dim tmpCol As Integer
' Save current settings of Grid Row and col. This is needed only if
' the focus is set somewhere else in the Grid.
tmpRow = Grid1.Row
tmpCol = Grid1.Col
' Set Row and Col back to what they were before Text1_LostFocus:
Grid1.Row = gRow
Grid1.Col = gCol
Grid1.Text = Text1.Text ' Transfer text back to grid.
Text1.SelStart = 0 ' Return caret to beginning.
Text1.Visible = False ' Disable text box.
' Return row and Col contents:
Grid1.Row = tmpRow
Grid1.Col = tmpCol
End Sub

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多