/// <summary>Handles creating a previewform for the UserTrace image and its big big subroutine</summary> /// <param name="sender"></param> /// <param name="e"></param> private void PreviewPictureBox_Click(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Right && e.Button != MouseButtons.Left) { return; } fromPreviewPane = true; //If the usertrace is empty, just show it anyways. if (MyTrace.AllUsers.Count == 0 && e.Button == MouseButtons.Right) { UsersContextMenu.Show(PreviewPictureBox, e.Location); fromPreviewPane = false; return; } //Let's find the top right corner of the image. Size ImageSize = PreviewPictureBox.Image.Size; Size BoxSize = PreviewPictureBox.Size; Size RealImageSize = PreviewPictureBox.Size; int PictureX = 0; int PictureY = 0; double scale = 1; //Get the aspect ratio of the picturebox and image. double BoxWidthToHeight = (BoxSize.Width + 0.0) / (BoxSize.Height + 0.0); double ImageWidthToHeight = (ImageSize.Width + 0.0) / (ImageSize.Height + 0.0); if (ImageSize.Equals(BoxSize)) { //do nothing the thing is set. } else if (ImageWidthToHeight > BoxWidthToHeight) { //Find the correct Y //It's wider than it's tall //determine the scale scale = (ImageSize.Width + 0.0) / (BoxSize.Width + 0.0); //Determine the size of the image on screen RealImageSize = new Size(Convert.ToInt32(ImageSize.Width / scale), Convert.ToInt32(ImageSize.Height / scale)); //Now determine the correct Y PictureY = (BoxSize.Height - RealImageSize.Height) / 2; } else { //It's taller than it's wide //find the correct X //Determine the scale scale = (ImageSize.Height + 0.0) / (BoxSize.Height + 0.0); //Determine the size of the image on screen RealImageSize = new Size(Convert.ToInt32(ImageSize.Width / scale), Convert.ToInt32(ImageSize.Height / scale)); //Now determine the correct X PictureX = (BoxSize.Width - RealImageSize.Width) / 2; } //OK now that we know where the picture is and its size. //Now we have to translate the point that we clicked on to a point on the image. //first lets determine if we're in or out of the rectangle that contains the image. Rectangle ImageRectangle = new Rectangle(PictureX, PictureY, RealImageSize.Width, RealImageSize.Height); //If it isn't then oh my god we've literally done everything if (!ImageRectangle.Contains(e.Location)) { fromPreviewPane = false; return; } //Convert //subtract PictureX and Picture Y from the click position. int ClickPointX = e.X - PictureX; int ClickPointY = e.Y - PictureY; //now scale it. ClickPointX = Convert.ToInt32(ClickPointX * scale); ClickPointY = Convert.ToInt32(ClickPointY * scale); User ColideUser = null; foreach (User U in MyTrace.AllUsers) { //Create a rectangle that's going to represent this user. if (new Rectangle(U.DrawnX, U.DrawnY, U.Width(), U.Height()).Contains(ClickPointX, ClickPointY)) { ColideUser = U; break; } } if (!(ColideUser is null)) { //lets draw algo: using (Pen T = new Pen(new SolidBrush(Color.Red), 10)) using (Graphics GRD = Graphics.FromImage(PreviewPictureBox.Image)) { GRD.DrawRectangle(T, ColideUser.DrawnX, ColideUser.DrawnY, ColideUser.Width(), ColideUser.Height()); } PreviewPictureBox.Refresh(); using (Pen T = new Pen(new SolidBrush(Color.Black), 10)) using (Graphics GRD = Graphics.FromImage(PreviewPictureBox.Image)) { GRD.DrawRectangle(T, ColideUser.DrawnX, ColideUser.DrawnY, ColideUser.Width(), ColideUser.Height()); } UserListView.Items[MyTrace.AllUsers.IndexOf(ColideUser)].Selected = true; if (e.Button == MouseButtons.Left) { EditButton_Click(PreviewPictureBox, new EventArgs()); } if (e.Button == MouseButtons.Right) { UsersContextMenu.Show(PreviewPictureBox, e.Location); } }
private void PageTrackBar_Scroll(object sender, EventArgs e) { PreviewPictureBox.ShowPage(PageTrackBar.Value); }