I'm having trouble figuring out what's happening here. I'm drawing some stuff on the Panel canvas, but there's a problem, when I try to create the secon instance of the class (Miza).
When the first instance is created, the table draws just fine, but when it gets to the second instance is being created, the error occours in the line 69 saying: "Parameter is not valid"
I've been going thru the code many times but to no avail. I just can't spot the problem...
So, here's the code for the Class Miza:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
namespace GRAFIKA_TEST
{
class Miza
{
private string imeMize="Miza";
public string ImeMize
{
get { return imeMize; }
set { imeMize = value; }
}
private int radijMize;
public int RadijMize
{
get { return radijMize; }
set
{
if (value<50)
{
value = 50;
}
radijMize=value;
}
}
private int stolpec;
public int Stolpec
{
get { return stolpec; }
set {
if (value==0)
{
value = 1;
}
stolpec = value * 30;
}
}
private int vrsta;
public int Vrsta
{
get { return vrsta; }
set
{
if (value == 0)
{
value = 1;
}
vrsta = value * 20;
}
}
public void NarisiMize(Graphics e)
{
Graphics gfx = e;
// Create a new pen and stuff to use for drawing the table
Pen myPen = new Pen(Color.Black);
SolidBrush myBrush = new SolidBrush(Color.Brown);
SolidBrush barvaImenaMize=new SolidBrush(Color.Yellow);
Font myFont=new Font("Ariel",8);
// draw the table on canvas
gfx.FillEllipse(myBrush, stolpec,vrsta, radijMize, radijMize);
// draw the name of the table
gfx.DrawString(imeMize, myFont,barvaImenaMize,stolpec+10,vrsta+20);
// draw 4 chairs around the table
gfx.DrawRectangle(myPen, stolpec-20, vrsta+15, 20, 20);
gfx.DrawRectangle(myPen, stolpec+50, vrsta+15, 20, 20);
gfx.DrawRectangle(myPen, stolpec+15, vrsta+50, 20, 20);
gfx.DrawRectangle(myPen, stolpec + 15, vrsta-20, 20, 20);
//get rid of stuff
myPen.Dispose();
myBrush.Dispose();
barvaImenaMize.Dispose();
myFont.Dispose();
gfx.Dispose();
}
}
}
And here's the code of the calling form:
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 GRAFIKA_TEST
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
// Get the graphics object
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
// this one is working OK!
Miza miza = new Miza();
miza.Vrsta = 1;
miza.Stolpec = 1;
miza.RadijMize = 50;
miza.ImeMize = "Bojan";
miza.NarisiMize(e.Graphics);
// this one is NOT working! (WHY?)
Miza miza1 = new Miza();
miza1.Vrsta = 1;
miza1.Stolpec = 2;
miza1.RadijMize = 50;
miza1.ImeMize = "Miha";
miza1.NarisiMize(e.Graphics);
}
}
}
I'm drawing this on a Panel...
Any ideas?
Regards and best wishes! Ales

New Topic/Question
Reply



MultiQuote





|