| | |
Problem with 2 forms working together.
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
I have a main form which is going to use much input data typed in by the user. So I thought to make a separate form to handle the input. The closest to a solution was this thread http://www.daniweb.com/forums/thread231368.html
But I don't want the second form to be disposed off, or be closed by clicking the close icon. I like to store the input data in the second form(seems logical to me) and let the main form use them.
I don't want the input form to be visible all of the time. Just want to let it pop up when the user needs it(via menu or button, don't know yet)
This is my code so far a main form with a button and a click event and an inputdata form:
Not very much, I know. But what would be the most elegant way to handle this?
As always, any help is greatly appreciated.
But I don't want the second form to be disposed off, or be closed by clicking the close icon. I like to store the input data in the second form(seems logical to me) and let the main form use them.
I don't want the input form to be visible all of the time. Just want to let it pop up when the user needs it(via menu or button, don't know yet)
This is my code so far a main form with a button and a click event and an inputdata form:
c# Syntax (Toggle Plain Text)
public partial class Form1 : Form { private InputData InputForm = new InputData(); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { InputForm.Show(); } }
As always, any help is greatly appreciated.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
1
#2 Nov 7th, 2009
Hi danny.
You have to handle formclosing event along with singleton - single instance of Form.
You have to handle formclosing event along with singleton - single instance of Form.
2
#3 Nov 7th, 2009
I would treat the settings form more like a static class for this since thats more or less how you want to deal with it.
Main form:
Settings:
Main form:
C# Syntax (Toggle Plain Text)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace daniweb.twoforms { public partial class frmMain : Form { public frmMain() { InitializeComponent(); } private void buttonGetValues_Click(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); sb.AppendLine("Value1: " + frmSettings.Value1); sb.AppendLine("Value2: " + frmSettings.Value2); sb.AppendLine("Value3: " + frmSettings.Value3); MessageBox.Show(sb.ToString()); } private void buttonShowForm_Click(object sender, EventArgs e) { frmSettings.ShowForm(); } } }
Settings:
C# Syntax (Toggle Plain Text)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace daniweb.twoforms { public partial class frmSettings : Form { static frmSettings instance; static frmSettings() { instance = new frmSettings(); } public static string Value1 { get { return instance.textBox1.Text; } set { instance.textBox1.Text = value; } } public static string Value2 { get { return instance.textBox2.Text; } set { instance.textBox2.Text = value; } } public static string Value3 { get { return instance.textBox3.Text; } set { instance.textBox3.Text = value; } } public static void ShowForm() { if (instance.Visible) instance.BringToFront(); else instance.Show(); } public frmSettings() { InitializeComponent(); //This smokes out a bug in code if you accidently create 2 instances if (instance != null) throw new InvalidOperationException("Only one instance allowed"); this.textBox1.Text = "default val 1"; this.textBox2.Text = "default val 2"; this.textBox3.Text = "default val 3"; } private void frmSettings_FormClosing(object sender, FormClosingEventArgs e) { e.Cancel = true; this.Hide(); } } }
•
•
Join Date: Nov 2009
Posts: 1
Reputation:
Solved Threads: 0
0
#5 32 Days Ago
I ha an MDI parent Form which I want it to be in the to of othe form when I click a button and when I click the button back the form should go to center, I create this code :
it not working.
C# Syntax (Toggle Plain Text)
if (TopMost == false) { //Dis play the form to the top this.TopMost = true; } else { // Display the form the ceter. TopMost = false; }
it not working.
Last edited by adatapost; 32 Days Ago at 9:08 pm. Reason: Use [code] tags to wrap your code.
![]() |
Similar Threads
- MDI Forms (VB.NET)
- Handling docuemnt.forms[0] in FireFox (JavaScript / DHTML / AJAX)
- reset list box is not working javascript (JavaScript / DHTML / AJAX)
- Dataset Problem (VB.NET)
- Problem with 2 forms (C#)
- Side-by-side forms? (HTML and CSS)
- Form Problem (ColdFusion)
- Problem with Forms (PHP)
- Problem with forms (PHP)
Other Threads in the C# Forum
- Previous Thread: SHDocVw insert element in document.body?
- Next Thread: How to send am Email using c# ?
| Thread Tools | Search this Thread |
Tag cloud for c#, form
.net 2008 access advice analyst array asp.net basic broadcast button c# chat check code combobox control custom data database datagridview datetime dbconnection default degrees development directrobot drawing e-commerce email enabled excel feedback file files form forms function game gdi+ html httpwebrequest index java javascript list listbox login maps math mysql notepad odp.net open operator oracle packaging path photoshop php picturebox post print problem programmer programming region remote remoting resource resourcefile richtextbox save saving server softwaredevelopment sql sql-server string stringformatting tables taborder text-file textbox treeview upload user validation vb vb.net video view vista visual visualbasic visualstudio webbrowser whileloop winforms working wpf







