1

I'm bit new at this so excuse me if my question is a bit novice. I'm designing a Windows form application to basically replace an old excel spreadsheet then email system(not that its much of a system). After the forms are filled out the answers are saved in terms of public variables, which is fine since it's a small program. Im having trouble referencing my variable from another windows form. Basically, I would like to have the filled out form close and a new "review" window pop up. I'm just using labels that will be show what the value of the variable is. If it was in the same class it wouldn't be a problem but im using two different forms that are partial classes of the same namespace. A bit of code:

using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace OPS_PictureLoader
{
public partial class Points_Screen : Form
{
public int DevJobStandardsTotal = 0;

And the label I would like to show a "0"(or whatever the program has added to it)

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 OPS_PictureLoader
{
public partial class Review : Form
{
    public Review()
    {
        InitializeComponent();


        label14.Text = DevJobStandardsTotal;

Again, thanks and feel free to tell me Im totally wrong :D

Sedaition
  • 61
  • 6
  • Also check [this](http://stackoverflow.com/questions/8566/best-way-to-access-a-control-on-another-form-in-winforms) discussion – Renatas M. May 25 '11 at 20:37

1 Answers1

2

You need to pass the instance of the first form to the second form's constructor:

public Review(Points_Screen owner)
{
    InitializeComponent();


    label14.Text = owner.DevJobStandardsTotal;
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964