简体   繁体   English

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

[英]How to draw System.Drawing.Icon to a SplitterPanel?

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? 如何显示该图标?

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. 而不是使用verticalSplitPanel.Panel1.CreateGraphics()调用中的Graphics对象,您应该处理面板的Paint事件并使用该事件args中提供的Graphics对象。

Try this: 尝试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM