Hello everyone! I'm working on my very first program ever, it's a calculator for (flightsim) pilots that calculates how fast you need to descend in order to reach your target at the altitude you want.
Here's what it looks like right now..
It works very well, but there are a few functions I want to add before I release it. I have managed to make it accept only numerous input and backspace, and if you write alphabetic letters, "Only numbers allowed" pops up.
BUT when I leave one or more text-boxes empty and press calculate, it crashes. What I need is a popup that says I have to write something in the input fields. How should I do that?
I also want to add some tooltips that pops up when I move the mouse cursor over the text fields. But again - how?
Would be very nice if some of you could help me, but keep in mind that I'm completely new to this and it's my first day of programming something. So please try to explain in an "easy" way...
Sounds like an annoying design to me. How about this?
1. Instead of showing a popup when the user enters invalid data (which is extremely annoying...), don't allow it to begin with. Use a masked textbox or handle the KeyPress event yourself and filter out invalid data.
2. Simply disable the "Calculate" button until all data is valid. You can do this easily by updating the Enabled property from within an Application.Idle event handler (WinForms) or by binding the IsEnabled property of the button to a set of properties using a custom converter (WPF)
when I leave one or more text-boxes empty and press calculate, it crashes. What I need is a popup that says I have to write something in the input fields. How should I do that?
Assuming you are using Visual Studio, try to use the debugger to find out what went wrong or attach the project to a message so we can take a look at the code. You will probably need to test for a non empty text box value using its Text (!= String.Empty) or Text.Length ( > 0) property before trying to test if it contains chars.
I like using the numeric up/down control, as it forces numeric entry for you, you can set a larger increment so values will 'spin-up' faster for the user, and will let you assing a min and max value... one thing that annoys me about it however is that is doesnt take a default value if a user leaves it blank... but it gives a good starting point for numeric input in my opinion.
If you are going to allow invalid data (which you shouldn't) then you should be using int.TryParse instead of int.Parse. Currently you only check for an empty string and this is why you are crashing (one reason anyway).
Ok, I tried to do what BigEd suggested; to disable the caclulate button until the fields had a valid value. I can't say I understood much of what you wrote, BigEd (sorry, but I'm VERY new to this...) but I found this, which looked like a perfect coding for what I was trying to do: http://stackoverflow.com/questions/4...box-is-valid-c
So I tried to use that and wrote this in my project file:
Here's a picture (I have added some new functions): (EDIT: I know, should be "pounds")
textBox6 = the top text box
button3 = the first calculate button
No errors, but when I start the program the button is still enabled. BUT if I write something and clear it again, either using backspace or the "clear fields" button, it gets disabled. And when I write somtehing again it enables like it should. What can I do to fix this, so the button is disabled from the program startup?
Last edited by Even92LN; June 27th, 2011 at 04:42 PM.
You can disable the button 2 ways that I can think of. First one method is when you click the button in its properties there will be one called (Enabled) set it to false and it will start the application with the button disabled.
The second method is clicking the form twice which will give you a form_load and inside this method you add button3.Enabled = false; This will run when the application loads and will disable your button at the beginning.
Have worked a little more on the application, and I must say I'm quite surprised by what I have achieved so far But I wonder how I can get the time format in "HH:MM" instead of "decimal-hours" in the "Scheduled flight time" textbox: