Log in

View Full Version : Problem with a drawing program in visual basic 2008 (c sharp)(gui)


Teutn
Jun 11, 2010, 03:01 AM
Hello all,

I am learning myself c sharp and for that I have been working on a drawing program where the user is capable of drawing lines in 3 different strokes and 4 different colors,

My first problem is how to let the user make a line by 2 mouseclicks on the panel.

This is the code I have so far:
Namespace WindowsFormsApplication1

namespace WindowsFormsApplication1{
public partial class Form1 : Form
{
Graphics e;
Pen p;
Point punt1, punt2;
int nPunt = 0;


public Form1()
{
InitializeComponent();

p = new Pen(Color.Black);
}

public void tekenpaneel_MouseClick(object sender, MouseEventArgs e)
{
if (nPunt == 0)
{
punt1 = new Point(e.X, e.Y);
nPunt++;
}
else if (nPunt == 1)
{
punt2 = new Point(e.X, e.Y);
nPunt = 0;
}
}

public void tekenpaneel_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawLine( p, punt1, punt2);
}

}
}






I don't got any errors but the program isn't doing anything when I click on the panel, I would be verry gratefull if someone could help me out :)

Teutn
Jun 11, 2010, 08:10 AM
OK now a quick update of how my code is now so its easier to help me :)
Already a big thanks, getting to really understand csharp now :D


namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public int A, B, X, Y;
public Color m_Color;
public Point punt1;
public Point punt2;
public int nPunt;

public Form1()
{
InitializeComponent();
}
public void tekenpaneel_MouseClick(object sender, MouseEventArgs e)
{
if (nPunt == 0)
{
punt1 = new Point(e.X, e.Y);
nPunt++;
}
else if (nPunt == 1)
{
punt2 = new Point(e.X, e.Y);
nPunt = 0;
}
}

private void zwartBtn2_CheckedChanged(object sender, EventArgs e)
{
m_Color = Color.Black;
}

private void roodBtn2_CheckedChanged(object sender, EventArgs e)
{
m_Color = Color.Red;
}

private void geelBtn2_CheckedChanged(object sender, EventArgs e)
{
m_Color = Color.Yellow;
}

private void blauwBtn2_CheckedChanged(object sender, EventArgs e)
{
m_Color = Color.Blue;
}

public void tekenpaneel_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawLine(new Pen(m_Color, 2), punt1, punt2);
}

}
}I get no errors but no lines either... any help would be welcome :) THANKS!