All that is written in the function:

private: System::Void textBox1_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) { char number = e.KeyChar; } 

It produces errors:

  1. e expression must have class type

  2. C2228 expression to the left of .KeyChar should represent a class, structure, or union.

What is the mistake?

Replacing e.KeyChar with e->KeyChar helped, only now a new problem with

 private: System::Void textBox1_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) { char number = e->KeyChar; if (!Char.IsDigit(number)) { e->Handled = true; } } 

Complains if (!Char.IsDigit(number))

  • You should not change your original question recursively adding new questions to it. This is misleading to write your answers and read the question and answers. It is better to ask a new question if a new problem has arisen., - Vlad from Moscow

1 answer 1

I think that means

 char number = e->KeyChar; ^^^^ 

For the second error message, try writing

 if (!Char::IsDigit(number)) ^^^ 
  • Thanks, it helped. It will be necessary to study these operators in more detail: D - Vitali
  • @Vitaly If it helped, then close the question by selecting the answer that helped you, so that the question was not suspended. - Vlad from Moscow