vb6 - VB6如何将一个字符串值从form2返回到form 1
问题描述
在我的项目中有两种形式:第一种形式我将其命名为 frmSettings ,我将使用文本框将值保存在 INI 文件中。第二种形式我将其命名为 frmSelectFolder ,我包含在 DirListBox 和 2 个命令按钮中
如上图设置表单中所示,我有 8 个文本框和 8 个命令按钮来浏览将从 frmSelectFolder 中选择的文件夹路径
如何为所有文本框使用 frmSelectFolder 而无需为每个命令按钮复制此表单以返回 DirlistBox 控件值?
解决方案
这是一些辅助frmSelectFolder
形式的示例代码
Option Explicit
Private m_bConfirm As Boolean
Public Function Init(sPath As String) As Boolean
Dir1.Path = sPath
Show vbModal
If m_bConfirm Then
sPath = Dir1.Path
'--- success
Init = True
End If
Unload Me
End Function
Private Sub cmdOk_Click()
If LenB(Dir1.Path) = 0 Then
MsgBox "Please select a path!", vbExclamation
Exit Sub
End If
m_bConfirm = True
Visible = False
End Sub
Private Sub cmdCancel_Click()
Visible = False
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode <> vbFormCode Then
Cancel = 1
Visible = False
End If
End Sub
以下是如何Init
从主要调用上述方法frmSettings
Option Explicit
Private Sub cmdStartupPath_Click()
Dim sPath As String
Dim oFrmSelector As New frmSelectFolder
sPath = txtStartupPath.Text
If oFrmSelector.Init(sPath) Then
txtStartupPath.Text = sPath
txtStartupPath.SetFocus
End If
End Sub
Private Sub cmdDownloadPath_Click()
Dim sPath As String
Dim oFrmSelector As New frmSelectFolder
sPath = txtDownloadPath.Text
If oFrmSelector.Init(sPath) Then
txtDownloadPath.Text = sPath
txtDownloadPath.SetFocus
End If
End Sub
这是一个完整示例项目的链接,供您研究:SelectFolder.zip
推荐阅读
- sql - 如何在 CASE 中只计算一次相同的行?SQL
- reactjs - 使用 React Router,在 Layout 组件顶部显示 Not Found 页面
- azure - terraform 中现有存储帐户的密钥保管库访问策略
- micronaut - 如何在 Micronaut 的集合中获取带注释的类?
- c# - 用户控制 WPF C#
- javascript - 使用Javascript根据类之间的数字计算值
- python - 用 pandas 计算状态持续时间
- c# - OpenApi 生成器 - 从配置文件传递映射
- firebase - firebase - 限制用户登录 14 天
- r - 结构方程建模