vb.net - 检查表单的图标是否为空或设置为默认图标?
问题描述
知道如何检查表单的图标值是否为空值或设置为默认值吗?我尝试过这样的事情,但没有运气......
If Me.Icon Is Nothing Then
MsgBox("Nothing")
End If
我注意到表单的图标属性已经有一个值。默认一个。那么,如何检查我的表单是否使用此默认值?
先感谢您!!!
解决方案
似乎没有办法确定当前Icon
是否为DefaultIcon
. 但是有一个静态/共享属性DefaultIcon
,您可以通过反射访问它:
Imports System.Reflection
Imports System.Runtime.CompilerServices
Module FormsExtensions
<Extension()>
Public Function HasDefaultIcon(form As System.Windows.Forms.Form) As Boolean
' relies on reflection, so might break in future
' necessary because the DefaultIcon property is internal
Dim fType = GetType(Windows.Forms.Form)
Dim defaultIconProp = fType.GetProperty("DefaultIcon", BindingFlags.NonPublic Or BindingFlags.Static)
Dim defaultIcon = TryCast(defaultIconProp?.GetValue(form), System.Drawing.Icon)
Return form.Icon Is defaultIcon
End Function
End Module
使用这种扩展方法,检查很容易:
Dim hasDefaultIcon As Boolean = Me.HasDefaultIcon()
推荐阅读
- android - 对话框 Theme.DeviceDefault 强制
- python - IF 语句格式化 Python
- javascript - Vue.js - 在没有道具的情况下将数据从父级传递给子级
- c# - Get tables names of a specific database selected by user from combobox
- javascript - How is this portion of code able to modify the mouse pointer seemingly outside of the browser window?
- asp.net-mvc - 我的数据库中的 EntityState.Modify 而不是 Delete
- c# - 使用 ASP.Net 发送 SMTP 邮件
- d3.js - Setting the color of the nodes in d3
- html - Html:文本不在表格下,但应该在
- ios - Firebase 云消息传递中 iOS 的 ttl“生存时间”是否有替代方案?