public void getSizesForEachRowsAndColumns(int row, int col) { int imageWidthinPanel = (this.Size.Width / col) - paddingValue; int imageHeightPanel = (this.Size.Height / row) - paddingValue; int pictureBox_X = 0; int pictureBox_Y = 0; { { PictureBoxExtended pb = new PictureBoxExtended(); pb.SizeMode = PictureBoxSizeMode.Zoom; pb.Margin = new System.Windows.Forms.Padding(0); if (File.Exists("Test1.jpg")) { pb.Image = new Bitmap("Test1.jpg"); } else { pb.Image = new Bitmap(2048, 1536); } pb.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; pb.Location = new Point(pictureBox_X, pictureBox_Y + paddingValue); //if (imageHeightPanel - paddingValue > 0) // pb.Size = new Size(imageWidthinPanel, imageHeightPanel - paddingValue); //else pb.Size = new Size(imageWidthinPanel, imageHeightPanel); var wfactor = (double)pb.Image.Width / pb.ClientSize.Width; var hfactor = (double)pb.Image.Height / pb.ClientSize.Height; var resizeFactor = Math.Max(wfactor, hfactor); if (!imageSizeList.Contains(new RowColumnFactorsWithSize(row, col, new Size((int)(pb.Image.Width / resizeFactor), (int)(pb.Image.Height / resizeFactor))))) { imageSizeList.Add(new RowColumnFactorsWithSize(row, col, new Size((int)(pb.Image.Width / resizeFactor), (int)(pb.Image.Height / resizeFactor)))); } } } }
public void createPanel(int row, int col) { int imageWidthinPanel = (this.Size.Width / col) - paddingValue; int imageHeightPanel = (this.Size.Height / row) - paddingValue; int pictureBox_X = 5; int pictureBox_Y = 0; imgCount = 0; for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { pb = new PictureBoxExtended(); pb.SizeMode = PictureBoxSizeMode.Zoom; pb.Margin = new System.Windows.Forms.Padding(0); pb.Index = ++imgCount; if (imgCount <= Images) { if (File.Exists("Test1.jpg")) { pb.Image = new Bitmap("Test1.jpg"); } else { pb.Image = new Bitmap(2048, 1536); } } else { pb.Image = new Bitmap(2048, 1536); } pb.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; pb.Location = new Point(pictureBox_X, pictureBox_Y); pb.Size = new Size(imageWidthinPanel, imageHeightPanel - paddingValue); pb.Paint += pb_Paint; this.Controls.Add(pb); pictureBox_X += imageWidthinPanel + paddingValue; } pictureBox_Y += imageHeightPanel + paddingValue; pictureBox_X = 5; } this.Refresh(); }
void pb_Paint(object sender, PaintEventArgs e) { PictureBoxExtended pb = sender as PictureBoxExtended; var wfactor = (double)pb.Image.Width / pb.ClientSize.Width; var hfactor = (double)pb.Image.Height / pb.ClientSize.Height; var resizeFactor = Math.Max(wfactor, hfactor); var zoomedImageSize = new Size((int)(pb.Image.Width / resizeFactor), (int)(pb.Image.Height / resizeFactor)); int height = pb.Height - zoomedImageSize.Height; int width = pb.Width - zoomedImageSize.Width; SolidBrush solidBrush = new SolidBrush(Color.Black); if (pb.Index <= Images) { Graphics g = pb.Parent.CreateGraphics(); int stringWidth = TextRenderer.MeasureText("Image " + pb.Index.ToString(), new System.Drawing.Font(new System.Drawing.FontFamily("Times New Roman"), 10)).Width;; g.DrawString("Image " + pb.Index.ToString(), new System.Drawing.Font(new System.Drawing.FontFamily("Times New Roman"), 10), solidBrush, new PointF((float)((pb.Location.X + pb.Width / 2) - stringWidth / 2), (float)(pb.Location.Y - 15))); } //Console.WriteLine(pb.Location.X.ToString()+"__"+ pb.Location.Y.ToString()); }
void pbPaint(object sender, PaintEventArgs e) { PictureBoxExtended pb = sender as PictureBoxExtended; var wfactor = (double)pb.Image.Width / pb.ClientSize.Width; var hfactor = (double)pb.Image.Height / pb.ClientSize.Height; var resizeFactor = Math.Max(wfactor, hfactor); var zoomedImageSize = new Size((int)(pb.Image.Width / resizeFactor), (int)(pb.Image.Height / resizeFactor)); int height = pb.Height - zoomedImageSize.Height; int width = pb.Width - zoomedImageSize.Width; SolidBrush solidBrush = new SolidBrush(Color.Black); if (pb.Index <= Images) { if (pb.Tag != null) { Graphics g = pb.Parent.CreateGraphics(); int stringWidth = TextRenderer.MeasureText(pb.Tag.ToString(), new System.Drawing.Font(new System.Drawing.FontFamily("Times New Roman"), 10)).Width;; #region Code to display Right eye and left eye instead of OD and OS if it is DR report string name = string.Empty; if (!isMedicalName) { if (pb.Tag.ToString().Contains("OS")) { name = "Left Eye"; } else if (pb.Tag.ToString().Contains("OD")) { name = "Right Eye"; } } #endregion else { name = pb.Tag.ToString(); } g.DrawString(name, new System.Drawing.Font(new System.Drawing.FontFamily("Times New Roman"), 10), solidBrush, new PointF((float)((pb.Location.X + pb.Width / 2) - stringWidth / 2), (float)(pb.Location.Y + pb.Height))); } } //Console.WriteLine(pb.Location.X.ToString()+"__"+ pb.Location.Y.ToString()); }
public Point GetPictureBoxPoint(PictureBoxExtended pb) { Point p = pb.PointToClient(Cursor.Position); Point unscaled_p = new Point(); // image and container dimensions int w_i = pb.Image.Width; int h_i = pb.Image.Height; int w_c = pb.Width; int h_c = pb.Height; float imageRatio = w_i / (float)h_i; // image W:H ratio float containerRatio = w_c / (float)h_c; // container W:H ratio if (imageRatio >= containerRatio) { // horizontal image float scaleFactor = w_c / (float)w_i; float scaledHeight = h_i * scaleFactor; // calculate gap between top of container and top of image float filler = Math.Abs(h_c - scaledHeight) / 2; unscaled_p.X = (int)(p.X / scaleFactor); unscaled_p.Y = (int)((p.Y - filler) / scaleFactor); } else { // vertical image float scaleFactor = h_c / (float)h_i; float scaledWidth = w_i * scaleFactor; float filler = Math.Abs(w_c - scaledWidth) / 2; unscaled_p.X = (int)((p.X - filler) / scaleFactor); unscaled_p.Y = (int)(p.Y / scaleFactor); } return(unscaled_p); }
public void createPanel(int row, int col, string name) { int imageWidthinPanel = (this.Size.Width / col) - paddingValue; int imageHeightPanel = (this.Size.Height / row) - paddingValue; int pictureBox_X = 5; int pictureBox_Y = 0; imgCount = 0; for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { PictureBoxExtended pb = new PictureBoxExtended(); pb.SizeMode = PictureBoxSizeMode.Zoom; pb.Margin = new System.Windows.Forms.Padding(0); { ToolTip tt = new ToolTip(); tt.AutoPopDelay = 500; tt.InitialDelay = 1000; tt.ReshowDelay = 500; tt.SetToolTip(pb, "Select Images"); } if (imgCount < Images && Images > 0) { if (File.Exists(imagePaths[imgCount])) { Common.CommonMethods common_methods = Common.CommonMethods.CreateInstance(); Bitmap bm = new Bitmap(10, 10); LoadSaveImage.LoadImage(imagePaths[imgCount], ref bm); pb.Image = bm; } else { pb.Image = new Bitmap(2048, 1536); } } else { pb.Image = new Bitmap(2048, 1536); } if (imgCount < Images && Images > 0 && imageNames.Length == Images) { pb.Tag = imageNames[imgCount]; } pb.Index = ++imgCount; pb.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; pb.Location = new Point(pictureBox_X, pictureBox_Y); pb.Size = new Size(imageWidthinPanel, imageHeightPanel - paddingValue); pb.Click += pb_Click; pb.Paint += pbPaint; this.Controls.Add(pb); pictureBox_X += imageWidthinPanel + paddingValue; } pictureBox_Y += imageHeightPanel + paddingValue; pictureBox_X = 5; } this.Refresh(); }
public void createTable() { switch (images.Length) { case 1: { this.RowCount = 1; this.ColumnCount = 1; break; } case 2: if (isPortrait) { this.RowCount = 2; this.ColumnCount = 1; } else { this.RowCount = 1; this.ColumnCount = 2; } this.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50)); this.RowStyles.Add(new RowStyle(SizeType.Percent, 50)); break; case 3: this.RowCount = 2; this.ColumnCount = 2; this.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50)); this.RowStyles.Add(new RowStyle(SizeType.Percent, 50)); break; case 4: this.RowCount = 2; this.ColumnCount = 2; this.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50)); this.RowStyles.Add(new RowStyle(SizeType.Percent, 50)); break; case 5: if (isPortrait) { this.RowCount = 3; this.ColumnCount = 2; } else { //this.RowCount = 2; //this.ColumnCount = 3; this.RowCount = 3; this.ColumnCount = 2; } this.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50)); this.RowStyles.Add(new RowStyle(SizeType.Percent, 50)); break; case 6: if (isPortrait) { this.RowCount = 3; this.ColumnCount = 2; } else { //this.RowCount = 2; //this.ColumnCount = 3; this.RowCount = 3; this.ColumnCount = 2; } this.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50)); this.RowStyles.Add(new RowStyle(SizeType.Percent, 50)); break; case 7: { //this.ColumnStyles.RemoveAt(0); //this.ColumnStyles.RemoveAt(0); this.RowCount = 4; this.ColumnCount = 2; //this.ColumnStyles.Insert(0, new ColumnStyle(SizeType.Percent, 25)); //this.ColumnStyles.Insert(1, new ColumnStyle(SizeType.Percent, 25)); //this.ColumnStyles.Insert(2, new ColumnStyle(SizeType.Percent, 25)); //this.ColumnStyles.Insert(3, new ColumnStyle(SizeType.Percent, 25)); this.RowStyles.Insert(0, new RowStyle(SizeType.Percent, 25)); this.RowStyles.Insert(1, new RowStyle(SizeType.Percent, 25)); this.RowStyles.Insert(2, new RowStyle(SizeType.Percent, 25)); this.RowStyles.Insert(3, new RowStyle(SizeType.Percent, 25)); //this.RowCount = 4; //this.ColumnCount = 2; //this.RowCount = 3; //this.ColumnCount = 3; } this.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50)); //this.RowStyles.Add(new RowStyle(SizeType.Percent, 25)); break; default: this.RowCount = 2; this.ColumnCount = 2; break; } int imgCnt = 0; for (int i = 0; i < this.RowCount; i++) { for (int j = 0; j < this.ColumnCount; j++) { Label lbl = new Label(); PictureBoxExtended pb = new PictureBoxExtended(); pb.SizeMode = PictureBoxSizeMode.Zoom; pb.Margin = new System.Windows.Forms.Padding(0); try { pb.Image = new Bitmap("Test1.jpg"); pb.Dock = DockStyle.Fill; lbl.BackColor = Color.Transparent; lbl.Text = "Image " + (1 + imgCnt).ToString(); lbl.Margin = new System.Windows.Forms.Padding(0); lbl.Dock = DockStyle.Top; lbl.TextAlign = ContentAlignment.MiddleCenter; } catch (Exception ex) { Console.WriteLine(ex.Message); } Panel pnl = new Panel(); pnl.Dock = DockStyle.Fill; pnl.Controls.Add(pb); pnl.Controls.Add(lbl); this.Controls.Add(pnl, j, i); //MessageBox.Show("Image " + (1 + imgCnt).ToString() + "PictureBox details" + "Location " + "x=" + pb.Location.X.ToString() + "y =" + pb.Location.Y.ToString() + "Size width=" + pb.Image.Width + "Height=" + pb.Image.Height); //MessageBox.Show(" Panel Details" + "Location " + "x=" + pnl.Location.X.ToString() + "y =" + pnl.Location.Y.ToString() + "Size width=" + pnl.Width + "Height=" + pnl.Height); imgCnt++; } } //GetImageWidthHeight(); }