-1

I'm not sure which part is marked null. I want to transfer data from a form called Need to a form called Coach. The data information is sent directly to the SetActionValuse of Coach and to the Money text box as soon as it is entered in the text box called taketimes. Thank you to coach my code..

This is Need Form

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public delegate void DataPushEventHandler(string value);
    //public delegate void DataGet(string value);
    public partial class Need : Form
    {
        public DataPushEventHandler datasendE;
        public Need()
        {
            InitializeComponent();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            this.Visible = false;
            Main newform = new Main();
            newform.Show();
        }

        private void taketimes_TextChanged(object sender, EventArgs e)
        {
            datasendE(taketimes.Text);
        }


        private void button1_Click(object sender, EventArgs e)
        {
            Coach newform = new Coach();
            this.datasendE += new DataPushEventHandler(newform.SetActionValuse);    
            //this.Visible = false;
            newform.Show();
        }
    }
}

This is Coach form

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    
    public partial class Coach : Form
    {
        string sendData;
        public Coach()
        {
            InitializeComponent();

        }
        public void SetActionValuse(string para)
        {
            money.Text = para;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            this.Visible = false;
            Main newform = new Main();
            newform.Show();
        }

        private void money_TextChanged(object sender, EventArgs e)
        {

        }

        private void Coach_Load(object sender, EventArgs e)
        {
           // money.Text = sendData;
        }
    }
}
ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86

1 Answers1

1

When you have an app in visual studio, take a look at the top of the screen - find the green play triangle icon and make sure it says Debug next to it, click play, run your app til it hits the error and notice that VS is stopped with a line highlighted in yellow

Point your mouse at every word/expression (you can usually select-highlight an expression to see its evaluated value) to the left of a period . until the tooltip says "null" - that's the problem you need to fix. Modern versions of visual studio have an exception helper window that opens and actually tells you what was null

If you've made this mistake inside a try catch that is catching the error then visual studio won't necessarily stop on a line and highlight it, by default. If you go to the debug menu, click exceptions then in the tool window that appears click next to "common language runtime" so it is ticked then visual studio will stop on the error as soon as it throws, even if it is in a try catch. This can be really handy for pinpointing the source of many different kinds of errors, not just null ref

Caius Jard
  • 72,509
  • 5
  • 49
  • 80