/// <summary> /// /// </summary> /// <param name="tabName"></param> /// <param name="imgPath"></param> /// <param name="fromFile"></param> private void CreateNewTab(string tabName, string imgPath, bool fromFile) { GroupBox tabGroupBox = new GroupBox(); tabGroupBox.Size = new Size(projectDisplaySize.Width + 100, projectDisplaySize.Height + 100); tabGroupBox.Location = new Point(((tabControlDesignerView.Width / 2) - (tabGroupBox.Width / 2)), 50); tabGroupBox.Text = "Designer View"; tabGroupBox.Anchor = AnchorStyles.Top; //Makes the groupBox relocate when the form is resized by the user PictureBox designerViewPage = new PictureBox(); designerViewPage.Size = projectDisplaySize; //The height and width need to be formatted so they will fit within the window but the aspect ratio needs to stay the same designerViewPage.Location = new Point(50, 50); designerViewPage.MouseClick += new MouseEventHandler(PictureBox_Click); designerViewPage.Name = tabName; //This is for when the user clicks on the picture box I don't have to try and get the tab name designerViewPage.BackgroundImageLayout = ImageLayout.Stretch; RightClickContextMenu picBoxCM = new RightClickContextMenu(); picBoxCM.MenuItems.Add("Delete Button", new EventHandler(DeleteButton_Click)); picBoxCM.MenuItems.Add("Alter Page Link", new EventHandler(AlterButton_Click)); picBoxCM.Name = tabName; cmLst.Add(picBoxCM); Timer buttonDrawing = new Timer(); buttonDrawing.Interval = 10; //Interval is 10 maybe change this so that it is less CPU intensive buttonDrawing.Enabled = true; buttonDrawing.Tag = tabName; buttonDrawing.Tick += new EventHandler((sender, e) => Timer_Tick(sender, e, designerViewPage, imgPath)); timerLst.Add(buttonDrawing); TabPage tabPage = new TabPage(); tabPage.Text = tabName; tabPage.AutoScroll = true; designerViewPage.ContextMenu = picBoxCM; tabGroupBox.Controls.Add(designerViewPage); tabControlDesignerView.TabPages.Add(tabPage); tabPage.Controls.Add(tabGroupBox); //Might want to improve this NewTabPage newTab = new NewTabPage(); newTab.tabName = tabName; newTab.picBox = designerViewPage; newTab.grpBox = tabGroupBox; newTab.percentageOfZoom = 100f; tabLst.Add(newTab); if (fromFile == false) { DisplayPage newDP = new DisplayPage(tabName); newDP.AddImagePath(imgPath); pageLst.Add(newDP); } }
private void AlterButton_Click(object sender, EventArgs e) { //The code in this function is discgusting and almost getting to the point of spaghetti code //Shits getting hard to keep track of and needs to be optimised //Grabs the point on the picturebox the right click was made RightClickContextMenu rcm = new RightClickContextMenu(); PictureBox pic = new PictureBox(); double percentageOfZoom = 0; double xCoordinate = 0; double yCoordinate = 0; foreach (NewTabPage t in tabLst) { if (t.tabName == tabControlDesignerView.SelectedTab.Text) { pic = t.picBox; percentageOfZoom = t.percentageOfZoom; break; } } foreach (RightClickContextMenu r in cmLst) { if (r.Name == tabControlDesignerView.SelectedTab.Text) { xCoordinate = r.p.X; yCoordinate = r.p.Y; break; } } //Maybe I should put this in its own fuction seen as it's repeated so many times var screenPosition = pic.PointToScreen(new Point(0, 0)); Point p = new Point((int)((xCoordinate - screenPosition.X) / (percentageOfZoom / 100)), (int)((yCoordinate - screenPosition.Y) / (percentageOfZoom / 100))); DetectIfPointIsInside detectIfPoint = new DetectIfPointIsInside(projectDisplaySize.Width); if (p != null && p != new Point(0, 0)) { foreach (DisplayPage d in pageLst) { if (d.displayPageName == tabControlDesignerView.SelectedTab.Text) { foreach (CustomButton c in d.GetButtonList()) { if (detectIfPoint.DoesIntersect(c.GetPoly(), c.GetPoly().Length, p)) { c.SetPageLink(GetSelectedPage()); break; } } foreach (CircleButton c in d.GetCircleBtnLst()) { if (detectIfPoint.DoesIntersectCircle(c.GetRadius(), p, c.GetCentre())) { c.SetPageLink(GetSelectedPage());; break; } } break; } } } else { MessageBox.Show("Error could not find the point the right click was made", "INTERNAL ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } }