⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄

📁 vb模拟 图书管理系统
💻
字号:

--------------------------------------------------------------------------------

VB中MsFlexGrid控件的使用细则(收集) 

>> 将文本赋值给MsFlexGrid的单元格 
 MsFlexGrid.TextMatrix(3,1)=”Hello” 

>> 在MsFlexGrid控件单元格中插入背景图形 
 Set MsFlexGrid.CellPicture=LoadPicture(“C:\temp\1.bmp”) 

>>选中某个单元 
 MsFlexGrid.Row=1 
 MsFlexGrid.Col=1 

>>用粗体格式化当前选中单元 
 MsFlexGrid.CellFontBold=True 

>> 添加新的一行 
 使用AddItem方法,用Tab字符分开不同单元格的内容 
 dim row as string 
 row=”AAA”&vbtab&”bbb” 
 MsFlexFrid1.addItem row 


>>怎样来实现MSFlexGrid控件单数行背景为白色,双数的行背景为蓝色? 
   Dim i As Integer 
   With MSFlexGrid1 
        .AllowBigSelection = True   ’ 设置网格样式 
        .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 

>>程序运行时,想动态增加MSFlexgrid的列数 
在第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中的对齐功能的使用 
设置MSFlexGrid1.ColAlignment(index)=n 


>>得到MSFlexGrid控件中当前选中的一行 
msflexgrid1.rowsel就是当前选中行 

>> 如何通过代码调节列宽度 
msflexgrid1.colwidth(i)=4000 

collected by junglesong 
junglesong@etang.com 
2004-1-21 
///////////////////////////////////
If Trim(Text2.Text) <> "" Then
If str = "" Then
str = "姓名'" + Trim(Text2.Text) + "'"
Else
str = str + "and 姓名='" + Trim(Text2.Text) + "'"
End If
End If
If Trim(Text3.Text) <> "" Then
If str = "" Then
str = "单位'" + Trim(Text3.Text) + "'"
Else
str = str + "and 单位='" + Trim(Text3.Text) + "'"
End If
End If
If Trim(Text4.Text) <> "" Then
If str = "" Then
str = "级别'" + Trim(Text4.Text) + "'"
Else
str = str + "and 级别='" + Trim(Text4.Text) + "'"
End If
End If
If Trim(Text5.Text) <> "" Then
If str = "" Then
str = "性别'" + Trim(Text5.Text) + "'"
Else
str = str + "and 性别='" + Trim(Text5.Text) + "'"
End If
End If
/////////////////////////////////////////////////////////////
在VB程序中,如果你用如下语句动态创建一个Combo控件

Dim WithEvents cmbDropList As ComboBox
...
Set cmbDropList = Controls.Add("VB.ComboBox", "cmbDropList")
后,Combo控件的Style值是1 (VbComboDropDown 下拉式组合框,包括一个下拉式列表和一个文本框。可以从列表选择或在文本框中输入 ),若想把Style的值更改2 (VbComboDrop-DownList 2 下拉式列表。这种样式仅允许从下拉式列表中选择 )

通过语句Combo1.Style=2是不行的,因为Style是只读属性。为了突破这个限制,我动用的Spy++这个武器,对两种不同Style值的combo控件进行侦察,发现了两处不同

    1、combo控件的style的值为1-VbComboDropDown时,combo控件窗口的Styles=&H54010242,而combo控件的style的值为2-VbComboDrop-DownList时,combo控件窗口的Styles=&H54010243

    2、combo控件的style的值为1-VbComboDropDown时,combo控件里有一个Edit文本框窗口,而combo控件的style的值为2-VbComboDrop-DownList时,则没有Edit文本框窗口

我首先试着用API函数改变combo控件窗口的Styles值,

Call SetWindowLong(Combo1.hwnd, GWL_STYLE,&H54010243)

看Combo控件有没有什么改变,结果大失所望,

我再次试着用API函数杀死Combo控件里的那个Edit窗口,耶~~~,成功了

下面是我的实现代码:

Private Const GWL_STYLE = (-16)
Private Const GW_CHILD = 5

Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long

Const SW_HIDE = 0
Const SW_SHOW = 5

Dim WithEvents cmbDropList As ComboBox

Private Sub cmbDropList_Click()
  MsgBox cmbDropList.Text
End Sub

Private Sub Command1_Click()
  Dim ChildHwnd As Long
  
  Set cmbDropList = Controls.Add("VB.ComboBox", "cmbDropList")
  
  cmbDropList.Visible = True
  cmbDropList.AddItem "One"
  cmbDropList.AddItem "Two"
  
  ChildHwnd = GetWindow(cmbDropList.hwnd, GW_CHILD)  注释:取edit句柄
  Call DestroyWindow(ChildHwnd)                      注释:Kill edit窗口
  注释:改变cmbDropList的Style,这一语句可有可无~~~~,
  Call SetWindowLong(cmbDropList.hwnd, GWL_STYLE, GetWindowLong(cmbDropList.hwnd, GWL_STYLE) + 1)

End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -