|
Instead of using Console.ReadLine you are going to have to use Console.ReadKey. Something along the lines of this:-
string str = string.Empty;
while (str.Length <= 5)
{
char c = Console.ReadKey(true).KeyChar;
if (c == '\r')
{
break;
}
if (c == '\b')
{
if (str != string.Empty)
{
str = str.Substring(0, str.Length - 1);
Console.Write("\b \b");
}
}
int enteredValue;
if(Int32.TryParse(c.ToString(), out enteredValue))
{
Console.Write(c);
str += c;
}
}
Console.WriteLine();
Console.WriteLine("You entered " + str);
Console.ReadLine();
This checks if the char entered is numeric, it handles backspaces and it checks to see if the user pressed enter. I am sure you could alter this to work with your app.
Hope it helps
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Thank you so much. This helps a great deal.
|
|
|
|
|
Glad to help
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
An alternative way to avoid the overload is just to check that the parsing actually succeeded:
bool MultiplyFromConsole(){
int number1, number2;
string line1, line2;
Console.Write("Please enter a number: ");
line1 = Console.ReadLine();
Console.Write("Please enter a number: ");
line2 = Console.ReadLine();
if(!(int.TryParse(line1, out number1) && int.TryParse(line2, out number2))
return false;
Console.WriteLine("Multiplication: " + (number1 * number2));
return true;
}
|
|
|
|
|
Thank you. My mentor wants me to allow the user another chance if he/she enters a number that is too large or enters letters instead of number. This is quite a learning experience.
Thank you for your help.
Deborah
|
|
|
|
|
hi
how to paint lines on combo-box in difference colors ?
for example:
line1 - red
line2 - green
line3 - yellow
i need any c# code
thanks
|
|
|
|
|
Throw us a bone here. What technology?
|
|
|
|
|
on WinForm , FrameWork 3.5 , C#
thanks
|
|
|
|
|
ComboBox and ListBox offer the same technique for OwnerDrawn painting; you can find an example here[^].
|
|
|
|
|
- Set Combo's draw mode (property is called DrawMode or something similar) to OwnerDrawFixed.
- Write OnPaint handler that paints the current item's background, if you want that
... and uses a brush of the appropriate colour to paint the text. Use the Font property of the combo.
|
|
|
|
|
i want to learn .net i have no idea please help me out
|
|
|
|
|
Decide which language you want to use.
Download the free tool from Microsoft Visual Studio express
Locate a good book and start working through it.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I agree with Mycroft - a book or a training course are the best ways - if you just dive in and learn as you go you will miss far too much important stuff, or not understand the stuff you do learn.
Wrox do good books, as do Apress - just avoid anything with multiple exclamation marks or "in nnn days" in the title.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
VB6 for smarties in 11 months!!!!!
|
|
|
|
|
|
Hi!
For an application I have to learn, maintain and upgrade there is a code for installing Windows services. The code works on Windows XP, but it don't work on Windows 7 which I use.
The Windows service (Service.exe), needs two arguments for the main method. The two arguments are a string and a file path (File.txt).
This is the code for installing the service on XP:
string installutilFolder;
string filePath;
string serviceFolder;
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = installutilFolder + @"\installutil";
process.StartInfo.Arguments = @"/i /key=""" + filePath + "\" \"" + serviceFolder + "\\Service.exe \"" ;
process.Start();
Pretty simple only the assignment is a bit weird. Notice the installutil will have two arguments:
* The string containing the file path which is the argument for the service
* The service to install
I'm happy that this actually works on Windows XP. But when I run this code on Windows 7, the services seems not to be installed, because I cannot find it where all other installed services are in Windows.
Any solution for how to install the service for Window 7? A solution which is same for Window XP and Windows 7 would be best.
|
|
|
|
|
if installutil is any good, it will produce some output, maybe a log file, maybe some system events, telling you about success/failure with some detail. As it isn't a standard piece of software, nobody is going to be able to tell but you.
|
|
|
|
|
InstallUtil is standard Microsoft software to install Windows Services. http://msdn.microsoft.com/en-us/library/50614e95%28v=vs.80%29.aspx[^]
The log file gave this result:
Running a transacted installation.
Beginning the Install phase of the installation.
See the contents of the log file for the <Path to folder for Service.exe> \Service.exe assembly's progress.
The file is located at <Path to folder for Service.exe >\QuickLoop.InstallLog.
An exception occurred during the Install phase.
System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.
The Rollback phase of the installation is beginning.
See the contents of the log file for the <Path to folder for Service.exe> \Service.exe assembly's progress.
The file is located at <Path to folder for Service.exe >\QuickLoop.InstallLog.
The Rollback phase completed successfully.
The transacted install has completed.
According to the MSDN link above this problem seems to be common and the installation has to be made as administrator. I confirmed this with an other service I created and installed with terminal as administrator.
modified 16-Jan-12 11:29am.
|
|
|
|
|
I wouldn't expect to be able to install a service except as an admin.
|
|
|
|
|
Is there some reason that you would expect a normal user to be able to install a service??
Since services usually run under a custom account or as the local system, I wouldn't expect anyone other than an admin-level user to be able to install a service, or any other software for that matter.
|
|
|
|
|
Thanks for the input and I can understand your point.
The application which handle the service installations don't need any admin account. Through this application the user can easily install, run, stop and uninstall the services. No other services are possible to reach from the application. Therefore it was first designed to not run as admin since the user couldn't cause any harm to other services except their own.
But now Windows 7 forces admin so I have to implement it that way.
|
|
|
|
|
Yeah, there's a lot of stuff you could get away with on XP that you can't on Vista/7. People are finding out that just because you COULD do something on XP, it doesn't mean that is was a good idea to do so.
|
|
|
|
|
Can anyone recommend a free/commercial MSIL obfuscator that will also fix up a .pdb so that I can capture a meaningful stack trace in the event of an unexpected exception in my obfuscated assembly?
No, I'm not trying to prevent someone from cracking a licensing scheme (my app is 100% free). I'd like to protect a financial modelling algorithm.
Thanks,
/ravi
|
|
|
|
|
How does Microsoft calculate the left alignment of text on a button?
Test button settings:
- All Margins set to 0.
- All Padding set to 0.
- TextAlign = MiddleLeft.
- Button style is Flat.
- Setting flat border width to 0 or 1 has no effect on position of text.
For pattern illustration:
- U = Unknown Pixel (we are not drawing these)
- T = Text pixel
My drawing:
1. Draw text at x = 0.
2. Draws text 5 pixels from left edge - I can live with that.
Pattern: UUUUT
Not important: Why is DrawString(...) drawing the text at x=4 instead of x=0?
Microsoft drawing:
1. Draws text 11 pixels from left edge.
Pattern: UUUUUUUUUUT
Important: Where are the extra 6 pixels coming from?
I have tried to account for the extra padding by examining the systems information settings. Unfortunately none of those settings explain where the padding is coming from (BorderSize=1, Border3DSize=2).
Thanks for any explanation,
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence." - Edsger Dijkstra
"I have never been lost, but I will admit to being confused for several weeks. " - Daniel Boone
|
|
|
|
|
One logical, if unlikely, hypothesis might be that the position of the first character is calculated based on the underlying bounding box of the character which may include a built-in left-margin factor.
To exclude this hypothesis, which I'd guess you may have already done, I'd vary the first character from lower to upper case, and compare a "naturally wide" "W" with a "naturally narrow "I." If they are both drawn at identical distances from the left edge of the Button at the Alignment settings you describe: that's one less hypothesis
A more probable hypothesis (?): the fact you are using the Paint Event and DrawString means you are relying on an internal drawing area that is offset from the absolute pixel edges of the Button: since I never use Paint and DrawString, I don't know how you could test this hypothesis, but I am sure someone else reading this post will.
best, Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle
modified 16-Jan-12 5:43am.
|
|
|
|