|
Hi..
I want to learn network programming using C#.
So, from where to start i.e. Sockets, TCP, etc
|
|
|
|
|
Search for sockets in CodeProject articles , there are a lot
|
|
|
|
|
Hello all,
I'd like to open a console window that is usable with System.Console.ReadLine/WriteLine from a WinForm.
I'm trying to do it by clicking a button, but I'm having difficulty figuring it out.
How do I create / initialize the window?
Also, are there any issues with passing info back and forth between the console window and the form?
Currently, I can get a string to output to the Output window when I click the button, but I want a console. I can also use the process control to call a cmd.exe window, but can't get the IO there...
Thanks in advance.
|
|
|
|
|
You might be able to create a cmd.exe process and then use the RedirectStandardInput and RedirectStandardOutput to the streams of the Console class (something like GetStandardInputStream and GetStandardOutputStream from the Console class). You should be able to then write using Console.WriteLine etc and read using Console.ReadLine etc to read and write from cmd.exe.
Note I havn't had the time to look it up properly, but then again that's your job , still might be useful to me when I get the time.
You know you're a Land Rover owner when the best route from point A to point B is through the mud.
Ed
|
|
|
|
|
How to check validation numeric field in C# coz C# doesn't has built-in IsNumeric function
Angela
|
|
|
|
|
Three ways
1 - use a MaskedEditBox
2 - write your own handler so the edit box only takes numbers
3 - use Char.IsNumber to check all the characters in the string.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
ok, thanks
|
|
|
|
|
Use this
public bool IsNumeric(string s)<br />
{<br />
try<br />
{<br />
Int32.Parse(s);<br />
}<br />
catch<br />
{<br />
return false;<br />
}<br />
return true;<br />
}<br />
Nikhil
|
|
|
|
|
Thanks for your source code
just now i also found another way to validate the numeric field, I would like to share it with you :
public bool chkNumeric(string strText)
{
char[] chars = strText.ToCharArray();
for (int i = 0; i < chars.Length; i++)
{
if (chars[i] > 57 || chars[i] < 48)
{
return false;
}
}
return true;
}
angela
|
|
|
|
|
this code wil not handle -ve numbers and number exceeding int max limit
Regards
Shajeel
|
|
|
|
|
|
Be careful. The exception police will get you. As has been explained to me, relying on exceptions is bad practice. Use TryParse instead of Parse and it returns a boolean to let you know if it worked or not.
|
|
|
|
|
Well you could just do like this:
try
{
Convert.ToInt32(txtstring);
}
catch
{
MessageBox.Show("You must input a numeric value!");
return;
}
-- modified at 2:53 Thursday 8th June, 2006
|
|
|
|
|
And whats about this...
if(!char.IsNumber(e.KeyChar)
e.Handled=true;
write it in the text control's KeyPress event.
_____________________________
Success is not something to wait for, its something to work for.
|
|
|
|
|
A couple of notes about the other replies:
1. You don't want to be catching exceptions as part of the normal logic flow. This is a well-accepted standard in software development.
2. You don't want to do this in a KeyPress event since that won't handle pasting code from another source.
For a more robust equivalent to VB's IsNumeric method see: http://www.tangiblesoftwaresolutions.com/Articles/CSharp%20Equivalent%20to%20IsNumeric.htm[^]
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter
Instant C++: VB to C++ converter
Clear VB: Cleans up VB.NET code
|
|
|
|
|
David Anton wrote: 2. You don't want to do this in a KeyPress event since that won't handle pasting code from another source.
Hi David Anton
I didn't understand this point!
_____________________________
Success is not something to wait for, its something to work for.
|
|
|
|
|
Standard Windows copy/paste doesn't trigger KeyPress events.
User the TextChanged event to capture pasting of text also.
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter
Instant C++: VB to C++ converter
Clear VB: Cleans up VB.NET code
|
|
|
|
|
David Anton wrote: Standard Windows copy/paste doesn't trigger KeyPress events.
User the TextChanged event to capture pasting of text also.
of course! I checked it last day and found the same situation. It means that we can't rely on only keyPress event for validation, we have to check some other events too; like, as you mentioned, TextChanged etc.
Thanks.
_____________________________
Success is not something to wait for, its something to work for.
|
|
|
|
|
this code may help you to check whether the given value is numeric or not
using System.Text.RegularExpressions;
public static bool CheckNumeric(string strText)
{
return CheckRegExPattern(@"^[0-9]+$", strText.Trim());
}
-- modified at 7:05 Friday 9th June, 2006
|
|
|
|
|
Suamal wrote: CheckRegExPattern
What is this? I didn't find it.
Suamal wrote: using System.Text.RegularExpressions;
public static bool CheckNumeric(string strText)
{
return CheckRegExPattern(@"^[0-9]+$", strText.Trim());
}
While taking idea from this I tryed to implement it like this:
using System.Text.RegularExpressions;<br />
public bool CheckNumeric(string strtext)<br />
{<br />
System.Text.RegularExpressions.Regex rr = new Regex(@"^[0-9]+$");<br />
return rr.IsMatch(strtext); <br />
}<br />
<br />
MessageBox.Show(this.CheckNumeric(TextBox1.Text).ToString());
Its working, but i'm unable to interpret this @"^[0-9]+$"
Thanks and Best Regards
_____________________________
Success is not something to wait for, its something to work for.
|
|
|
|
|
At last found the site
.NET Framework Regular Expressions [^]
Thanks God
and Thanks to the forum
_____________________________
Success is not something to wait for, its something to work for.
|
|
|
|
|
Hi,
I need to write a windows service that will take a backup of the database tables and their data to a file when the server goes down and at the end of day everyday. Can anybody tell me how do I go about it? For the back-up do I need to use SQL-DMO or is there some other way out?
Thanks in advance,
Aakar.
|
|
|
|
|
For my money, SQL-DMO is the way to go. It allows you to stay within the confines of the application and is just a cleaner implementation (IMHO!)
I attempted to invoke sqlo from within C# and it did work, but catching any exceptions was a bit awkward.
/dave
----
If you always do what you always done, you'll always get what you've always got - Anonymous
|
|
|
|
|
My application saves the Size and Location properties of the main form in a configuration file. When the program runs I first create the form, set the Size and Location properties, then call the form's Show method.
I noticed after closing and restarting the application the form would grow slightly larger, which puzzled me. If I output the value of the Size property immeadiately before and after I call the form's Show method I can see that the form grows in height by exactly 19 pixels. No matter what I set as the value of the Size property, the height always seemed to increase by 19 pixels.
I had a hunch maybe 19 pixels was the height of the title bar. I increased the size of the title bar font in Windows, but my form still grew by 19. However, when I increased the size of the menu font my form grew by a larger amount.
Other than the menu I have two controls in the form. A ListView control with the Dock property set to Fill and a StatusBar control with the Dock property set to Bottom.
Any ideas?
Thanks,
Chris
|
|
|
|
|
Maybe you can try saving and setting the form's ClientSize instead.
I haven't done any testing but AFAIK the ClientSize does not include title bar height and width etc.
Edbert
Sydney, Australia
|
|
|
|