i am trying to create a program that is able to draw a housing plan. the user should be able to input the required meters then upon clicking a left,right,up, down button, the system draws a line in that direction. I have managed to do this but however how do i protect my painted window when it has been obscured by another window. i also would like to be able to click on corners and be able to draw interior walls from a point marked from a corner. here is my code for what i have done so far...
Code:
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace SalesGuruWizardInterface
{
public partial class graphics : Form
{
public graphics()
{
}
public int startpositionx = 190;
public int startpositiony = 640;
public int currentpositionx = 190;
public int currentpositiony = 640;
public int listx = 0;
public int listy = 0;
public int clistx = 0;
public int clisty = 0;
public List<int> xlist = new List<int>();
public List<int> ylist = new List<int>();
public int count = 0;
public Graphics g;
bool shouldPaint = false;
public void draw()
{
g = this.CreateGraphics();
Pen mypen = new Pen(Color.Brown,3);
Pen myredpen = new Pen(Color.Red, 10);
myrectangle = new Rectangle(currentpositionx , currentpositiony , 1, 1);
g.DrawRectangle(myredpen,myrectangle);
g.DrawLine(mypen, startpositionx , startpositiony , currentpositionx ,currentpositiony );
startpositionx = currentpositionx ;
startpositiony = currentpositiony ;
xlist.Add(startpositionx);
ylist.Add(startpositiony);
listBox1.Items.Add(xlist[count] + " " + ylist[count]);
count += 1;
}
public void Area(int[] x, int[] y,int intcount)
{
{//This Construcot for Area of a Polygon
double area = 0;
for (int i = 0; i < intcount; i++)
{
//MessageBox.Show(x[i] + " " + y[i] );
area += ((x[i] * y[i + 1]) - (x[i + 1] * y[i]));
}
area = area / 2;
MessageBox.Show(((area* 4756.242568370986920332936979786)/1000000).ToString() + "m squared");
}
}
private void upbutton_Click(object sender, EventArgs e)
{
currentpositiony -= Convert.ToInt16((double.Parse(textBox1.Text) * 0.0145));
draw();
}
private void rightbutton_Click(object sender, EventArgs e)
{
currentpositionx += Convert.ToInt16((double.Parse(textBox1.Text) * 0.0145));
draw();
}
private void leftbutton_Click_1(object sender, EventArgs e)
{
currentpositionx -= Convert.ToInt16((double.Parse(textBox1.Text) * 0.0145));
draw();
}
private void downbutton_Click(object sender, EventArgs e)
{
currentpositiony += Convert.ToInt16((double.Parse(textBox1.Text) * 0.0145));
draw();
}
private void uprightbutton_Click(object sender, EventArgs e)
{
currentpositiony -= Convert.ToInt16(double.Parse(textBox1.Text) * 0.0145 * System.Math.Sin(45));
currentpositionx += Convert.ToInt16(double.Parse(textBox1.Text) * 0.0145 * System.Math.Cos(45));
draw();
}
private void downrightbutton_Click(object sender, EventArgs e)
{
currentpositiony += Convert.ToInt16(double.Parse(textBox1.Text) * 0.0145 * System.Math.Sin(45));
currentpositionx -= Convert.ToInt16(double.Parse(textBox1.Text) * 0.0145 * System.Math.Cos(45));
draw();
}
private void downleftbutton_Click(object sender, EventArgs e)
{
currentpositiony += Convert.ToInt16(double.Parse(textBox1.Text) * 0.0145 * System.Math.Sin(45));
currentpositionx += Convert.ToInt16(double.Parse(textBox1.Text) * 0.0145 * System.Math.Cos(45));
draw();
}
private void upleftbutton_Click(object sender, EventArgs e)
{
currentpositiony -= Convert.ToInt16(double.Parse(textBox1.Text) * 0.0145 * System.Math.Sin(45));
currentpositionx -= Convert.ToInt16(double.Parse(textBox1.Text) * 0.0145 * System.Math.Cos(45));
draw();
}
private void Areabutton_Click(object sender, EventArgs e)
{
xlist.Add(xlist[0]);
ylist.Add(ylist[0]);
Area(xlist.ToArray(), ylist.ToArray(),count);
}
private void graphics_Load(object sender, EventArgs e)
{
loadsg();
}
public void loadsg()
{
//i am using this as the canvas window
Graphics h = this.CreateGraphics();
Pen mypen = new Pen(Color.Blue, 5);
myrectangle = new Rectangle(180, 50, 800, 600);
h.DrawRectangle(mypen, myrectangle);
}
private void cmdclear_Click(object sender, EventArgs e)
{
g.Clear(Color.LightGray);
loadsg();
startpositionx = 190;
startpositiony = 640;
currentpositionx = 190;
currentpositiony = 640;
xlist.Clear();
ylist.Clear();
count = 0;
}
Comment