Skip to content

How to change object in main form from class in c#?

farmor

Asked Jun 6, 2006, 4:28 PM EDT1 answer
Share
LinkedInX
Hello all.
I am learning a little c# and done most java console apps before so I will try to do a chess program in c# ,for fun it don't have to be strong, but I have a problem I don't know how to get access to the form from a class I understand I need a referens but don't know how to get one.
Here is my code:

using System;
using System.Collections.Generic;
using System.Text;

namespace Schack
{
class Bord
{
private Pjas[,] pjaser;

public Bord()
{
pjaser = new Pjas[8,8];
int[] start = new int[2];
for (int i = 0; i <= 7; i++)
{
start[0] = 1;
start[1] = i;
pjaser[1,i]=new Bonde(start,0);
}
}

public void rita()
{
??????????? The Line under is the problem.
Form1.label1.Text ="Hello"; //////Dont work (It has no referens how do I create one?)
for (int i = 0; i <= 7; i++)
for (int k = 0; k <= 7; k++)
{
if (pjaser[i, k] != null) pjaser[i, k].rita();
}
}
}
}

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    You can try creating a new instance of the Form1 class before you try and assign a value to one of its components.

    Form1 form1 = new Form1();
    form1.label1.Text ="Hello";
    0