Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace lab07_live
- {
- public partial class Form1 : Form
- {
- public List<MyNode> obiekty = new List<MyNode>();
- public List<MyLine> linie = new List<MyLine>();
- public Pen Pioro = new Pen(Color.Black, 50);
- public Pen PioroLinie = new Pen(Color.Black, 2);
- public int X;
- public int Y;
- public int ObjectCount = 1;
- public Form1()
- {
- InitializeComponent();
- }
- private void panel1_MouseDown(object sender, MouseEventArgs e)
- {
- X = e.X;
- Y = e.Y;
- MyNode Wezel = new MyNode(X, Y);
- obiekty.Add(Wezel);
- panel1.Refresh();
- Wezel.Text = $"Obiekt {ObjectCount.ToString()}";
- treeView1.Nodes.Add(Wezel);
- ObjectCount++;
- for (int i = 0; i < obiekty.Count-1; i++)
- {
- double roznica1 = Math.Pow((Math.Abs(Wezel.NodeX - obiekty[i].NodeX)), 2);
- double roznica2 = Math.Pow((Math.Abs(Wezel.NodeY - obiekty[i].NodeY)), 2);
- if (Math.Sqrt(roznica1+roznica2) < 150)
- {
- obiekty[i].NCount++;
- obiekty[i].Nodes.Add(new MyNode(Wezel.NodeX,Wezel.NodeY,$"Sฤ siad {obiekty[i].NCount.ToString()}"));
- MyLine Nowa = new MyLine(Wezel.NodeX,Wezel.NodeY,obiekty[i].NodeX,obiekty[i].NodeY);
- linie.Add(Nowa);
- panel1.Refresh();
- }
- }
- }
- private void panel1_Paint(object sender, PaintEventArgs e)
- {
- Graphics g = e.Graphics;
- for (int i = 0; i < obiekty.Count; i++)
- {
- g.DrawEllipse(Pioro,obiekty[i].NodeX,obiekty[i].NodeY,5, 5);
- }
- for (int i = 0; i < linie.Count; i++)
- {
- g.DrawLine(PioroLinie, linie[i].sx, linie[i].sy, linie[i].ex, linie[i].ey);
- }
- }
- private void panel1_MouseMove(object sender, MouseEventArgs e)
- {
- toolStripStatusLabel1.Text = $"{e.X}, {e.Y}";
- }
- }
- public class MyNode : TreeNode
- {
- public int NodeX, NodeY;
- public int NCount = 0;
- //TreeNode dziedziczy tez naturalnie liste sasiadow
- public MyNode(int x, int y)
- {
- NodeX = x;
- NodeY = y;
- }
- public MyNode(int x, int y, string n)
- {
- NodeX = x;
- NodeY = y;
- Text = n;
- }
- }
- public class MyLine
- {
- public int sx, sy, ex, ey;
- public MyLine(int x1, int y1, int x2, int y2)
- {
- sx = x1;
- sy = y1;
- ex = x2;
- ey = y2;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement