FlowLayoutPanel 内的自定义面板的 C# 问题
如果您需要更多详细信息,请告诉我。
我正在为媒体(图像、视频、文件夹)创建缩略图视图,有点像文件的窗口视图。
我使用 FlowLayoutPanel 来保存缩略图。每个缩略图都有一个面板、PictureBox 和标签。
我希望能够更改边框的颜色/格式。我重写了面板的 OnPaint 并在其中添加了一些代码。
现在问题来了。 OnPaint 覆盖不会被调用。一次也没有。所以我的彩色边框根本不显示。如果我将一个拖到可以正常渲染的表单上,则会调用覆盖...所以它一定与 FlowLayoutPanel 有关。
自定义面板:
public class MediaPanel : System.Windows.Forms.Panel
{
public MediaPanel()
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint
| ControlStyles.UserPaint
| ControlStyles.OptimizedDoubleBuffer
| ControlStyles.ResizeRedraw, true);
}
protected override void OnPaint(PaintEventArgs e)
{
ControlPaint.DrawBorder(e.Graphics, this.ClientRectangle,
Color.Red, ButtonBorderStyle.Solid);
}
}
如果我遗漏了任何信息或者我没有足够清楚地解释我的问题,请告诉我。
谢谢。
Please let me know if you need more details.
I'm creating a thumbnail view for media (images, videos, folders) sorta like the windows view for files.
I'm using a FlowLayoutPanel to hold the thumbnails. And a Panel, PictureBox and Label for each thumbnail.
I wanted to be able to change the color/format of the border. I overrided the Panel's OnPaint and added some code in there.
Now here's the problem. The OnPaint override doesn't get called. Not even once. So my colored border doesn't show up at all. If I drag one onto the form it renders fine, the override gets called... So it must be something to do with the FlowLayoutPanel.
The custom panel:
public class MediaPanel : System.Windows.Forms.Panel
{
public MediaPanel()
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint
| ControlStyles.UserPaint
| ControlStyles.OptimizedDoubleBuffer
| ControlStyles.ResizeRedraw, true);
}
protected override void OnPaint(PaintEventArgs e)
{
ControlPaint.DrawBorder(e.Graphics, this.ClientRectangle,
Color.Red, ButtonBorderStyle.Solid);
}
}
Please let me know if I'm missing any information or I'm not explaining my problem clearly enough.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论