-1

I have a masked textbox set to date.short I would like to automate the cuurentdate to be filled in when the masked textbox is clicked I though the following would work but I get the error InvalidCastExpectation was ungandeld "Application is in break mode"

Private Sub MaskedTextBox1_Click(sender As Object, e As MaskInputRejectedEventArgs) Handles MaskedTextBox1.Click
    MaskedTextBox1.Text = DateTime.Now.ToString("dd/MM/yyyy")
End Sub

I also thought about changing ("dd/MM/yyyy") to ("dd-MM-yyyy") but this also dosnt fix it?

LabRat
  • 1,996
  • 11
  • 56
  • 91

1 Answers1

1

The Click event does not use the MaskInputRejectedEventArgs parameter:

Private Sub MaskedTextBox1_Click(sender As Object, e As EventArgs) 
                                 Handles MaskedTextBox1.Click
LarsTech
  • 80,625
  • 14
  • 153
  • 225
  • 1
    Good catch. I place my money on he double clicked the control to create the `MaskInputRejectedEventArgs` handler, but changed the handler for `click`. This would indeed cause his exact error `Unable to cast object of type 'System.Windows.Forms.MouseEventArgs' to type 'System.Windows.Forms.MaskInputRejectedEventArgs'.` Im not sure why he just didn't selected it in the event drop down for `MouseClick` in the first place... – Trevor Jun 15 '16 at 13:59