开发者

How can a standard error icon be shown in on a C# windows forms dialog?

I'd like to use the standard error icon (Standard Icons) on a Windows Forms dialog. How can the 开发者_Go百科error icon be loaded into an Image for display?


By using Icon.ToBitmap()

Bitmap b = SystemIcons.Error.ToBitmap();

EDIT:

Three years later and one more upvote, I feel compelled to direct people who just want to draw the icon to a graphics object to read the answer by @Hans Passant. It's a better solution.


I have to sputter at the horrid waste of burning up such expensive resources as a Control and a Windows window, just to draw a dinky icon. To save one line of code:

    protected override void OnPaint(PaintEventArgs e) {
        e.Graphics.DrawIcon(SystemIcons.Error, 10, 10);
        base.OnPaint(e);
    }


If you're using Visual Studio's Designer, add a PictureBox object. Then in code, set your PictureBox's Image property:

dialog.PictureBox.Image = SystemIcons.Error.ToBitmap();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜