如何将 System.Drawing.Icon 绘制到 SplitterPanel 上?
我有这样的东西:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码可以在面板的表面上绘制图标,但只要面板决定重新绘制自身,该图标就会被清除。您不应使用
verticalSplitPanel.Panel1.CreateGraphics()
调用中的Graphics
对象,而是应处理面板的Paint
事件并使用Graphics
> 该事件参数中提供的对象。试试这个:
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 fromverticalSplitPanel.Panel1.CreateGraphics()
call you should handle panel'sPaint
event and useGraphics
object provided in that event args.Try this: