hi
there is a button on my main form . when i click it ,my message form (dynamically is created and content a TableLayoutPanel with a label and a button "Ok") will display . the problem is :
when i click "ok" button (for first time) nothing is happend . but for 2th time i click , then the dialoge will close . normally if i add button on designer every thing is ok , but in dynamically adding this problem is occured. i mean i must click on ok button twice to close the dialog ....and i don't want it
this is whole program :
and this is callig from main form :
there is a button on my main form . when i click it ,my message form (dynamically is created and content a TableLayoutPanel with a label and a button "Ok") will display . the problem is :
when i click "ok" button (for first time) nothing is happend . but for 2th time i click , then the dialoge will close . normally if i add button on designer every thing is ok , but in dynamically adding this problem is occured. i mean i must click on ok button twice to close the dialog ....and i don't want it
this is whole program :
VB.NET:
Imports System.Windows.Forms
Public Class FaDialogs
Private frm As New MsgForm
Private WithEvents tlp As TableLayoutPanel
Private WithEvents btn As Button
Private WithEvents lbl_Message As Label
Public Function FaMsgBox(ByVal msg As String, ByVal DlgStyle As MsgBoxStyle) As Boolean
Select Case DlgStyle
Case MsgBoxStyle.OkOnly
'Label
lbl_Message = New Label
lbl_Message.Text = msg
lbl_Message.Dock = DockStyle.Fill
lbl_Message.Margin = New Padding(15)
'Button
btn = New Button
btn.Name = "btn_Action"
btn.Text = "Ok"
btn.Anchor = (AnchorStyles.Bottom Or AnchorStyles.Right Or AnchorStyles.Left Or AnchorStyles.Top)
btn.Margin = New Padding(100, 10, 100, 10)
'TabelLayoutPanel
tlp = New TableLayoutPanel
tlp.ColumnCount = 1
tlp.RowCount = 2
tlp.Dock = DockStyle.Fill
tlp.RowStyles.Add(New RowStyle(SizeType.Percent, 65.0!))
tlp.RowStyles.Add(New RowStyle(SizeType.Percent, 35.0!))
tlp.Controls.Add(btn, 0, 1)
frm.Controls.Add(tlp)
ExecForm.Text = frm.ShowDialog().ToString
End Select
Return True
End Function
Private Sub btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn.Click
btn.DialogResult = Windows.Forms.DialogResult.OK
End Sub
End Class
and this is callig from main form :
VB.NET:
Public Class ExecForm
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a As New FaDialogs
a.FaMsgBox(" this is test .", MsgBoxStyle.OkOnly)
End Sub
End Class
Last edited: