Fixed disposing of modal dialog box

This commit is contained in:
MaxXor 2014-07-18 17:05:44 +02:00
parent b6b5fd75f6
commit 5159d6a1b8
2 changed files with 71 additions and 47 deletions

View File

@ -8,44 +8,47 @@ namespace Core
{
public static DialogResult Show(string title, string promptText, ref string value)
{
Form form = new Form();
Label label = new Label();
TextBox textBox = new TextBox();
Button buttonOk = new Button();
Button buttonCancel = new Button();
DialogResult dialogResult = DialogResult.Cancel;
using (var form = new Form())
{
Label label = new Label();
TextBox textBox = new TextBox();
Button buttonOk = new Button();
Button buttonCancel = new Button();
form.Text = title;
label.Text = promptText;
textBox.Text = value;
form.Text = title;
label.Text = promptText;
textBox.Text = value;
buttonOk.Text = "OK";
buttonCancel.Text = "Cancel";
buttonOk.DialogResult = DialogResult.OK;
buttonCancel.DialogResult = DialogResult.Cancel;
buttonOk.Text = "OK";
buttonCancel.Text = "Cancel";
buttonOk.DialogResult = DialogResult.OK;
buttonCancel.DialogResult = DialogResult.Cancel;
label.SetBounds(9, 20, 372, 13);
textBox.SetBounds(12, 36, 372, 20);
buttonOk.SetBounds(228, 72, 75, 23);
buttonCancel.SetBounds(309, 72, 75, 23);
label.SetBounds(9, 20, 372, 13);
textBox.SetBounds(12, 36, 372, 20);
buttonOk.SetBounds(228, 72, 75, 23);
buttonCancel.SetBounds(309, 72, 75, 23);
label.AutoSize = true;
textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
label.AutoSize = true;
textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
form.ClientSize = new Size(396, 107);
form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
form.FormBorderStyle = FormBorderStyle.FixedDialog;
form.StartPosition = FormStartPosition.CenterScreen;
form.MinimizeBox = false;
form.MaximizeBox = false;
form.AcceptButton = buttonOk;
form.CancelButton = buttonCancel;
form.ClientSize = new Size(396, 107);
form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
form.FormBorderStyle = FormBorderStyle.FixedDialog;
form.StartPosition = FormStartPosition.CenterScreen;
form.MinimizeBox = false;
form.MaximizeBox = false;
form.AcceptButton = buttonOk;
form.CancelButton = buttonCancel;
DialogResult dialogResult = form.ShowDialog();
value = textBox.Text;
return dialogResult;
dialogResult = form.ShowDialog();
value = textBox.Text;
}
return dialogResult;
}
}
}

View File

@ -24,7 +24,10 @@ namespace xRAT_2.Forms
if (bool.Parse(XMLSettings.ReadValue("ShowToU")))
{
new frmTermsOfUse().ShowDialog();
using (var frm = new frmTermsOfUse())
{
frm.ShowDialog();
}
Thread.Sleep(300);
}
@ -301,13 +304,15 @@ namespace xRAT_2.Forms
{
if (lstClients.SelectedItems.Count != 0)
{
frmDownloadAndExecute frmDaE = new frmDownloadAndExecute(lstClients.SelectedItems.Count);
if (frmDaE.ShowDialog() == System.Windows.Forms.DialogResult.OK)
using (var frm = new frmDownloadAndExecute(lstClients.SelectedItems.Count))
{
foreach (ListViewItem lvi in lstClients.SelectedItems)
if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Client c = (Client)lvi.Tag;
new Core.Packets.ServerPackets.DownloadAndExecute(DownloadAndExecute.URL, DownloadAndExecute.RunHidden).Execute(c);
foreach (ListViewItem lvi in lstClients.SelectedItems)
{
Client c = (Client)lvi.Tag;
new Core.Packets.ServerPackets.DownloadAndExecute(DownloadAndExecute.URL, DownloadAndExecute.RunHidden).Execute(c);
}
}
}
}
@ -389,13 +394,15 @@ namespace xRAT_2.Forms
{
if (lstClients.SelectedItems.Count != 0)
{
frmVisitWebsite frmVW = new frmVisitWebsite(lstClients.SelectedItems.Count);
if (frmVW.ShowDialog() == System.Windows.Forms.DialogResult.OK)
using (var frm = new frmVisitWebsite(lstClients.SelectedItems.Count))
{
foreach (ListViewItem lvi in lstClients.SelectedItems)
if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Client c = (Client)lvi.Tag;
new Core.Packets.ServerPackets.VisitWebsite(VisitWebsite.URL, VisitWebsite.Hidden).Execute(c);
foreach (ListViewItem lvi in lstClients.SelectedItems)
{
Client c = (Client)lvi.Tag;
new Core.Packets.ServerPackets.VisitWebsite(VisitWebsite.URL, VisitWebsite.Hidden).Execute(c);
}
}
}
}
@ -426,12 +433,18 @@ namespace xRAT_2.Forms
private void menuSettings_Click(object sender, EventArgs e)
{
new frmSettings(listenServer).ShowDialog();
using (var frm = new frmSettings(listenServer))
{
frm.ShowDialog();
}
}
private void menuBuilder_Click(object sender, EventArgs e)
{
new frmBuilder().ShowDialog();
using (var frm = new frmBuilder())
{
frm.ShowDialog();
}
}
private void menuStatistics_Click(object sender, EventArgs e)
@ -439,12 +452,20 @@ namespace xRAT_2.Forms
if (listenServer.BytesReceived == 0 || listenServer.BytesSent == 0)
MessageBox.Show("Please wait for at least one connected Client!", "xRAT 2.0", MessageBoxButtons.OK, MessageBoxIcon.Information);
else
new frmStatistics(listenServer.BytesReceived, listenServer.BytesSent, listenServer.ConnectedClients, listenServer.AllTimeConnectedClients).ShowDialog();
{
using (var frm = new frmStatistics(listenServer.BytesReceived, listenServer.BytesSent, listenServer.ConnectedClients, listenServer.AllTimeConnectedClients))
{
frm.ShowDialog();
}
}
}
private void menuAbout_Click(object sender, EventArgs e)
{
new frmAbout().ShowDialog();
using (var frm = new frmAbout())
{
frm.ShowDialog();
}
}
#endregion