'MSFlexGrid賦值的方法 MSFlexGrid1.TextMatrix(0, 1) = "老師"
創(chuàng)新互聯(lián)是一家專業(yè)提供沁縣企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、H5高端網(wǎng)站建設(shè)、小程序制作等業(yè)務(wù)。10年已為沁縣眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站建設(shè)公司優(yōu)惠進(jìn)行中。
MSFlexGrid1.TextMatrix(1, 2) = "學(xué)生"
MSFlexGrid1.TextMatrix(2, 3) = "校長"
MSFlexGrid1.TextMatrix(3, 4) = "班主任"
MSFlexGrid1.TextMatrix(4, 5) = "教務(wù)主任"
MSFlexGrid1.AddItem 2
MSFlexGrid1.AddItem 4
MSFlexGrid1.AddItem 6
MSFlexGrid1.AddItem 8
``MSFLEXGRID 中如何取的某個(gè)單元格的數(shù)據(jù)
Private Sub MSFlexGrid1_Click()
MsgBox MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, MSFlexGrid1.Col), vbOKOnly, "提示消息"
End Sub
MSFlexGrid1.Row,表格中的當(dāng)前行
MSFlexGrid1.Col,表格中的當(dāng)前列
'初始化MSFlexGrid
Dim i As Integer
MSFlexGrid1.Rows = 0
For i = 0 To 10
MSFlexGrid1.AddItem "AA" + Str(i)
'For i = 0 To 10
MSFlexGrid1.Col = 1
MSFlexGrid1.Row = i
MSFlexGrid1.Text = CStr(i)
MSFlexGrid1.Col = 2
MSFlexGrid1.Row = i
MSFlexGrid1.Text = CStr(i) CStr(i)
MSFlexGrid1.Col = 3
MSFlexGrid1.Row = i
MSFlexGrid1.Text = CStr(i) CStr(i) CStr(i)
Next i'實(shí)現(xiàn)MSFlexGrid控件,單行背景為淺灰,雙行為蘭色
Dim j As Integer
With MSFlexGrid1
.AllowBigSelection = True ' 設(shè)置網(wǎng)格樣式
.FillStyle = flexFillRepeat
For j = 0 To .Rows - 1
.Row = j: .Col = .FixedCols
.ColSel = .Cols() - .FixedCols - 1
If j Mod 2 = 0 Then
.CellBackColor = HC0C0C0 ' 淺灰
Else
.CellBackColor = vbBlue ' 蘭色
End If
Next j
End With '在MsFlexGrid控件單元格中插入背景圖形
Set MSFlexGrid1.CellPicture = LoadPicture("f:\temp\snow.bmp")'MSFlexGrid控件如何移到最后一行
MSFlexGrid1.TopRow = MSFlexGrid1.Rows - 1
'隱藏第一行
'Private Sub Command1_Click1()
'MSFlexGrid1.RowHeight(1) = 0
'End Sub
'隱藏第一列
'Private Sub Command_Click2()
'MSFlexGrid1.ColWidth(1) = 0
'End Sub
在MSFlexGrid上點(diǎn)擊右鍵,選擇屬性,選擇"選擇模式",自己任選
點(diǎn)擊得到行代碼
msgrid1.Col就是你選擇的列號
msgrid1.Row 就是你選擇的行號
msgrid1.text就是你選擇單元格的內(nèi)容。
將文本賦值給MsFlexGrid的單元格
MsFlexGrid.TextMatrix(3,1)=”Hello”
在MsFlexGrid控件單元格中插入背景圖形
Set MsFlexGrid.CellPicture=LoadPicture(“C:\temp\1.bmp”)
選中某個(gè)單元
MsFlexGrid.Row=1
MsFlexGrid.Col=1
用粗體格式化當(dāng)前選中單元
MsFlexGrid.CellFontBold=True
添加新的一行
使用AddItem方法,用Tab字符分開不同單元格的內(nèi)容
dim row as string
row=”AAA”vbtab”bbb”
MsFlexFrid1.addItem row
怎樣來實(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
MSFlexGrid控件如何移到最后一行
MSFlexGrid1.TopRow = MSFlexGrid1.Rows – 1
如何判斷msflexgrid有無滾動條
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 ’判斷水平滾動條的可見性
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 ’判斷垂直滾動條的可見性
Dim i As Long
HeScroll = False
i = GetScrollRange(MshGrid.hWnd, SB_VERT, lpMinPos, lpMaxPos)
If lpMaxPos lpMinPos Then HeScroll = True
End Function
程序運(yùn)行時(shí),想動態(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
請教MSFlexGrid中的對齊功能的使用
設(shè)置MSFlexGrid1.ColAlignment(index)=n
得到MSFlexGrid控件中當(dāng)前選中的一行
msflexgrid1.rowsel就是當(dāng)前選中行
如何通過代碼調(diào)節(jié)列寬度
msflexgrid1.colwidth(i)=4000
--------------------------------------------------------------------------------------
'OutDataToText
'將MsFlexGrid控件中顯示的內(nèi)容輸出到文本文件
Public Sub OutDataToText(Flex As MSFlexGrid)
Dim s As String
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim strTemp As String
On Error GoTo Ert
Me.MousePointer = 11
On Error Resume Next
DoEvents
Dim FileNum As Integer
FileNum = FreeFile
Open "d:aa.txt" For Output As #FileNum
With Flex
k = .Rows
For i = 0 To k - 1
strTemp = ""
For j = 0 To .Cols - 1
DoEvents
strTemp = strTemp .TextMatrix(i, j) ","
Next j
Print #FileNum, Left(strTemp, Len(strTemp) - 1)
Next i
End With
Close #FileNum
Me.MousePointer = 0
MsgBox "導(dǎo)出成功"
Ert:
MsgBox Err.Description
Me.MousePointer = 0
End Sub
增加 MsFlexGrid 的編輯功能
概述
MsFlexGrid 控件沒有提供文本編輯的功能,下面的例子演示了如何利用一個(gè)TextBox 實(shí)現(xiàn)編輯當(dāng)前網(wǎng)格的功能。
在按下一個(gè)鍵后, 就把TextBox 移動到當(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 過程:
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 過程:
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 過程:
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
8 好了。 按 F5 開始測試。 您可以自由地在 Grid 中移動, 按回車可以開始或結(jié)束編輯。
使用MsFlexGrid控件的幾個(gè)函數(shù)
作者:中國論壇網(wǎng)收集 來源: 加入時(shí)間:2004-8-25
在VB處理數(shù)據(jù)顯示的時(shí)候,使用表格是一種好的方法,雖然DataGrid可以與數(shù)據(jù)源綁定,但是總有美中不足,就是
外觀不好看,所以有時(shí)應(yīng)用MsFlexGrid顯示數(shù)據(jù)還是一種比較好的方法,以下幾個(gè)函數(shù)是用來控制MsFlexGrid的程序
(本人語言表達(dá)能力有限,還請見諒)
''MsFlexGrid操作函數(shù)
''合并列
Public Function MergeCol(GridObj As Object, ByVal StartCol As Long, ByVal EndCol As Long, ByVal
ColValue As String, ByVal CurrentRow As Long) As Boolean
If StartCol EndCol Or StartCol GridObj.Cols Or CurrentRow GridObj.Rows Then
MsgBox "對不起,行列設(shè)置錯誤!", vbOKOnly, App.Title
MergeCol = False
Exit Function
End If
For I = StartCol To EndCol
GridObj.MergeCol(I) = True
GridObj.TextArray(faIndex(GridObj, CurrentRow, I)) = ColValue
GridObj.ColAlignment(I) = flexAlignCenterCenter
Next I
GridObj.MergeRow(CurrentRow) = True
MergeCol = True
End Function
''合并行
Public Function MergeRow(GridObj As Object, ByVal StartRow As Long, ByVal EndRow As Long, ByVal
RowValue As String, ByVal CurrentCol As Long) As Boolean
If StartRow EndRow Or StartRow GridObj.Rows Or CurrentCol GridObj.Cols Then
MsgBox "對不起,行列設(shè)置錯誤!", vbOKOnly, App.Title
MergeRow = False
Exit Function
End If
For I = StartRow To EndRow
GridObj.MergeRow(I) = True
GridObj.TextArray(faIndex(GridObj, I, CurrentCol)) = RowValue
GridObj.ColAlignment(CurrentCol) = flexAlignCenterCenter
Next I
GridObj.MergeCol(CurrentCol) = True
MergeRow = True
End Function
''轉(zhuǎn)換索引
Public Function faIndex(GridObj As Object, ByVal row As Integer, ByVal col As Integer) As Long
If row GridObj.Rows Or row 0 Or col GridObj.Cols Or col 0 Then
MsgBox "對不起,行列設(shè)置錯誤!", vbOKOnly, App.Title
faIndex = -1
Exit Function
End If
faIndex = row * GridObj.Cols + col
End Function
''插入行
Public Function SetItem(GridObj As Object, ByVal row As Integer, ByVal col As Integer, ByVal
SetValue As String) As Boolean
If row GridObj.Rows Or row 0 Or col GridObj.Cols Or col 0 Then
MsgBox "對不起,行列設(shè)置錯誤!", vbOKOnly, App.Title
SetItem = False
Exit Function
End If
GridObj.TextArray(faIndex(GridObj, row, col)) = SetValue
SetItem = True
End Function
''得到單元格值
Public Function GetItem(GridObj As Object, ByVal row As Integer, ByVal col As Integer) As String
If row GridObj.Rows Or row 0 Or col GridObj.Cols Or col 0 Then
MsgBox "對不起,行列設(shè)置錯誤!", vbOKOnly, App.Title
GetItem = ""
Exit Function
End If
GetItem = GridObj.TextArray(faIndex(GridObj, row, col))
End Function
在msflexgrid控件中每一個(gè)cell格的內(nèi)容是不可以由用戶直接編輯的但是我們可以通過一些小技
巧來方便的實(shí)現(xiàn)這編輯功能來擴(kuò)展msflexgrid的應(yīng)用(在實(shí)際應(yīng)用中這是很常用的功能)。
你只需按下面的做即可輕松實(shí)現(xiàn)編輯msflexgrid控件數(shù)據(jù)的功能
例在窗體上放一文本框txtvalue,和一msflexgrid控件grid
‘文本框控件的keypress事件
private sub txtvalue_keypress(keyascii as integer)
‘放入一些處理過程,如只需輸入數(shù)字時(shí)的處理
dim i
i=1
end sub
private sub txtvalue_change()
grid.text = txtvalue.text
end sub
'在grid的entercell事件中加入下例代碼
private sub grid_entercell()
txtvalue.text = grid.text
txtvalue.selstart = 0
txtvalue.sellength = len(txtvalue.text)
end sub
'當(dāng)用戶輸入數(shù)據(jù)時(shí)直接調(diào)用文本框的keypress事件
private sub grid_keypress(keyascii as integer)
txtvalue_keypress keyascii
end sub
ok,這樣一個(gè)可編輯的msflexgrid控件就完成了,簡單吧!!
Private Sub fgrid1_click() '單擊MSFlexGrid
sphy = Trim(FGrid1.TextMatrix(FGrid1.Row, 0))
delrecord
End Sub
Private Sub fgrid1_RowColChange()'用上下鍵在MSFlexGrid上選擇
sphy = Trim(FGrid1.TextMatrix(FGrid1.Row, 0))
delrecord
End Sub
Private Sub DeleteRecord()'刪除
Dim I As Integer '
Dim Ssql As String
Dim response As String
response = MsgBox("真的刪除當(dāng)前記錄?", vbInformation + vbYesNo, "警告")
If response = vbYes Then
Ssql = "delete from login where loginname='" sphy "'"
gcnLeaguers.Execute (Ssql)
MsgBox "刪除成功!", vbInformation + vbOKOnly, "系統(tǒng)提示"
End If
Exit Sub
End Sub
刪除后可能還要刷新一下,你試試吧
MSHFlexGrid1.SelectionMode = flexSelectionByRow
還是
Private Sub Form_Load()
With MSHFlexGrid1
.FixedCols = 0
.Cols = 2
.Rows = 0
.AddItem "1" vbTab "11"
.AddItem "2" vbTab "22"
.AddItem "3" vbTab "33"
End With
End Sub
Private Sub MSHFlexGrid1_RowColChange()
Static intPrevRow As Long
If MSHFlexGrid1.Row intPrevRow Then
intPrevRow = MSHFlexGrid1.Row
Dim i As Long
For i = 0 To MSHFlexGrid1.Cols - 1
MsgBox MSHFlexGrid1.TextMatrix(intPrevRow, i)
Next
End If
End Sub
原理
當(dāng)用戶點(diǎn)擊msflexgrid中的某個(gè)cell格要輸入數(shù)據(jù)時(shí),產(chǎn)生entercell事件,在這里我們對文本
框進(jìn)行初始化,輸入當(dāng)前cell格中的內(nèi)容,并且選中所有文本。當(dāng)用戶要按下按鍵進(jìn)行輸入時(shí),就直
接調(diào)用txtvalue的事件,由文本框來處理.
處理的結(jié)果同grid的當(dāng)前cell同步,使用戶編輯cell格就象使用文本框一樣方便。
網(wǎng)格單元格中文字的多行顯示很簡單,只要把WordWarp屬性改為True就可以了。
1.VB6自帶MSHFlexGrid只支持2048條記錄顯示,這個(gè)問題通過裝VB6 的SP6解決.
2.TopRow屬性的使用,這個(gè)屬性可以使用代碼移動MSHFlexGrid的行顯示,如要做一個(gè)從上至下的滾動顯示,使用這個(gè)屬性解決起來非常方便
3.使用選碼高亮即選中顯示某一行,如要選中第三行,可以使用代碼:
MSHFlexGrid1.Row = 3
MSHFlexGrid1.TopRow =3
myMSHFlexGrid.ColSel = MSHFlexGrid1.Cols - 1
MSHFlexGrid中單擊某一行變色,如何實(shí)現(xiàn)?
Option Explicit
Public j As Long
Private Sub RowColor(i As Long, j As Long)
'i代表現(xiàn)在點(diǎn)的這一行
Dim n As Long 'n代表列
With Me.MSHFlexGrid1
For n = 1 To .Cols - 1
.Row = i
.Col = n
.CellBackColor = HC0FFFF
If j 0 And i j Then
.Row = j
.CellBackColor = HFFFFFF
End If
Next n
j = i
End With
End Sub
Private Sub Form_Load()
With Me.MSHFlexGrid1
.Cols = 5
.Rows = 6
End With
End Sub
Private Sub MSHFlexGrid1_Click()
Call RowColor(Me.MSHFlexGrid1.Row, j)
Debug.Print j
End Sub
把按鈕的Enable屬性改為False。
用代碼:按鈕名.Enable=False。
用API:EnableWindow。
1、VB是一種可視化的面向?qū)ο蟮某绦蛟O(shè)計(jì)語言,Enabled是VB中控件的一種屬性。
2、Enabled屬性有兩種值True和False,分別代表真和假。當(dāng)一個(gè)控件的Enabled屬性值為真時(shí)代表該控件可以用,當(dāng)控件的Enabled屬性為False時(shí)代表該控件不可用(圖形會變度為灰色且不可以選中)。
擴(kuò)展資料
vb.net?特性:
1、vb.net 完全集成到 Visual Studio 集成開發(fā)環(huán)境中,在這種集成開發(fā)環(huán)境與 VB 在若干方面有差異。主要體現(xiàn)在窗體的布局以及菜單等方面都有所不同。
2、vb.net 項(xiàng)目與 VB 不同。它使用基于文件夾的模型,所有項(xiàng)目均放置在項(xiàng)目文件夾層次結(jié)構(gòu)中。
3、vb.net 中使用ado.net來訪問數(shù)據(jù)庫,ado.net是.netFramework的一部分。在 vb.net 中實(shí)現(xiàn)數(shù)據(jù)訪問的方法主要有兩種。
窗體半透明: FormXX.Opacity=0.5或者: SetStyle(ControlStyles.SupportsTransparentBackColor, True)ControlXX.BackColor = Color.Transparent '或者是帶Alpha的顏色ControlXX.BackColor = Color.FromArgb(128,Color.Red)
也容易,如果是黑白三個(gè)顏色加上相同的漸變量,彩色的是起始顏色的三個(gè)分量與終止顏色的對應(yīng)三個(gè)分量的差值,再除于相同的份數(shù),就得出三原色各自的步進(jìn)量。
窗體上放個(gè)圖片框試試下面代碼:
Private?Sub?PictureBox1_Paint(ByVal?sender?As?Object,?ByVal?e?As?System.Windows.Forms.PaintEventArgs)?Handles?PictureBox1.Paint
Dim?startColor?As?Color?=?Color.Red
Dim?endColor?As?Color?=?Color.Green
Dim?s?As?String?=?"vb.net?如何使文字能漸變顏色,就是顏色慢慢變淡然后在慢慢恢復(fù)?"
Dim?Steps?As?Integer?=?s.Length?\?2
Dim?StepR?As?Integer?=?(CInt(endColor.R)?-?startColor.R)?\?Steps
Dim?StepG?As?Integer?=?(CInt(endColor.G)?-?startColor.G)?\?Steps
Dim?StepB?As?Integer?=?(CInt(endColor.B)?-?startColor.B)?\?Steps
Dim?R?As?Integer?=?startColor.R
Dim?G?As?Integer?=?startColor.G
Dim?B?As?Integer?=?startColor.B
Dim?drawFont?As?New?System.Drawing.Font("Arial",?16)
Dim?X?As?Integer?=?50
For?i?As?Integer?=?1?To?Steps
Dim?drawBrush?As?New?SolidBrush(Color.FromArgb(R,?G,?B))
e.Graphics.DrawString(s.Substring(i?-?1,?1),?drawFont,?drawBrush,?X,?50.0)
X?+=?18
R?+=?StepR
G?+=?StepG
B?+=?StepB
Next
For?i?As?Integer?=?1?To?Steps
Dim?drawBrush?As?New?SolidBrush(Color.FromArgb(R,?G,?B))
e.Graphics.DrawString(s.Substring(i?+?Steps?-?1,?1),?drawFont,?drawBrush,?X,?50.0)
X?+=?18
R?-=?StepR
G?-=?StepG
B?-=?StepB
Next
End Sub
Me.TransparencyKey = Color.White
'將窗體上的所有白色設(shè)為透明。
Me.BackColor = Color.White
'將窗體設(shè)為白色,若包括窗體上的控件顏色在內(nèi),沒有其他顏色,則全部透明。
分享題目:關(guān)于vb.net淺灰的信息
文章分享:http://jinyejixie.com/article0/dochcio.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護(hù)、App開發(fā)、全網(wǎng)營銷推廣、網(wǎng)站營銷、網(wǎng)站改版、網(wǎng)站收錄
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)