Come on empty date control

xiaoxiao2021-03-06  52

The date control from .NET cannot be empty, not convenient, according to this control, customize the empty date control, the code is as follows: public class mydatetimepicker inherits system.windows.Forms.DatetimePicker Private Txt As TextBox public enum DEFAUTVALUE EMPTY = 0 Today = 1 END ENUM

Private mdefvalue as defautvalue = defautValue.empty

Property DefValue () AS DefautValue Get Return Me.mdefValue End Get Set (Byval Value As DefautValue) MDEfValue = Value End End Property

Public Sub New (ByVal defval As DefautValue) txt = New TextBox Me.Controls.Add (txt) txt.BorderStyle = BorderStyle.None txt.Anchor = AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right Or AnchorStyles.Top txt.Bounds = New Rectangle (0, 0, Me.Width - 20, Me.Height) txt.show () me.defvalue = defval if defval = defautvalue.empty the txt.text = "" else txt.text = DATE2STRING (Date. Today) Endiff End Sub

Public Sub New () txt = New TextBox Me.Controls.Add (txt) txt.BorderStyle = BorderStyle.None txt.AutoSize = False txt.Anchor = AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right Or AnchorStyles.Top txt. Bounds = New Rectangle (0, 0, Me.Width - 20, Me.Height) txt.visible = true txt.bringtofront () txt.text = "" End Sub

Public overrides property text () AS String get return txt.text end set (byval val as string) if Val <> "" andalso isdate (val) Andalso cdate (val) <= me.maxdate andalso cdate (val)> = Me.Mindate Then Me.Value = cdate (val) txt.text = val else if me.defvalue = defautvalue.empty the txt.text = "" Elseif Me.DefValue = defautvalue.toDay Then Me.Value = Date.Today TXT .Text = Date2String (Date.Today) End If End If End Set End PropertyPrivate Sub myDateTimePicker_ValueChanged (ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.ValueChanged txt.Text = Date2String (Me.Value) End Sub

Private Sub myDateTimePicker_Leave (ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Leave If txt.Text <> "" AndAlso Not IsDate (txt.Text) Then Me.Text = Date2String (txt.Text) End If End Sub

Private sub mydatetimepicker_closeup (Byval e as system.eventargs) Handles mybase.closeup if clickinbox = false kil

Dim Temp as string = me.value me.value = me.value.adddays (1) me.value = Temp 'txt.text = DATE2STRING (Me.Value)

End if clickinbox = false End Sub

Private ClickInBox as Boolean = TRUE

Private sub mydatetimepicker_mousedown (Byval e as system.windows.forms.mouseeventargs) Handles mybase.mousedown clickinbox = true end sublend clas

转载请注明原文地址:https://www.9cbs.com/read-54045.html

New Post(0)