我有一個圖片框(圖片框1),並在該框中繪製了一個矩形,並使用另一個圖片框(圖片框2)顯示繪製的部分。問題是當我畫矩形(圖片框1)時,圖片框2不會顯示,但當更改窗體的位置(移動窗體)時,圖片框2出現。Diaplay圖像問題
如何顯示所繪製的藥水......
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.DrawRectangle(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();
}
}
Winforms或WPF? – 2010-06-29 11:26:31
如果您正在對控件進行自定義繪製,則可能需要修改代碼。如果您提供適當的代碼部分,這將有所幫助。 – Nayan 2010-06-29 11:36:18
這將有助於發佈一些代碼。您的問題似乎是PictureBox 2不會呈現,除非您重新繪製表單。該代碼將幫助診斷可能發生的原因。 – Prashant 2010-06-29 11:38:25