Witam. Jako że w programowaniu jestem nowicjuszem, mogę pisać mało zrozumiale, za co z góry przepraszam.
Mam taki problem:
Tworzę nową klasę i w niej chcę dodać metodę która narysuje mi coś na głównym oknie w Form
Mam domyślną klasę Form1:Form w której stworzyłem jakiś obiekt graficzny
System.Drawing.Graphics g;
g = this.CreateGraphics();
, pióro : Pen myPen = new Pen(System.Drawing.Color.Red, 3);
i wypisałem to na ekran : ` g.DrawLine(myPen, 105, 370, 105, `code>i wypisałem to na ekran : ` g.DrawLine(myPen, 105, 370, 105, 170);
W takiej postaci wszystko działa, lecz gdy zrobiłem oddzielną klasę :
public class wykres
{
public int a, b, c;
Graphics g;
public void rysuj()
{
g = this.CreateGraphics();
TextBox textBox1;
TextBox textBox2;
TextBox textBox3;
Pen myPen = new Pen(System.Drawing.Color.Red, 3);
Pen myPen2 = new Pen(System.Drawing.Color.White, 3);
g.DrawLine(myPen2, 105, 270, 105, 170);
g.DrawLine(myPen2, 125, 270, 125, 170);
g.DrawLine(myPen2, 145, 270, 145, 170);
a = int.Parse(textBox1.Text);
b = int.Parse(textBox2.Text);
c = int.Parse(textBox3.Text);
g.DrawLine(myPen, 105, 270, 105, 270 - a);
g.DrawLine(myPen, 125, 270, 125, 270 - b);
g.DrawLine(myPen, 145, 270, 145, 270 - c);
textBox1.Text = "0";
textBox2.Text = "0";
textBox3.Text = "0";
}
}
to zwraca mi błąd:
Error 1 'WindowsFormsApplication1.wykres' does not contain a definition for 'CreateGraphics' and no extension method 'CreateGraphics' accepting a first argument of type 'WindowsFormsApplication1.wykres' could be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Nero\Moje dokumenty\Visual Studio 2008\Projects\wykres\wykres\Class1.cs 21 22 wykres
Jak z tej klasy narysować coś w głównym okienku :)
Ktoś łaskawy podpowie ?