private void propertyGrid_PropertyValueChanged(object s, PropertyValueChangedEventArgs e) { PropertyGrid props = (PropertyGrid)s; try { TextBox propTxt = (TextBox)props.SelectedObject; //PropertyCategories propLine = (PropertyCategories)props.SelectedObject; if (propTxt != null) { System.Drawing.Drawing2D.GraphicsPath myPath = new System.Drawing.Drawing2D.GraphicsPath(); myPath.AddEllipse(0, 0, propTxt.Width - 1, propTxt.Height - 1); Region myRegion = new Region(myPath); propTxt.Region = myRegion; } } catch { } try { PropertyCategories propLine = (PropertyCategories)props.SelectedObject; reDrawAll(); } catch { } }
public Edge(float k, float b, float x1, float x2, float y1, float y2, TextBox txtBoxFrom, TextBox txtBoxTo, PropertyCategories currentLine) { this.k = k; this.b = b; this.x1 = x1; this.x2 = x2; this.y1 = y1; this.y2 = y2; this.txtBoxFrom = txtBoxFrom; this.txtBoxTo = txtBoxTo; this.currentLine = currentLine; }
private void propertyGrid_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { if (e.KeyData == Keys.Enter) { PropertyGrid props = (PropertyGrid)sender; TextBox propTxt = (TextBox)props.SelectedObject; PropertyCategories propLine = (PropertyCategories)props.SelectedObject; if (propTxt != null) { System.Drawing.Drawing2D.GraphicsPath myPath = new System.Drawing.Drawing2D.GraphicsPath(); myPath.AddEllipse(0, 0, propTxt.Width - 1, propTxt.Height - 1); Region myRegion = new Region(myPath); propTxt.Region = myRegion; } if (propLine != null) { } } }
private void sheet_MouseUp(object sender, MouseEventArgs e) { if (alreadySelected == true) { if (drawEdgeButton.Enabled == false) { int k = V.Count; if ((Ox > OxSelected) && (Oy > OySelected)) { for (int i = 0; i < k; i++) { if ((V[i].txtBoxVertex.Left > OxSelected) && (V[i].txtBoxVertex.Left < Ox) && (V[i].txtBoxVertex.Top > OySelected) && (V[i].txtBoxVertex.Top < Oy)) { TextBox txt = new TextBox(); txt.Multiline = true; txt.BackColor = Color.Silver; txt.TextAlign = HorizontalAlignment.Center; //To Do по центру надо а тут сверху txt.Text = V[i].txtBoxVertex.Text; txt.Left = V[i].txtBoxVertex.Left; txt.Top = V[i].txtBoxVertex.Top; txt.Width = V[i].txtBoxVertex.Width; txt.Height = V[i].txtBoxVertex.Height; System.Drawing.Drawing2D.GraphicsPath myPath = new System.Drawing.Drawing2D.GraphicsPath(); myPath.AddEllipse(0, 0, txt.Width - 1, txt.Height - 1); Region myRegion = new Region(myPath); txt.Region = myRegion; // Пропушим себя ещё чтоб знать чо кликать txt.MouseDown += delegate(object copyTxt, MouseEventArgs me) { clickVertex(copyTxt, me); }; txt.MouseMove += delegate(object copyTxt, MouseEventArgs me) { setMouseMove(copyTxt, me); }; txt.MouseUp += delegate(object copyTxt, MouseEventArgs me) { isDragOff(copyTxt, me); }; txt.Parent = sheet; Vertex copyV = new Vertex(txt); //V[i]; V.Add(copyV); V[V.Count - 1].txtBoxVertex.Left = V[V.Count - 1].txtBoxVertex.Left + 50; V[V.Count - 1].txtBoxVertex.Top = V[V.Count - 1].txtBoxVertex.Top + 50; } } } } if (deleteButton.Enabled == false) { int k = V.Count; if ((Ox > OxSelected) && (Oy > OySelected)) { try { for (int i = 0; i < k; i++) { if ((V[i].txtBoxVertex.Left > OxSelected) && (V[i].txtBoxVertex.Left < Ox) && (V[i].txtBoxVertex.Top > OySelected) && (V[i].txtBoxVertex.Top < Oy)) { //int p = E.Count; for (int j = 0; j < E.Count; j++) { if ((V[i].txtBoxVertex == E[j].txtBoxFrom) || (V[i].txtBoxVertex == E[j].txtBoxTo)) { E.RemoveAt(j); } } V[i].txtBoxVertex.Parent = null; V.RemoveAt(i); i--; } } } catch { } } } } alreadySelected = false; newEdgeDraw = false; for (int i = 0; i < V.Count; i++) { if ((Ox > V[i].txtBoxVertex.Left) && (Ox < V[i].txtBoxVertex.Left + V[i].txtBoxVertex.Width) && (Oy > V[i].txtBoxVertex.Top) && (Oy < V[i].txtBoxVertex.Top + V[i].txtBoxVertex.Height)) { float x1 = V[i].txtBoxVertex.Left + V[i].txtBoxVertex.Left / 2; float y1 = V[i].txtBoxVertex.Left + V[i].txtBoxVertex.Left / 2; float x2 = Ox; float y2 = Oy; float k = (y2 - y1) / (x2 - x1); float b = y1 - k * x1; PropertyCategories line = new PropertyCategories(); E.Add(new Edge(k, b, V[i].txtBoxVertex.Left + 30, V[i].txtBoxVertex.Top + 30, x2, y2, txtBoxStart, V[i].txtBoxVertex, line)); } } reDrawAll(); }
//Восстанавливаем из xml public void LoadAll(string fileName) { deleteAll(); XDocument xdoc = XDocument.Load(fileName); var xElements = xdoc.Elements("vertex"); foreach (XElement el in xdoc.Root.Elements()) { if (el.Name == "vertexs") { foreach (XElement ell in el.Elements()) { if (ell.Name == "vertex") { TextBox loadTxtBox = new TextBox(); loadTxtBox.Multiline = true; loadTxtBox.Parent = sheet; loadTxtBox.BackColor = Color.Silver; loadTxtBox.Left = Int32.Parse(ell.Attribute("Left").Value); loadTxtBox.Top = Int32.Parse(ell.Attribute("Top").Value); loadTxtBox.Width = Int32.Parse(ell.Attribute("Width").Value); loadTxtBox.Height = Int32.Parse(ell.Attribute("Height").Value); loadTxtBox.Text = ell.Attribute("Text").Value; loadTxtBox.TextAlign = HorizontalAlignment.Center; //To Do по центру надо а тут сверху System.Drawing.Drawing2D.GraphicsPath myPath = new System.Drawing.Drawing2D.GraphicsPath(); myPath.AddEllipse(0, 0, loadTxtBox.Width - 1, loadTxtBox.Height - 1); Region myRegion = new Region(myPath); loadTxtBox.Region = myRegion; // Пропушим себя ещё чтоб знать чо кликать loadTxtBox.MouseDown += delegate(object sender, MouseEventArgs e) { clickVertex(sender, e); }; loadTxtBox.MouseMove += delegate(object sender, MouseEventArgs e) { setMouseMove(sender, e); }; loadTxtBox.MouseUp += delegate(object sender, MouseEventArgs e) { isDragOff(sender, e); }; V.Add(new Vertex(loadTxtBox)); } } } if (el.Name == "lines") { foreach (XElement ell in el.Elements()) { if (ell.Name == "Line") { float x1 = float.Parse(ell.Attribute("x1").Value); float x2 = float.Parse(ell.Attribute("x2").Value); float y1 = float.Parse(ell.Attribute("y1").Value); float y2 = float.Parse(ell.Attribute("y2").Value); float k; float b; try { k = float.Parse(ell.Attribute("k").Value); b = float.Parse(ell.Attribute("b").Value); } catch { k = 0; b = 0; } int from = Int32.Parse(ell.Attribute("From").Value); int To = Int32.Parse(ell.Attribute("To").Value); PropertyCategories line = new PropertyCategories(); E.Add(new Edge(k, b, x1, x2, y1, y2, V[from].txtBoxVertex, V[To].txtBoxVertex, line)); } } } } reDrawAll(); }
public void clickVertex(object sender, MouseEventArgs e) { isDrag = true; for (int i = 0; i < V.Count; i++) { V[i].txtBoxVertex.BackColor = Color.Silver; } TextBox tBox = (TextBox)sender; tBox.BackColor = Color.Red; propertyGrid.SelectedObject = tBox; //Рисуем ребро if (drawEdgeButton.Enabled == false) { if (selected1) { float x1 = tBoxEdge.Left + tBoxEdge.Width / 2; float y1 = tBoxEdge.Top + tBoxEdge.Height / 2; float x2 = tBox.Left + 10; float y2 = tBox.Top + 10; float k = (y2 - y1) / (x2 - x1); float b = y1 - ((y2 - y1) * x1) / (x2 - x1); System.Drawing.Pen koord; koord = new System.Drawing.Pen(System.Drawing.Color.Black, 3); AdjustableArrowCap bigArrow = new AdjustableArrowCap(7, 9); koord.CustomStartCap = bigArrow; //koord.StartCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; System.Drawing.Graphics MyFormGrap = sheet.CreateGraphics(); MyFormGrap.DrawLine(koord, x2, y2, x1, y1); //пишем string str = "лол"; float nStrX = (x1 + x2) / 2; float nStrY = (y1 + y2) / 2; MyFormGrap.DrawString(str, new Font(FontFamily.GenericSansSerif, 12.0F, FontStyle.Regular), new SolidBrush(System.Drawing.Color.Black), nStrX, nStrY); koord.Dispose(); MyFormGrap.Dispose(); PropertyCategories line = new PropertyCategories(); E.Add(new Edge(k, b, x1, x2, y1, y2, tBoxEdge, tBox, line)); selected1 = false; } else { selected1 = true; tBoxEdge = tBox; } } //удаляем вершину if (deleteButton.Enabled == false) { for (int i = 0; i < V.Count; i++) { if (V[i].txtBoxVertex == tBox) { V.RemoveAt(i); } } //Двойной цикл потому что при одинарном походу сбивается i for (int i = 0; i < E.Count; i++) { for (int j = 0; j < E.Count; j++) { if ((E[j].txtBoxFrom == tBox) || (E[j].txtBoxTo == tBox)) { E.RemoveAt(j); } } } tBox.Parent = null; tBox = null; reDrawAll(); } }