Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.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# 滚动时刷新flowlayoutpanel中的子控件_C#_.net_Winforms_Custom Controls - Fatal编程技术网

C# 滚动时刷新flowlayoutpanel中的子控件

C# 滚动时刷新flowlayoutpanel中的子控件,c#,.net,winforms,custom-controls,C#,.net,Winforms,Custom Controls,在.NET3.5中,我使用winforms制作了一个图像缩略图查看器控件 主控件派生自FlowLayoutPanel,该面板获取图像列表并显示它们。显示的图像由CustomControl制成,我在其上绘制控件和附带的标签以及控件的边框。 可以通过单击和yada-yada来选择图像,正如您所期望的那样 下面是一张截图来说明: 那部分很好用。问题是,当我滚动FlowLayoutPanel派生控件时,边框没有正确重画,并且仍有行,如此屏幕截图所示: 我已将FlowLayoutPanel和图像设置为

在.NET3.5中,我使用winforms制作了一个图像缩略图查看器控件

主控件派生自
FlowLayoutPanel
,该面板获取图像列表并显示它们。显示的图像由
CustomControl
制成,我在其上绘制控件和附带的标签以及控件的边框。 可以通过单击和yada-yada来选择图像,正如您所期望的那样

下面是一张截图来说明:

那部分很好用。问题是,当我滚动
FlowLayoutPanel
派生控件时,边框没有正确重画,并且仍有行,如此屏幕截图所示:

我已将
FlowLayoutPanel
和图像设置为双缓冲。图像和标签没有问题,所以我怀疑这是另外一回事,但我不知道它是什么

我认为用于绘制图像边界的方法可能有问题。以下是我使用的代码:

    protected override void OnPaint(PaintEventArgs e)
    {
        Rectangle captionContainer;

        captionContainer = new Rectangle();
        if (!string.IsNullOrEmpty(this.Caption))
            captionContainer = this.DrawCaption(e.Graphics);

        if (this.Image != null)
            this.DrawImage(e.Graphics, captionContainer);

        this.Size = new Size(this.Padding.Horizontal + this.ImageSize.Width, this.Padding.Vertical + this.ImageSize.Height + captionContainer.Height);

        ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, this.currentBorderColor, ButtonBorderStyle.Solid);

        base.OnPaint(e);
    }
如果需要的话,我会发布更多的代码,但是它相当长,所以我不想放太多的代码,除非它确实是必要的


有人能看到哪里出了问题吗?

我还通过使用
图形
对象绘制边框解决了这个问题。替换

ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, this.currentBorderColor, ButtonBorderStyle.Solid);


这就是诀窍。不知道为什么一个有效而另一个无效…

解决了这个问题。虽然我想知道上面的方法到底出了什么问题。
e.Graphics.DrawRectangle(new Pen(this.currentBorderColor, 1F), new Rectangle(Point.Empty, new Size(this.Width - 1, this.Height - 1)));