Click here to Skip to main content
15,913,854 members
Home / Discussions / C#
   

C#

 
QuestionSingleton Form updated from main Form - Object Reference Error Pin
Edunt15-Feb-11 4:36
Edunt15-Feb-11 4:36 
AnswerRe: Singleton Form updated from main Form - Object Reference Error Pin
Luc Pattyn15-Feb-11 5:20
sitebuilderLuc Pattyn15-Feb-11 5:20 
GeneralRe: Singleton Form updated from main Form - Object Reference Error Pin
Edunt15-Feb-11 9:28
Edunt15-Feb-11 9:28 
GeneralRe: Singleton Form updated from main Form - Object Reference Error Pin
Luc Pattyn15-Feb-11 10:10
sitebuilderLuc Pattyn15-Feb-11 10:10 
AnswerRe: Singleton Form updated from main Form - Object Reference Error Pin
musefan15-Feb-11 5:26
musefan15-Feb-11 5:26 
GeneralRe: Singleton Form updated from main Form - Object Reference Error Pin
Edunt15-Feb-11 9:45
Edunt15-Feb-11 9:45 
AnswerRe: Singleton Form updated from main Form - Object Reference Error Pin
_Erik_15-Feb-11 5:47
_Erik_15-Feb-11 5:47 
AnswerRe: Singleton Form updated from main Form - Object Reference Error [modified] Pin
Edunt15-Feb-11 10:07
Edunt15-Feb-11 10:07 
Ok, thanks for the replies - very helpful all.

Just to wrap this up, here is the working example of taking text from one form and appending it onto a second form.

frmParentForm has a textBox, plus two buttons now - one to send the text and one to hide/show the second form.

frmChildForm is the second form that has to have text appended. It has a textBox plus one button to close this form - if you close it, a new instance will be created next time you send to it.

frmParentForm code:-

using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
<br />
namespace PassingDataExample<br />
{<br />
    public partial class frmParentForm : Form<br />
    {<br />
        public frmParentForm()<br />
        {<br />
            InitializeComponent();<br />
        }<br />
<br />
        public void btnSendToNextForm_Click(object sender, EventArgs e)<br />
        {<br />
            frmChildForm form = frmChildForm.GetInstance();<br />
            form.Enabled = true;<br />
            form.Visible = false;<br />
            form.Hide();<br />
            form.textBox1.AppendText(textBox1.Text + "\r\n");<br />
        }<br />
<br />
        private void btnShowChild_Click(object sender, EventArgs e)<br />
        {<br />
            frmChildForm form = frmChildForm.GetInstance();<br />
            if (form.Visible == false)<br />
            {<br />
                form.Visible = true;<br />
                form.Show();<br />
            }<br />
            else<br />
            {<br />
                form.Visible = false;<br />
                form.Hide();<br />
            }<br />
        }<br />
    }<br />
}



frmChildForm code:-

using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
<br />
namespace PassingDataExample<br />
{<br />
    public partial class frmChildForm : Form<br />
    {<br />
<br />
        private static frmChildForm frm;<br />
<br />
        public static frmChildForm GetInstance()<br />
        {<br />
            if (frm == null || frm.IsDisposed)<br />
            {<br />
                frm = new frmChildForm();<br />
            }<br />
            return frm;<br />
        }<br />
<br />
        private frmChildForm()<br />
        {<br />
            InitializeComponent();<br />
        }<br />
<br />
        private void btnClose_Click(object sender, EventArgs e)<br />
        {<br />
            this.Close();<br />
        }<br />
    }<br />
}


Hope this helps someone else - I do like practical examples.

modified on Tuesday, February 15, 2011 6:47 PM

Questionremove duplicates from list collection Pin
arkiboys15-Feb-11 0:40
arkiboys15-Feb-11 0:40 
AnswerRe: remove duplicates from list collection PinPopular
Pravin Patil, Mumbai15-Feb-11 0:53
Pravin Patil, Mumbai15-Feb-11 0:53 
GeneralRe: remove duplicates from list collection Pin
arkiboys15-Feb-11 0:57
arkiboys15-Feb-11 0:57 
GeneralRe: remove duplicates from list collection Pin
musefan15-Feb-11 1:28
musefan15-Feb-11 1:28 
GeneralRe: remove duplicates from list collection Pin
PIEBALDconsult15-Feb-11 1:49
mvePIEBALDconsult15-Feb-11 1:49 
GeneralRe: remove duplicates from list collection Pin
musefan15-Feb-11 1:58
musefan15-Feb-11 1:58 
GeneralRe: remove duplicates from list collection Pin
PIEBALDconsult15-Feb-11 4:07
mvePIEBALDconsult15-Feb-11 4:07 
GeneralRe: remove duplicates from list collection Pin
musefan15-Feb-11 4:12
musefan15-Feb-11 4:12 
GeneralRe: remove duplicates from list collection Pin
PIEBALDconsult15-Feb-11 4:31
mvePIEBALDconsult15-Feb-11 4:31 
GeneralRe: remove duplicates from list collection Pin
Pravin Patil, Mumbai15-Feb-11 1:50
Pravin Patil, Mumbai15-Feb-11 1:50 
GeneralRe: remove duplicates from list collection Pin
musefan15-Feb-11 1:53
musefan15-Feb-11 1:53 
GeneralRe: remove duplicates from list collection Pin
Luc Pattyn15-Feb-11 2:36
sitebuilderLuc Pattyn15-Feb-11 2:36 
AnswerRe: remove duplicates from list collection Pin
musefan15-Feb-11 0:55
musefan15-Feb-11 0:55 
GeneralRe: remove duplicates from list collection Pin
arkiboys15-Feb-11 0:58
arkiboys15-Feb-11 0:58 
GeneralRe: remove duplicates from list collection Pin
musefan15-Feb-11 1:05
musefan15-Feb-11 1:05 
GeneralRe: remove duplicates from list collection Pin
arkiboys15-Feb-11 1:08
arkiboys15-Feb-11 1:08 
GeneralRe: remove duplicates from list collection Pin
musefan15-Feb-11 1:12
musefan15-Feb-11 1:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.