如何将 System.Drawing.Icon 绘制到 SplitterPanel 上?

发布于 2024-10-05 23:12:16 字数 542 浏览 6 评论 0原文

我有这样的东西:

var systemIcon = SystemIcons.Information;
verticalSplitPanel.SplitterDistance = systemIcon.Width;

var g = verticalSplitPanel.Panel1.CreateGraphics();
g.DrawIcon(systemIcon, 0, 0);

它编译并运行没有错误,但由于某种原因图标不可见。

我也尝试过这个:

var systemIcon = SystemIcons.Information;
verticalSplitPanel.SplitterDistance = systemIcon.Width;

var g = verticalSplitPanel.Panel1.CreateGraphics();
g.DrawImage(systemIcon.ToBitmap(), 0, 0);

它再次编译并运行,没有错误,但不显示图标。

我怎样才能显示这个图标?

I've got something like this:

var systemIcon = SystemIcons.Information;
verticalSplitPanel.SplitterDistance = systemIcon.Width;

var g = verticalSplitPanel.Panel1.CreateGraphics();
g.DrawIcon(systemIcon, 0, 0);

This compiles and runs without error, but for some reason the icon isn't visible.

I also tried this:

var systemIcon = SystemIcons.Information;
verticalSplitPanel.SplitterDistance = systemIcon.Width;

var g = verticalSplitPanel.Panel1.CreateGraphics();
g.DrawImage(systemIcon.ToBitmap(), 0, 0);

Again it compiles and runs without error, but doesn't show the icon.

How can I display this icon?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心如狂蝶 2024-10-12 23:12:16

您的代码可以在面板的表面上绘制图标,但只要面板决定重新绘制自身,该图标就会被清除。您不应使用 verticalSplitPanel.Panel1.CreateGraphics() 调用中的 Graphics 对象,而是应处理面板的 Paint 事件并使用 Graphics > 该事件参数中提供的对象。

试试这个:

verticalSplitPanel.Panel1.Paint += (s, eargs) =>
    {
        var icon = SystemIcons.Information;
        eargs.Graphics.DrawIcon(icon, 0, 0);
    };

Your code can paint icon over panel's surface, but it will be cleared whenever panel decides to repaint itself. Instead of using Graphics object from verticalSplitPanel.Panel1.CreateGraphics() call you should handle panel's Paint event and use Graphics object provided in that event args.

Try this:

verticalSplitPanel.Panel1.Paint += (s, eargs) =>
    {
        var icon = SystemIcons.Information;
        eargs.Graphics.DrawIcon(icon, 0, 0);
    };
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文