Witam,
mam program i w klasie Punkt2Dk mam metode ToString i chcę aby ona wypisywała pewien tekst do textboxa, jednak VS2010 podkreśla mi to jako błąd i daje:
The name 'richTextBox1' does not exist in the current context
Jak mogę to zrobić aby było dobrze?
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;
using System.Collections;
namespace zad43
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Punkt2Dk ob = new Punkt2Dk(5, 7);
Punkt2Ds st = new Punkt2Ds();
OperacjeNaPunktach op = new OperacjeNaPunktach();
st.ustal(5, 7);
op.PrzesunPunkt(ob, 2, 2);
op.PrzesunPunkt(ref st, 2, 2);
richTextBox1.AppendText("Poczatkowe wspol. punktu dla klasy: " + ob.x + " " + ob.y + "\n\n");
richTextBox1.AppendText("Poczatkowe wspol. punktu dla struktury: " + ob.x + " " + ob.y + "\n\n");
richTextBox1.AppendText("Wspolrzedne punktu po przesunieciu dla klasy: " + ob.x + " " + ob.y + "\n\n");
richTextBox1.AppendText("Wspolrzedne punktu po przesunieciu dla struktury: " + st.x + " " + st.y + "\n\n");
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click_1(object sender, EventArgs e)
{
Punkt2Dk[] ob;
ob = new Punkt2Dk[10000];
for(int i=0;i <10000; i++)
ob[i] = new Punkt2Dk(5, 7);
long pam1 = System.GC.GetTotalMemory(true);
Punkt2Ds[] st;
st = new Punkt2Ds[10000];
for (int i = 0; i < 10000; i++)
st[i].ustal(5, 7);
long pam2 = System.GC.GetTotalMemory(true);
richTextBox1.AppendText("Tablica klas zajmuje: " + pam1 + "\n\n");
richTextBox1.AppendText("Tablica struktur zajmuje: " + pam2 + "\n\n");
ArrayList Lista1 = new ArrayList();
ArrayList Lista2 = new ArrayList();
for (int i = 0; i < 10000; i++)
Lista1.Add(ob);
long pam3 = System.GC.GetTotalMemory(true);
for (int i = 0; i < 10000; i++)
Lista1.Add(st);
long pam4 = System.GC.GetTotalMemory(true);
richTextBox1.AppendText("Lista klas zajmuje: " + pam3 + "\n\n");
richTextBox1.AppendText("Lista struktur zajmuje: " + pam4 + "\n\n");
}
}
struct Punkt2Ds
{
public int x;
public int y;
public void ustal(int x1, int y1)
{
x = x1;
y = y1;
}
}
class OperacjeNaPunktach
{
public void PrzesunPunkt(ref Punkt2Ds st, int x1, int y1)
{
st.x += x1;
st.y += y1;
}
public void PrzesunPunkt(Punkt2Dk ob, int x1, int y1)
{
ob.x += x1;
ob.y += y1;
}
}
class Punkt2Dk
{
public int x;
public int y;
public Punkt2Dk(int x1, int y1){
x = x1;
y = y1;
}
public string ToString()
{
richTextBox1.AppendText("Wspolrzedne punktu po przesunieciu dla klasy: "+ x, y + "\n\n");
}
}
}