Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 底辟图像问题_C#_Winforms - Fatal编程技术网

C# 底辟图像问题

C# 底辟图像问题,c#,winforms,C#,Winforms,我有一个图片框(图片框1),在该框中绘制了一个矩形,并使用另一个图片框(图片框2)显示了绘制的部分。问题是,当我绘制矩形(在图片框1中)时,图片框2不会显示,但当更改表单位置(移动表单)时,图片框2会显示 如何显示绘制的药剂 private void pictureBox1_Paint(object sender, PaintEventArgs e) { using (Pen pen = new Pen(Color.Green, 2)) { pen.Color =

我有一个图片框(图片框1),在该框中绘制了一个矩形,并使用另一个图片框(图片框2)显示了绘制的部分。问题是,当我绘制矩形(在图片框1中)时,图片框2不会显示,但当更改表单位置(移动表单)时,图片框2会显示

如何显示绘制的药剂

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();
    } 
}
private void pictureBox1\u Paint(对象发送方,PaintEventArgs e)
{
使用(钢笔=新钢笔(颜色:绿色,2))
{
pen.Color=Color.Red;
pen.DashStyle=System.Drawing.Drawing2D.DashStyle.Dash;
e、 绘图矩形(钢笔、矩形);
foreach(矩形中的矩形r)
{
label1.Top=r.Top;label1.Left=r.Left;label1.Width=r.Width;
标签1.高度=r.高度;
e、 绘图矩形(钢笔,r);
e、 图形.抽绳(label1.Text,label1.Font,新SolidBrush(label1.ForeColor),r);
}
}

如果(!(rect.Width您可以使用OnPaint事件绘制或重新绘制您的picturebox。

我知道了。只需右键单击图片框2并选择“带到前面”选项。

如果您正在对控件进行自定义绘制,则可能需要修改代码。如果您提供了适当的代码部分,这会有所帮助。发布一些代码会有所帮助。您的问题似乎是,除非您重新绘制表单,否则PictureBox 2不会呈现。代码将帮助诊断可能发生这种情况的原因。所有图片框(1和2)在面板中