private void pnCanvas_MouseMove(object sender, MouseEventArgs e) { Point current = e.Location; bool found = false; foreach (TFTControl control in TFTCan.GetControls()) { if (IsPointInControl(control, current)) { hovered = control; found = true; } } if (!found) { hovered = null; } if (selected != null && MouseButtonDown) { selected.X = e.X - offset.X; selected.Y = e.Y - offset.Y; TFTCan.RedrawControls(); } }
private void lvControls_MouseDoubleClick(object sender, MouseEventArgs e) { if (lvControls.SelectedItems.Count > 0) { string control = lvControls.SelectedItems[0].Text; TFTControl con = null; if (control == "Button") { con = new TFTButton(10, 10, 100, 50, TFTCan); TFTCan.RedrawControls(); } else if (control == "Label") { con = new TFTLabel(10, 10, 100, 50, TFTCan); TFTCan.RedrawControls(); } else if (control == "Rectangle") { con = new TFTRectangle(10, 10, 100, 50, TFTCan); TFTCan.RedrawControls(); } if (con != null) { LoadProperties(con); selected = con; } } }
private void pnCanvas_MouseDown(object sender, MouseEventArgs e) { MouseButtonDown = true; selected = hovered; Debug.WriteLine("Selected Control: " + selected); if (selected != null) { LoadProperties(selected); offset = new Point(e.X - selected.X, e.Y - selected.Y); } else { dgvProperties.DataSource = null; } }
private bool IsPointInControl(TFTControl control, Point point) { return((point.X >= control.X) && (point.X <= (control.X + control.Width)) && (point.Y >= control.Y) && (point.Y <= (control.Y + control.Height))); }
public void AddControl(TFTControl con) { TFTCan.AddControl(con); TFTCan.RedrawControls(); }
private void LoadProperties(TFTControl sel) { //Load standard Properties (base class) DataTable table = new DataTable(); table.Columns.Add("Property"); table.Columns.Add("Value"); DataRow row = table.NewRow(); row["Property"] = nameof(sel.Name); row["Value"] = sel.Name; table.Rows.Add(row); row = table.NewRow(); row["Property"] = nameof(sel.X); row["Value"] = sel.X; table.Rows.Add(row); row = table.NewRow(); row["Property"] = nameof(sel.Y); row["Value"] = sel.Y; table.Rows.Add(row); row = table.NewRow(); row["Property"] = nameof(sel.Width); row["Value"] = sel.Width; table.Rows.Add(row); row = table.NewRow(); row["Property"] = nameof(sel.Height); row["Value"] = sel.Height; table.Rows.Add(row); row = table.NewRow(); row["Property"] = nameof(sel.BorderWith); row["Value"] = sel.BorderWith; table.Rows.Add(row); row = table.NewRow(); row["Property"] = nameof(sel.Text); row["Value"] = sel.Text; table.Rows.Add(row); row = table.NewRow(); row["Property"] = nameof(sel.FontSize); row["Value"] = sel.FontSize; table.Rows.Add(row); row = table.NewRow(); row["Property"] = nameof(sel.BackgroundColor); row["Value"] = sel.BackgroundColor; table.Rows.Add(row); row = table.NewRow(); row["Property"] = nameof(sel.ForegroundColor); row["Value"] = sel.ForegroundColor; table.Rows.Add(row); if (sel is TFTRectangle rect) { //nothing } else if (sel is TFTButton btn) { row = table.NewRow(); row["Property"] = nameof(btn.AutoSize); row["Value"] = btn.AutoSize; table.Rows.Add(row); } else if (sel is TFTLabel lbn) { //nothing } dgvProperties.Tag = sel; dgvProperties.DataSource = table; }