如何从 Icon 创建 Image 对象以与 ToolStripStatusLabel 项一起使用
我需要能够在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Icon 有 ToBitmap 方法,它会给你一个 Bitmap,它是一个 Image
Icon has the ToBitmap method, which will give you a Bitmap, which is an Image
您可以直接在设计器中设置图像。
如果必须使用代码,为什么不将图像添加到项目资源中,然后为其分配图像属性呢?
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?