M
M
Mozzarella2017-06-19 11:41:25
OOP
Mozzarella, 2017-06-19 11:41:25

Is it correct to use a function to create a handler?

Is it correct to use a function to create a control handler?

public static void Validate(ValidateType type, Control control)
        {
            switch (type)
            {
                case ValidateType.OnlyNumbers:
                    {
                        control.KeyPress += ValidNumbers;
                        break;
                    }
                case ValidateType.OnlyText:
                    {
                        control.KeyPress += ValidNumbers;
                        break;
                    }
                    
            }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxmyd, 2017-09-20
@Maxmyd

In the validation event, it is already too late to subscribe to KeyPress, the handler will not work. You need to subscribe earlier, and call Validate in the event handler.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question