|
不错,原来都想到一块儿了,我以前也作做尝试, 思路一样,只是写成模块, 调用相对简单一些,但方法一样. 见猎心喜,也放上来. 只因是公司软件产品, 不便分享其它源码了.(原理完全一样)
设置自动编码与名称切换只换在组合框的标记属性中设置为(autocbo23) 即可, 如果只有两列则为autocbo12
不过,相对宿命的风的方法,增加一个判断,就是如果窗体是不可编辑的,则不显示编码,而只显示中文.
关键代码:
Public Function gt_SetCboEnterEvent(Optional rctrComboBox As Control, Optional rintType As Integer = 0, Optional rstrTemp As String)
Dim blnCancel As Boolean
Dim frm As Form
On Error Resume Next
If TypeOf rctrComboBox.Parent Is Form Then
Set frm = rctrComboBox.Parent
Else
If TypeOf rctrComboBox.Parent.Parent Is Form Then
Set frm = rctrComboBox.Parent.Parent
Else
If TypeOf rctrComboBox.Parent.Parent.Parent Is Form Then
Set frm = rctrComboBox.Parent.Parent.Parent
Else
Exit Function
End If
End If
End If
If frm Is Nothing Then Exit Function
If Nz(rctrComboBox.ControlSource) <> "" Then
If frm.AllowEdits = False Or rctrComboBox.Enabled = False Or rctrComboBox.Locked = True Then
blnCancel = True
End If
Else
If rctrComboBox.Enabled = False Or rctrComboBox.Locked = True Then
blnCancel = True
End If
End If
If blnCancel Then Exit Function
If InStr(rctrComboBox.Tag, "autocbo") > 0 Then
gt_SetComboColumnWidth rctrComboBox, rstrTemp
End If
Select Case rintType
Case 2
gt_ComboAutoExpand rctrComboBox, True
Case 1
gt_ComboAutoExpand rctrComboBox, False
Case 0
End Select
End Function
Public Function gt_SetCboExitEvent(Optional rctrComboBox As Control, Optional rintType As Integer = 0, Optional rstrTemp As String)
Dim blnCancel As Boolean
Dim frm As Form
On Error Resume Next
If TypeOf rctrComboBox.Parent Is Form Then
Set frm = rctrComboBox.Parent
Else
If TypeOf rctrComboBox.Parent.Parent Is Form Then
Set frm = rctrComboBox.Parent.Parent
Else
If TypeOf rctrComboBox.Parent.Parent.Parent Is Form Then
Set frm = rctrComboBox.Parent.Parent.Parent
Else
Exit Function
End If
End If
End If
If frm Is Nothing Then Exit Function
If Nz(rctrComboBox.ControlSource) <> "" Then
If frm.AllowEdits = False Or rctrComboBox.Enabled = False Or rctrComboBox.Locked = True Then
blnCancel = True
End If
Else
If rctrComboBox.Enabled = False Or rctrComboBox.Locked = True Then
blnCancel = True
End If
End If
If blnCancel Then Exit Function
If InStr(rctrComboBox.Tag, "autocbo") > 0 Then
gt_SetComboColumnWidth rctrComboBox, rstrTemp
End If
End Function
效果图:
获得焦点变成编码,可选择编码,失去焦点变成中文
[此贴子已经被作者于2005-7-27 21:32:29编辑过]
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|