例如,当时间不在今天时,我需要将Infrasgistics.Win.UltraWinEditors.UltraDateTimeEditor的背景色设置为黄色。此外,当我将光标移动到编辑器上时,我需要显示一条警告消息。我知道XAML有这样的属性我可以使用。冬天怎么样?
关于如何实现目标的快速示例。我很确定还有其他方法可以做到这一点,但这对有效
' Globals controls and Forms
Dim f As Form
Dim dt As Infragistics.Win.UltraWinEditors.UltraDateTimeEditor
Dim tt As Infragistics.Win.ToolTip
' This Main has been built using LinqPAD, you could have problems
' running it, as is in a WinForms project, but the concepts are the same
Sub Main()
dt = New UltraDateTimeEditor()
dt.Dock = DockStyle.Top
' Add the event handlers of interest to the UltraDateTimeEditor
AddHandler dt.Validating, AddressOf onValidating
AddHandler dt.Enter, AddressOf onEnter
tt = New Infragistics.Win.ToolTip(dt)
' Just another control to trigger the OnEnter and Validating events
Dim b = New Button()
b.Dock = DockStyle.Bottom
f = New Form()
f.Size = New Size(500, 500)
f.Controls.Add(dt)
f.Controls.Add(b)
f.Show()
End Sub
Sub onValidating(sender As Object , e As EventArgs)
' Some condtions to check and then set the backcolor as you wish
dt.BackColor = Color.Yellow
End Sub
Sub onEnter(sender As Object, e As EventArgs)
' Set the background back
dt.BackColor = Color.White
' Some condition to check to display the tooltip
If dt.DateTime <> DateTime.Today Then
tt.ToolTipText = "Invalid date"
' Time to leave the message visible
tt.AutoPopDelay = 2000
tt.DisplayStyle = ToolTipDisplayStyle.BalloonTip
' Calculation to set the tooltip in the middle of the editor
Dim p = New Point(dt.Left + 50, dt.Top + (dt.Height 2))
p = dt.PointToScreen(p)
' Show the message....
tt.Show(p)
End If
End Sub