| | |
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 15 Days Ago
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.
Failure is not fatal, but failure to change might be. - John Wooden
2
#3 15 Days Ago
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 6 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; 6 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 |
.net 3.5 6 access action algorithm array asp asp.net basic beginner broadcast c# camera cgi check code combobox commerce connection contorl data database datastructure datetime development disabled dom drawing dubai ecommerce editor enum error excel file form forms gdi+ index javascript keypress label linux list listbox login mailmerge marshalbyrefobject math messagebox mono msword mysql open operator panel photoshop php platform post programming redirect remoting reporting resource richtextbox robot server silverlight smoobjects sql sql-server sqlserver statistics stream study table tcpclientchannel text textbox totaldays trouble upload usercontrol validation vb video visual visual-studio visualbasic visualbasic6 webdevelopment website window winforms wordautomation wpf write zend







