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.
Try this:
verticalSplitPanel.Panel1.Paint += (s, eargs) =>
{
var icon = SystemIcons.Information;
eargs.Graphics.DrawIcon(icon, 0, 0);
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.