Numeric Only TextBoxes

crewchiefpro

New member
Joined
Dec 21, 2016
Messages
4
Location
Illinois and San Diego
Programming Experience
10+
I have researched this but it still isn't clear to me.

In VFP we had numeric only textbox classes. Nothing but numbers and decimals could be entered and these classes were different than Alpha Numeric textbox classes. All I needed to do is drop one of these on a form and it knew what to do. Can I do the same thing in Windows Forms for both the PC and Internet forms?

Also, in VFP if I had a Tab Control ( We called them PageFrames ) and wanted to reference a textbox on the Second page we would type:
thisform.pageframe1.pgTAB1.txtQuarterValue.value = 45.045

I noticed this is different in C#. I was able to reference a textbox on this Tab Control simply by saying the textbox name. Is that normal or am I missing something?

Can I have Tab Controls on Web Forms?
 
First things first, you have a multitude of unrelated questions there. Please keep each thread to a single topic and each topic to a single thread. The thread title says "Numeric Only TextBoxes" so anythiung not directly related to that doesn't belong here. Any other questions belong in their own thread(s) with titles that describe that topic.

Also, this is the Windows Forms forum so questions about Web Forms or any other technology other than Windows Forms don't belong here. I can't think of a question that would ever relate to both Windows Forms and Web Forms. If a question appears to relate to both then it almost certainly relates to neither, e.g. string manipulation doesn't relate to either but can be used in applications of both types.
In VFP we had numeric only textbox classes. Nothing but numbers and decimals could be entered and these classes were different than Alpha Numeric textbox classes. All I needed to do is drop one of these on a form and it knew what to do. Can I do the same thing in Windows Forms for both the PC and Internet forms?
As I said, Windows applications and web applications are very different. In a web application, the text field is part of an HTML page and so you treat it that way. If you want to limit the characters that can be typed into a field then that would be done with javascript code, not C#.

As for Windows Forms, the simple option is to handle the KeyPress event of the TextBox. You can exclude invalid characters in the event handler. The main issue there is that it doesn't stop someone pasting invalid text into the control. If that's an issue then you would need a more rigorous implementation that probably should be done as a custom control. Of course, you could always just use a NumericUpDown control.
Also, in VFP if I had a Tab Control ( We called them PageFrames ) and wanted to reference a textbox on the Second page we would type:
thisform.pageframe1.pgTAB1.txtQuarterValue.value = 45.045

I noticed this is different in C#. I was able to reference a textbox on this Tab Control simply by saying the textbox name. Is that normal or am I missing something?
That's normal. When you design a form, you are creating a new class; one that inherits the Form class. For each control you add in the designer, a member variable is added to that class. You access each control via that member variable. You can also access them via the Controls collection of their direct parent but there's no point doing that if you don't have to.
Can I have Tab Controls on Web Forms?
Again, Windows controls and web controls are very different. If you want to see what controls are available to you in Web Forms then open the Toolbox in a Web Forms project and take a look. If there's nothing like a TabControl there then you could look at using a jQuery plugin instead.
 
numeric only textbox classes
NumericUpDown is such a textbox control for Windows Forms. In ASP.Net you can set Input type=number (also for asp:TextBox).
 
Greetings crewchiefpro,

You can use something like this in the keypress event for C#. Number (1) permits only numbers and delete in the textbox and number 2. permits numbers, backspace and delete.

1.
privatevoid textBox4_KeyPress(object sender, KeyPressEventArgs e)
{
// Numbers Only. You can only use the delete to remove the numbers.
e.Handled = !char.IsDigit(e.KeyChar);
}

2.
privatevoid textBox4_KeyPress(object sender, KeyPressEventArgs e)
{
base.OnKeyPress(e);

// Permits numbers, backspace and delete.
if (e.KeyChar != (char)8 && !char.IsNumber(e.KeyChar))
{
e.Handled =
true;
}
}

 
Back
Top Bottom