2007-03-02 08:24:01| 分类: Visual Basic | 标签: |举报 |字号大中小 订阅
1.引用Microsoft FlexGrid Control 6.0(SP6)
2.在窗体中添加MSFlexGrid1,TextBox text1。
3.双击将显示文本框并可以编辑内容。
4.在文本框中输入内容后,如果鼠标双击或在其他单元格单击或回车MSFlexGrid1的内容将被更新为Text1的文本。
5.Form_Resize()作用是根据窗体大小的变化自动调节窗体内的控件位置。
6.窗体有个固定宽度和高度 105*510
代码:
Dim i As Integer
Dim j As Integer
Private Sub Form_Resize()
With MSFlexGrid1
Frame1.Width = Me.Width - Frame1.Left * 2 - 105
.Width = Me.Width - .Left * 2 - 105
.Height = Me.Height - .Top * 2 - 510 - Frame1.Height - 20
Frame1.Top = .Height + .Top
End With
End Sub
Private Sub MSFlexGrid1_DblClick()
With MSFlexGrid1
i = .Col
j = .Row
Text1.Move .Left + .CellLeft, .Top + .CellTop, .CellWidth, .CellHeight
Text1.Text = .Text
Text1.Visible = True
Text1.SetFocus
End With
End Sub
Private Sub MSFlexGrid1_LeaveCell()
Call SetText
End Sub
Private Sub Text1_DblClick()
Call SetText
End Sub
Sub SetText()
If i = 0 Or j = 0 Then
Exit Sub
End If
MSFlexGrid1.TextMatrix(j, i) = Text1.Text
Text1.Visible = False
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
Call SetText
End If
End Sub
效果图:
评论