C# event

Associate
Joined
30 Dec 2005
Posts
415
Just started learning C# yesterday and have already overcome many problems, but its slow work atm! Just wondering if there's an event in C# which is called upon when other form dialogs are closed and it is the active form...I suppose its on focus really...

I've tried this, but it doesn't seem to work. :(
Code:
        private void Main_Activated(object sender, EventArgs e)
        {  
            message.Text = message.Text + msgtext + " ";
            msgtext = null;
            this.message.Focus();
        }

Can anyone point me in the right direction? I basically need to run the code above each time all the other form dialogs are closed..

Cheers,
Rich
 
Doing what lol?
Sorry i'm completely new to this language.

I'll explain the scenario.

Basically I have a form called main and a form called responses.
main opens the responses form, which opens in front of main and you cannot access main until responses is closed (modal I think its called)...

The user picks a message in the responses form, which I want to then appear in the text box 'message' on the main form. When I tried to access main.message.text from the responses form, it says it didn't have permission to do so...

So what I was going to do was save the message from the responses form in a global variable called msgdump, which is then put in the main.message form box each time main is focused.

Obviously the first method/attempt was best, but I couldn't get round the permission bit..
 
Wow thanks for those informative posts. I've actually rebuilt the project from scratch as i've learnt a lot over the last few days and decided to restructure and rename items.

The form originally called 'Main' is now called 'messenger'. 'responses' is still called 'responses'.

As I don't need the text to update in the text box till the dialog box has been closed, I decided to use Inquisitors example. However, it threw up a few errors...


The code on responses.cs
Code:
   public partial class responses : Form
    {
        public responses()
        {
            InitializeComponent();
        }
        public string Message
        {
            get
            {
                return message.Text;
            }
            set
            {
                message.Text = value;
            }
        }
  etc...


The code on messenger.cs
Code:
        private void btn_responses_Click(object sender, EventArgs e)
        {
            Response responseForm = new responses();
            DialogResult result = responseForm.ShowDialog();
            string message = responseForm.message;
        }


This threw up the following errors:
Error 1 The type or namespace name 'Response' could not be found (are you missing a using directive or an assembly reference?) D:\Visual Studio 2005\Projects\Routy Helper\Routy Helper\messenger.cs 67 13 Routy Helper

Which is this line:
Response responseForm = new responses();


Error 2 The name 'message' does not exist in the current context D:\Visual Studio 2005\Projects\Routy Helper\Routy Helper\responses.cs 22 24 Routy Helper

Which is this line:
return message.Text;


Error 3 The name 'message' does not exist in the current context D:\Visual Studio 2005\Projects\Routy Helper\Routy Helper\responses.cs 26 17 Routy Helper

Which is this line:
message.Text = value;
 
Last edited:
Back
Top Bottom