.net 2005 convert from VB to c++

G

Galil

I have a subroutine I need to convert from vb.net 2005 to visual C++
( .net 2005)
The function only allows specific characters to be typed into a
textbox. the backspace and 0 -9.

Private Sub textbox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Select Case Asc(e.KeyChar) <-- Is this function available in C
+
+?
Case 8, 48 To 57
e.Handled = False
Case Else
e.Handled = True
End Select
End Sub

Could someone convert this into C++?
or is there a way to call this subroutine in C++?
I am very new to programming so please be specific. (#include
statements, etc.)
Thank you
 
M

Mattias Sjögren

The function only allows specific characters to be typed into a
textbox. the backspace and 0 -9.

Private Sub textbox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Select Case Asc(e.KeyChar) <-- Is this function available in C
+
+?
Case 8, 48 To 57
e.Handled = False
Case Else
e.Handled = True
End Select
End Sub

This code doesn't handle strings that gets pasted into the textbox.

Could someone convert this into C++?

Are you using Windows Forms? MFC? plain Windows APIs?


Mattias
 
G

Guest

Here is a conversion to C++/CLI (with Instant C++):

private:
//TODO: INSTANT C++ TODO TASK: Insert the following converted event handlers
at the end of the 'InitializeComponent' method for forms or into a
constructor for other classes:
TextBox1->KeyPress += gcnew
System::Windows::Forms::KeyPressEventHandler(this, &textbox1_KeyPress);

void textbox1_KeyPress(System::Object ^sender,
System::Windows::Forms::KeyPressEventArgs ^e)
{
if ((System::Convert::ToInt32(e->KeyChar) == 8) ||
(System::Convert::ToInt32(e->KeyChar) >= 48 &&
System::Convert::ToInt32(e->KeyChar) <= 57))
{
e->Handled = false;
}
else
{
e->Handled = true;
}
}

--
David Anton
http://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top