我正在根据电子邮件计数创建radioButton表单将打开,用户将检查单选按钮然后我将动态存储在配置文件中的emailId。这个功能我在outlook中实现添加
当outlook将关闭并且它将再次打开然后我从Config文件获取最后选择的邮件ID并存储在字符串中但我无法检查那些我从配置获得的特定emailID因为我已经动态创建了radiobutton。每当表单打开时我想检查最后选择的radioButton即使我关闭了前景也是我打开我需要检查最后选择的单选按钮。
这是我动态创建的单选按钮
For Each email As String In Arremailslist
Dim rb As New RadioButton
rb.Name = email
rb.Text = email
rb.AutoSize = True
dynamictablelayout.SetColumn(rb, 0)
dynamictablelayout.SetRow(rb, i)
dynamictablelayout.Controls.Add(rb)
i = i + 1
Next
我在Form_Load事件中调用此方法
这是我的按钮点击事件代码,用于检查在配置文件中检查和更新的电子邮件ID
Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
selectedmailID = Nothing
For Each c As Control In dynamictablelayout.Controls
If c.GetType Is GetType(RadioButton) Then
Dim rb As RadioButton = DirectCast(c, RadioButton)
If rb.Checked Then
selectedmailID = rb.Text
updateconfige(selectedmailID)
Exit For
End If
End If
Next
Me.Close()
End Sub
答案 0 :(得分:1)
假设您在变量中有更新的电子邮件ID字符串,请说selectedEmailIdFromConfig
然后,下面Form_Load
中的代码段应该如下所示
For Each email As String In Arremailslist
Dim rb As New RadioButton
rb.Name = email
rb.Text = email
rb.AutoSize = True
'Check the radiobutton by string equality check
If selectedEmailIdFromConfig = email Then
rb.Checked = True
End If
dynamictablelayout.SetColumn(rb, 0)
dynamictablelayout.SetRow(rb, i)
dynamictablelayout.Controls.Add(rb)
i = i + 1
Next
我希望这会有所帮助。