Click here to Skip to main content
15,925,505 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to write log file directly without annoying virtual memory Pin
vantoora10-Jan-09 3:20
vantoora10-Jan-09 3:20 
GeneralRe: How to write log file directly without annoying virtual memory Pin
Luc Pattyn10-Jan-09 3:44
sitebuilderLuc Pattyn10-Jan-09 3:44 
GeneralRe: How to write log file directly without annoying virtual memory Pin
vantoora10-Jan-09 4:04
vantoora10-Jan-09 4:04 
QuestionUpdate TextBox from second Form Pin
wi5nia10-Jan-09 2:02
wi5nia10-Jan-09 2:02 
AnswerRe: Update TextBox from second Form Pin
Jason C Bourne10-Jan-09 2:11
Jason C Bourne10-Jan-09 2:11 
GeneralRe: Update TextBox from second Form Pin
DaveyM6910-Jan-09 6:38
professionalDaveyM6910-Jan-09 6:38 
GeneralRe: Update TextBox from second Form Pin
Jason C Bourne11-Jan-09 1:44
Jason C Bourne11-Jan-09 1:44 
AnswerRe: Update TextBox from second Form Pin
DaveyM6910-Jan-09 6:21
professionalDaveyM6910-Jan-09 6:21 
This should really be done with a delegate/event. I prefer using events for stuff like this. Form2 needs a new event that it can raise, and make you Form1 instance subscribe to it after it has instanciated it. If using an event you'll need a class derived from EventArgs to pass the data back.

This is the sort of idea.
// Form1
using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 frm2 = new Form2();
            frm2.ReadyToUpdate += new EventHandler<Form2.MyEventArgs>(frm2_ReadyToUpdate);
            frm2.Show();
        }

        void frm2_ReadyToUpdate(object sender, Form2.MyEventArgs e)
        {
            textBox1.Text = e.Text;
        }
    }
}
//Form2
using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form2 : Form
    {
        public event EventHandler<MyEventArgs> ReadyToUpdate;
        public Form2()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            OnReadyToUpdate(new MyEventArgs("Test"));
            Close();
        }
        protected virtual void OnReadyToUpdate(MyEventArgs e)
        {
            EventHandler<MyEventArgs> eh = ReadyToUpdate;
            if (eh != null)
                eh(this, e);
        }
        public class MyEventArgs : EventArgs
        {
            public MyEventArgs(string text)
            {
                m_Text = text;
            }
            private string m_Text;
            public string Text
            {
                get { return m_Text; }
            }
        }
    }
}


Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

QuestionWord Search Style Game Pin
VinceAshbySmith10-Jan-09 1:21
VinceAshbySmith10-Jan-09 1:21 
AnswerRe: Word Search Style Game Pin
Eddy Vluggen10-Jan-09 1:42
professionalEddy Vluggen10-Jan-09 1:42 
GeneralRe: Word Search Style Game Pin
VinceAshbySmith10-Jan-09 2:06
VinceAshbySmith10-Jan-09 2:06 
GeneralRe: Word Search Style Game Pin
Jason C Bourne10-Jan-09 2:15
Jason C Bourne10-Jan-09 2:15 
GeneralRe: Word Search Style Game Pin
VinceAshbySmith10-Jan-09 2:30
VinceAshbySmith10-Jan-09 2:30 
GeneralRe: Word Search Style Game Pin
Jason C Bourne10-Jan-09 3:47
Jason C Bourne10-Jan-09 3:47 
GeneralRe: Word Search Style Game Pin
VinceAshbySmith10-Jan-09 5:01
VinceAshbySmith10-Jan-09 5:01 
GeneralRe: Word Search Style Game Pin
Jason C Bourne11-Jan-09 1:47
Jason C Bourne11-Jan-09 1:47 
GeneralRe: Word Search Style Game Pin
VinceAshbySmith11-Jan-09 10:50
VinceAshbySmith11-Jan-09 10:50 
GeneralRe: Word Search Style Game Pin
Eddy Vluggen10-Jan-09 9:23
professionalEddy Vluggen10-Jan-09 9:23 
AnswerRe: Word Search Style Game Pin
Jason C Bourne10-Jan-09 1:42
Jason C Bourne10-Jan-09 1:42 
QuestionHow ENQ command is sent to serial port Pin
Member 465172910-Jan-09 0:19
Member 465172910-Jan-09 0:19 
AnswerRe: How ENQ command is sent to serial port Pin
Luc Pattyn10-Jan-09 1:47
sitebuilderLuc Pattyn10-Jan-09 1:47 
AnswerRe: How ENQ command is sent to serial port Pin
Member 465172910-Jan-09 2:43
Member 465172910-Jan-09 2:43 
GeneralRe: How ENQ command is sent to serial port Pin
Member 465172910-Jan-09 2:57
Member 465172910-Jan-09 2:57 
GeneralRe: How ENQ command is sent to serial port Pin
Luc Pattyn10-Jan-09 3:02
sitebuilderLuc Pattyn10-Jan-09 3:02 
QuestionChange user controls in runtime using c# Pin
bensonbenadict10-Jan-09 0:11
bensonbenadict10-Jan-09 0:11 

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.