Diaplay image issue
I have a picture box (picture box 1) and in that box have drawn a rectangle and displayed the drawn portion using another picture box (picture box 2). Problem is when i draw rectangle (in picture box 1)the picture box 2 will not shows up but when change the position of the form (move the form) the picture box 2 shows up.
How to display the drawn potion...
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
using (Pen pen = new Pen(Color.Green, 2))
{
pen.Color = Color.Red;
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
e.Graphics.D开发者_运维百科rawRectangle(pen, rect);
foreach (Rectangle r in rectangles)
{
label1.Top = r.Top; label1.Left = r.Left; label1.Width = r.Width;
label1.Height = r.Height;
e.Graphics.DrawRectangle(pen, r);
e.Graphics.DrawString(label1.Text, label1.Font, new SolidBrush(label1.ForeColor), r);
}
}
if (!(rect.Width <= 0 | rect.Height <= 0))
{
sz1.Width = rect.Width * Convert.ToInt16(1.5);
sz1.Height = rect.Height * Convert.ToInt16(1.5);
pictureBox2.Size = sz1;
w.X = 500; w.Y = 20;
pictureBox2.Location = w;
Bitmap niv = new Bitmap(pictureBox2.Width, pictureBox2.Height);
using (Graphics g1 = Graphics.FromImage(niv))
{
g1.InterpolationMode = InterpolationMode.HighQualityBicubic;
g1.DrawImage(pictureBox1.Image, pictureBox2.ClientRectangle, rect, GraphicsUnit.Pixel);
}
pictureBox2.Image = niv;
pictureBox2.Visible = true;
pictureBox2.Invalidate();
}
}
You can paint or repainting your picturebox using the OnPaint event.
I got it. just right click on the picture box2 and selected "Bring to Front" option.
精彩评论