修改UltraDateTimeEditor背景

时间:2015-10-29 18:17:10

标签: vb.net winforms controls infragistics

例如,当时间不是今天时,我需要将Infragistics.Win.UltraWinEditors.UltraDateTimeEditor的背景颜色设置为黄色。此外,当我将光标移到编辑器上时,我需要显示一条警告消息。我知道XAML有我可以使用的这种属性。在winform中怎么样?

1 个答案:

答案 0 :(得分:1)

一个关于如何实现目标的简单示例。我很确定还有其他方法可以完成这项工作,但这可行

' 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