Search code examples
vb.netwinformscontrolsinfragistics

Modification of the UltraDateTimeEditor background


I need to set the background color of Infragistics.Win.UltraWinEditors.UltraDateTimeEditor to yellow when the time is not today, for example. Also, I need to show a warning message when I move the cursor over the editor. I know XAML has such property I can use. How about in winform?


Solution

  • A quick example on how you could accomplish your goal. I am pretty sure that there are other ways to get this done, but this works

    ' 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