473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

c# house plan drawing

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...

Expand|Select|Wrap|Line Numbers
  1. using System.Data;
  2. using System.Drawing;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using System.Drawing.Drawing2D;
  7. namespace SalesGuruWizardInterface
  8. {
  9.     public partial class graphics : Form
  10.     {
  11.         public graphics()
  12.         {
  13.  
  14.         }
  15.         public int startpositionx = 190;
  16.         public int startpositiony = 640;
  17.         public int currentpositionx = 190;
  18.         public int currentpositiony = 640;
  19.         public int listx = 0;
  20.         public int listy = 0;
  21.         public int clistx = 0;
  22.         public int clisty = 0;
  23.         public List<int> xlist = new List<int>();
  24.         public  List<int> ylist = new List<int>();
  25.         public int count = 0;
  26.          public Graphics g;
  27.          bool shouldPaint = false;
  28.  
  29.         public void draw()
  30.         {
  31.              g = this.CreateGraphics();
  32.             Pen mypen = new Pen(Color.Brown,3);
  33.             Pen myredpen = new Pen(Color.Red, 10);
  34.             myrectangle = new Rectangle(currentpositionx , currentpositiony , 1, 1);
  35.             g.DrawRectangle(myredpen,myrectangle);
  36.             g.DrawLine(mypen, startpositionx , startpositiony ,      currentpositionx ,currentpositiony );
  37.             startpositionx = currentpositionx ;
  38.             startpositiony = currentpositiony ;
  39.             xlist.Add(startpositionx);
  40.             ylist.Add(startpositiony);
  41.             listBox1.Items.Add(xlist[count] + " " + ylist[count]);
  42.             count += 1;
  43.  
  44.  
  45.               }
  46.  
  47.  
  48.         public void Area(int[] x, int[] y,int intcount)
  49.         {
  50.  
  51.             {//This Construcot for Area of a Polygon
  52.                 double area = 0;
  53.  
  54.                 for (int i = 0; i < intcount; i++)
  55.                 {
  56.                     //MessageBox.Show(x[i] + " " + y[i] );
  57.  
  58.                     area += ((x[i] * y[i + 1]) - (x[i + 1] * y[i]));
  59.                 }
  60.                 area = area / 2;
  61.  
  62.  
  63.                 MessageBox.Show(((area* 4756.242568370986920332936979786)/1000000).ToString()  + "m squared");
  64.             }
  65.  
  66.  
  67.         }
  68.  
  69.  
  70.  
  71.         private void upbutton_Click(object sender, EventArgs e)
  72.         {
  73.  
  74.                 currentpositiony -= Convert.ToInt16((double.Parse(textBox1.Text) * 0.0145));
  75.                 draw();
  76.  
  77.  
  78.         }
  79.  
  80.         private void rightbutton_Click(object sender, EventArgs e)
  81.         {
  82.               currentpositionx += Convert.ToInt16((double.Parse(textBox1.Text) * 0.0145));
  83.                 draw();
  84.  
  85.         }
  86.  
  87.         private void leftbutton_Click_1(object sender, EventArgs e)
  88.         {
  89.             currentpositionx -= Convert.ToInt16((double.Parse(textBox1.Text) * 0.0145));
  90.             draw();
  91.         }
  92.  
  93.         private void downbutton_Click(object sender, EventArgs e)
  94.         {
  95.             currentpositiony += Convert.ToInt16((double.Parse(textBox1.Text) * 0.0145));
  96.             draw();
  97.         }
  98.  
  99.         private void uprightbutton_Click(object sender, EventArgs e)
  100.         {
  101.             currentpositiony -= Convert.ToInt16(double.Parse(textBox1.Text) * 0.0145 * System.Math.Sin(45));
  102.             currentpositionx += Convert.ToInt16(double.Parse(textBox1.Text) * 0.0145 * System.Math.Cos(45));
  103.             draw();
  104.         }
  105.  
  106.         private void downrightbutton_Click(object sender, EventArgs e)
  107.         {
  108.             currentpositiony += Convert.ToInt16(double.Parse(textBox1.Text) * 0.0145 * System.Math.Sin(45));
  109.             currentpositionx -= Convert.ToInt16(double.Parse(textBox1.Text) * 0.0145 * System.Math.Cos(45));
  110.            draw();
  111.         }
  112.  
  113.         private void downleftbutton_Click(object sender, EventArgs e)
  114.         {
  115.             currentpositiony += Convert.ToInt16(double.Parse(textBox1.Text) * 0.0145 * System.Math.Sin(45));
  116.             currentpositionx += Convert.ToInt16(double.Parse(textBox1.Text) * 0.0145 * System.Math.Cos(45));
  117.             draw();
  118.         }
  119.  
  120.         private void upleftbutton_Click(object sender, EventArgs e)
  121.         {
  122.             currentpositiony -= Convert.ToInt16(double.Parse(textBox1.Text) * 0.0145 * System.Math.Sin(45));
  123.             currentpositionx -= Convert.ToInt16(double.Parse(textBox1.Text) * 0.0145 * System.Math.Cos(45));
  124.             draw();
  125.         }
  126.  
  127.         private void Areabutton_Click(object sender, EventArgs e)
  128.         {
  129.             xlist.Add(xlist[0]);
  130.             ylist.Add(ylist[0]);
  131.             Area(xlist.ToArray(), ylist.ToArray(),count);
  132.         }
  133.  
  134.  
  135.         private void graphics_Load(object sender, EventArgs e)
  136.         {
  137.  
  138.             loadsg();
  139.  
  140.         }
  141.         public void loadsg()
  142.         {
  143. //i am using this as the canvas window
  144.             Graphics h = this.CreateGraphics();
  145.            Pen mypen = new Pen(Color.Blue, 5);
  146.            myrectangle = new Rectangle(180, 50, 800, 600);
  147.            h.DrawRectangle(mypen, myrectangle);
  148.  
  149.  
  150.         }
  151.  
  152.         private void cmdclear_Click(object sender, EventArgs e)
  153.         {
  154.  
  155.             g.Clear(Color.LightGray);
  156.             loadsg();
  157.           startpositionx = 190;
  158.           startpositiony = 640;
  159.           currentpositionx = 190;
  160.           currentpositiony = 640;
  161.          xlist.Clear();
  162.          ylist.Clear();
  163.          count = 0;
  164.         }
Dec 23 '09 #1
6 7964
tlhintoq
3,525 Expert 2GB
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Dec 23 '09 #2
tlhintoq
3,525 Expert 2GB
Tip: The Lists of x and y... You might want to look at the Point object to replace all that. A point has an x and y property. Its the way standard geometry works. Two points determine a line and so on.
Your startpoint would then be new point(190, 640)

how do i protect my painted window when it has been obscured by another window.
I don't understand the question. What do you mean by "protect the window" ?

Oh... wait... you might want to look at overriding the "ONPAINT" method of the form and put your drawing functionality in that. This way your drawing will take place every time the form is redrawn, like after a portion has been obstructed.

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.
A wall would be a line... which is two points.
So draw a line from the mouse coordinates of click '1' to click '2'

But I think you have a more fundamental issue with your program. Once anything is painted on your canvas, it's there for life.
You don't seem to be keeping a collection of objects, such as walls. How do you plan on letting your user make changes?
You might want to consider a 'wall' class with properties like points, thickness, pen.
Then make a List<wall>. Once you have a list of walls you can move one by changing its coordinates, then you redraw.

A door class might have properties like the points, and degrees of rotation
Then you have a list of doors.

Your drawing function then draws all your walls in the wall list, all your doors in the door list, etc.
Dec 23 '09 #3
Thank you for the advice. i really am getting the picture of wht you are saying. is it possible if you can just write me up a sample class with walls and doors, windows and one example for drawing under the override onpaint?
Dec 23 '09 #4
i have tried to implement a class like the following please correct me if am wrong and suggest any advice


Expand|Select|Wrap|Line Numbers
  1.     class wall
  2.     {
  3.         public double thickness = 0.0;
  4.         public int[] startpoint = { 0, 0 };
  5.         public int[] currentpoint = { 0, 0 };
  6.         public double walllength = 0;
  7.         public string walltype = "Single";
  8.         public Graphics wallgraphic;
  9.         public Pen wallpen;
  10.         //drawing the wall
  11.         public void drawwall(int xstart,int ystart,int  length,string wtype, string direction)
  12.         {
  13.             switch (direction)
  14.             {
  15.                 case "Right":
  16.                     {
  17.                         wallpen = new Pen(Color.Red, 4);
  18.                         wallgraphic.DrawLine(wallpen, xstart, ystart, xstart + length, ystart);
  19.                         break;
  20.                     }
  21.                default:
  22.                     {
  23.                         break;
  24.                     }
  25.            }
  26.         }
  27.  
  28.     }
  29. }
Dec 23 '09 #5
tlhintoq
3,525 Expert 2GB
Please use code tags as previously mentioned. Its part of the posting guidelines in order to make it easier to read. It helps those that are helping you. If it isn't important enough to make it easier on those help you, then it show its isn't important enough to bother reading.

TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Dec 23 '09 #6
tlhintoq
3,525 Expert 2GB
I'm not so sure that having the drawing routine inside the wall class is the best plan.

Imagine a time 6 months from now when your user will want to be able to zoom in and out to see just one room in greater detail. If your wall class does its own drawing, and the window class does its own etc. you have a lot of code to change. But if the classes only have data such as their pen style and coordinates, used by a common draw routine in the main program... then the main program can calculate a scale effect on those coordinates.

You may also want to consider a constructor to make life easier on yourself. Like this you have to make a new wall object, then set all its values. You could do it all in one step

Expand|Select|Wrap|Line Numbers
  1. public wall(Color color, Point start, Point end, String Walltype)
  2. {
  3.    WallColor = color;
  4.    StrartPoint = start;
  5.    EndPoint = end;
  6.    WallType = Walltype;
  7. }
Now you can make a
Expand|Select|Wrap|Line Numbers
  1. wall MyWall = new Wall(Color.Red, Point(4,10), Point(60,50), "Interior");
Dec 23 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: mwdsmith | last post by:
Hi, I'm new to python, and I'm not sure if this is the place to post this kind of question; so feel free to tell me if I should take this elsewhere. So, to start me off on python, I decided to...
13
by: takashi | last post by:
Hi, I have a question. I am learning about how to use c++ language. I have attempted to make my own programs, using the knowledge that I have, but sometimes when I get stuck on writing a code, it...
8
by: jay | last post by:
Hello all, I'd like to probe the community for some insight, if I may. I am in the planning stages of developing an XML generator for my workplace. Our site has an internal news system which...
3
by: rperetz | last post by:
Hi all, I was given a task to create a houseHolding logic under a table that have millions records. first let me explain what is a house holding: let's say I have 2 records that have the same...
5
by: John Baima | last post by:
I need to annotate a large store floor plan. I have the floor plans as images, and I was wondering if there is any software available which would allow me to quickly and easily create hot-spots and...
1
by: Gemmalouise1988 | last post by:
Hi everyone, My most important college assignment to date seems pretty basic on the outside but I'm sure this will interest a few of you. If you see this document:...
6
by: Arben | last post by:
Can anyone halp me to write the Java code for thid exercise? -------------------------------------------------------------------------------------------------------------- Exercise: Use the class...
2
by: Stef Mientki | last post by:
hello, In the code below, I can build a large street like this: large_street = house * 25 but not a small street. like this: small_street = 5 * house Why is this different ? And more...
7
by: =?Utf-8?B?dmlubw==?= | last post by:
Hello, I am creating a VB 2008 application and i would like to create a plan. I try with Graphics of GDI but it doesn't work how i wish. Each wall and window of my plan is a Graphic but Graphic...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.