学生信息管理系统优化

    xiaoxiao2025-07-18  6

    因为这个系统可以优化的地方太多了。而且师兄师姐们也总结了很多,所以我在这里就写一些比较麻烦的吧。。大神请略过,轻虐。 一、VB 自动调整MSHFlexGrid各列列宽为最合适的宽度。 Public Sub AdjustColWidth(frmCur As Form, gridCur As Object, Optional bNullRow As Boolean = True, Optional dblIncWidth As Double = 0)    '--------------------------------------------------------------------    '功能:    '       自动调整Grid各列列宽为最合适的宽度    '参数:    '       [frmCur].........................................当前工作窗体    '       [gridCur]........................................当前要调整的Grid    '--------------------------------------------------------------------    Dim i, j As Integer  Dim dblWidth As Double      With gridCur            For i = 0 To .Cols - 1                dblWidth = 0                If .ColWidth(i) <> 0 Then                  For j = 0 To .Rows - 1                        If frmCur.TextWidth(.TextMatrix(j, i)) > dblWidth Then                          dblWidth = frmCur.TextWidth(.TextMatrix(j, i))                        End If                  Next                  .ColWidth(i) = dblWidth + dblIncWidth + 100                End If          Next      End With  End Sub 说明:以上模块实现MSHFlexGrid的单元格根据内容自动调整宽度. 调用方式 call AdjustColWidth(Form_Name,MSHFlexGrid_Name) 放在公共模块中,第一个自动调整宽度的过程在调用的时候需要注意窗体名称和窗体中的MSHFlexGrid控件的名称.别在A窗体调用出B窗体的控件… 二、删除模块通用代码 (部分控件代码请自行修改) Private Sub deleteCommand_Click()      mrc.MoveNext    '删除后显示下一条记录             If mrc.EOF Then                  mrc.MoveFirst                 mybookmark = mrc.Bookmark                 mrc.MoveLast                 mrc.Delete                 If mrc.EOF = mrc.BOF Then                     MsgBox "没有记录了,请关闭本窗口"                     ComboExamtype.Text = ""   '清空窗口                     ComboClassno.Text = ""                     ComboSID.Text = ""                     ComboCourse.Text = ""                     txtName.Text = ""                     txtResult.Text = ""                     cancelCommand.Enabled = False                     editCommand.Enabled = False                     deleteCommand.Enabled = False                     firstCommand.Enabled = False                     lastCommand.Enabled = False                     nextCommand.Enabled = False                     previousCommand.Enabled = False                     updateCommand.Enabled = False                     Exit Sub                 End If                 mrc.Bookmark = mybookmark                 Call viewData             Else                 mybookmark = mrc.Bookmark '做标记                 mrc.MovePrevious                 mrc.Delete                 mrc.Bookmark = mybookmark '取消标记                 Call viewData             End If End Sub 三、关于设置年级课程两个列表中内容的问题 Private Sub cmdAdd_Click()        If ListAllcourse.ListIndex >= 0 Then '将左边列表中所选元素移动到右边列表中         ListSelectcourse.AddItem ListAllcourse.Text '在右边列表中增加新元素         ListAllcourse.RemoveItem ListAllcourse.ListIndex '删除左边列表中的所选元素      End If                    With ListSelectcourse '去重         For intIndex1 = 0 To .ListCount - 1             For intIndex2 = .ListCount - 1 To intIndex1 + 1 Step -1                 If .List(intIndex2) = .List(intIndex1) Then                     .RemoveItem intIndex2                 End If             Next intIndex2         Next intIndex1      End With      cmdModify.Enabled = True End Sub
    转载请注明原文地址: https://ju.6miu.com/read-1300814.html
    最新回复(0)