简体   繁体   English

VB.NET表单图标错误

[英]VB.NET Form Icon Error

Everytime I set the form icon, I get the following error : 每次设置表单图标时,都会出现以下错误:

Value of type 'System.Drawing.Icon' cannot be converted to 'String' 类型'System.Drawing.Icon'的值不能转换为'String'

I have tried both external icon file and resources method, but none worked. 我已经尝试了外部图标文件和资源方法,但是没有一个起作用。

Dim X as new System.Drawing.Icon("icon.ico")
Me.Icon = X

and

Me.Icon = My.Resources.Icon

Same thing if I create a new project. 如果创建一个新项目也是一样。

Any help is appreciated, and thanks in advance! 任何帮助表示赞赏,并在此先感谢!

If you are developing a WinForms application, your first attempt should work: 如果您正在开发WinForms应用程序,则第一次尝试应该可以进行:

Me.Icon = New System.Drawing.Icon("path/to/.ico/file")

If you are writing your UI with WPF, then the .Icon property expects an ImageSource object: 如果使用WPF编写UI,则.Icon属性需要一个ImageSource对象:

Dim iconUri As New Uri("pack://application:,,,/WPFIcon2.ico", UriKind.RelativeOrAbsolute)
Me.Icon = BitmapFrame.Create(iconUri)

The second example is directly taken from the MSDN . 第二个示例直接取自MSDN

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM