如何从 Icon 创建 Image 对象以与 ToolStripStatusLabel 项一起使用

发布于 2024-08-23 03:47:53 字数 464 浏览 6 评论 0原文

我需要能够在 C# Windows 窗体应用程序中的 ToolStripStatusLabel 项上设置图标。该项目将显示图像和文本。我以为我可以将图标与这样的项目一起使用,但我错了。从现有 Icon 对象创建 Image 对象的最佳方法是什么?

预期的代码将类似于:(

Image image = new Image(); // Get this image somehow from a pre-existing Icon object
serverInfoToolStripStatusLabel.Text = "Connected to server X";
serverInfoToolStripStatusLabel.Image = image;

注意:serverInfoToolStripStatusLabel 被声明为 System.Windows.Forms.ToolStripStatusLabel) 问候。

I need to be able to set an icon on a ToolStripStatusLabel item in a C# Windows Forms application. The item will being displaying an image and text. I assumed that I could use an Icon with such an item but I am mistaken. What is the best way of creating an Image object from an existing Icon object?

the intended code will look something like:

Image image = new Image(); // Get this image somehow from a pre-existing Icon object
serverInfoToolStripStatusLabel.Text = "Connected to server X";
serverInfoToolStripStatusLabel.Image = image;

(NB: serverInfoToolStripStatusLabel is declared as System.Windows.Forms.ToolStripStatusLabel)
regards.

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

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

发布评论

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

评论(2

一个人的夜不怕黑 2024-08-30 03:47:53

Icon 有 ToBitmap 方法,它会给你一个 Bitmap,它是一个 Image

Icon has the ToBitmap method, which will give you a Bitmap, which is an Image

_畞蕅 2024-08-30 03:47:53

您可以直接在设计器中设置图像。

如果必须使用代码,为什么不将图像添加到项目资源中,然后为其分配图像属性呢?

You can set the image directly in designer.

If you have to use code, why not add the image to your project Resources and then assign the image property to it?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文