473,513 Members | 2,397 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Connection between 2 points with Draw method

1 New Member
Hello guys,
My problem is that when I want to draw 2 points on the form and connect them, the points do not appear but the connections are still on the form. I am using DrawEllipse and DrawLine methods.

Expand|Select|Wrap|Line Numbers
  1.  public partial class Form1 : Form
  2.     {
  3.         private Point p1, p2;
  4.         List<Point> p1List = new List<Point>();
  5.         List<Point> p2List = new List<Point>();
  6.  
  7.         public Form1()
  8.         {
  9.             InitializeComponent();
  10.         }
  11.  
  12.         private void Form1_Paint(object sender, PaintEventArgs e)
  13.         {
  14.  
  15.  
  16.             using (var p = new Pen(Color.Blue, 4))
  17.             {
  18.                 for (int x = 0; x < p1List.Count; x++)
  19.                 {
  20.                     e.Graphics.DrawLine(p, p1List[x], p2List[x]);
  21.                 }
  22.             }
  23.  private void Form1_MouseDown(object sender, MouseEventArgs e)
  24.         {
  25.  
  26.             Graphics gr = this.CreateGraphics();
  27.  
  28.             int x = e.X;
  29.             int y = e.Y;
  30.  
  31.             // Create pen.
  32.             Pen whitePen = new Pen(Color.Blue, 3);
  33.             Pen red = new Pen(Color.Red, 3);
  34.             SolidBrush whiteBrush = new SolidBrush(Color.Blue);
  35.  
  36.             // Create rectangle for ellipse.
  37.             Rectangle rect = new Rectangle(x - 5, y - 5, 10, 10);
  38.  
  39.             gr.DrawEllipse(whitePen, rect);
  40.             gr.FillEllipse(whiteBrush, rect);
  41.  
  42.             if (p1.X == 0)
  43.             {
  44.                 p1.X = e.X;
  45.                 p1.Y = e.Y;
  46.             }
  47.             else
  48.             {
  49.                 p2.X = e.X;
  50.                 p2.Y = e.Y;
  51.  
  52.                 p1List.Add(p1);
  53.                 p2List.Add(p2);
  54.  
  55.                 Invalidate();
  56.                 p1.X = 0;
  57.             }
  58.          }
  59.  
  60.  
  61.  
  62.         }
On the first picture you can see my first click on the form it draws a point and on the second picture the connection is drawn but without the points.
I need your help please!
Attached Images
File Type: jpg point.jpg (11.1 KB, 85 views)
File Type: jpg connection.jpg (14.1 KB, 71 views)
Mar 24 '14 #1
0 1056

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

Similar topics

6
1762
by: John | last post by:
I wrote this class class CLine { public float sX,sY,dX,dY,m,x,y; public void Draw (PaintEventArgs g) { //Graphics g = this.CreateGraphics (); Bitmap bm=new Bitmap(1,1);
6
538
by: harrylmh | last post by:
Hi, I'm learning C# and I just don't quite understand the need for polymorphism. why do we need to use it? how does a base class variable holding a derived class instance do any good? Also,...
1
1413
by: VSNT | last post by:
Is there a way to access the painting of a MainMenu so as to change its back color and add icons like i can with MenuItem? Thanks, Allen
1
2106
by: lallous | last post by:
Hello I am not very experienced with this issue and would your opinion on whether it is healthy or not: 1) I created an ATL COM object (say MyCOM): - that supports connection points - that...
11
28108
by: placid | last post by:
Hi all, Is it possible to be able to do the following in Python? class Test: def __init__(self): pass def puts(self, str): print str
0
1246
by: =?Utf-8?B?TWFyYyBXb29sZnNvbg==?= | last post by:
Hello, I can't seem to find any information on how best to implement multiple connections on a consumer web part and was wondering if anyone could point me in the right direction. I have...
1
1436
by: busiswa | last post by:
Hi All, I am just new in PHP, i am asked to draw a combobox using the draw() method. Can someone help me on how to go about that. Thank you, Busi
4
5468
by: KiddoGuy | last post by:
I want to loop through an array of numbers and use those to plot points. What method should I be thinking of? I know there's one that takes an X and Y coordinate and draws points. Is there one that...
1
2016
by: game2d | last post by:
I am trying to create a triangle in openGL 2.0 but some some reason background is shows up but no triangle. I am following this tutorial:...
0
7177
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7394
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7559
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7123
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7542
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5701
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3248
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.