Click to See Complete Forum and Search --> : how to close a form


swamivishal1
February 13th, 2005, 11:21 AM
hello gurus,

:wave: i am a newbie in c#.Net :D i am trying to close a form but by using application exit , the complete application closes while i wish to close the form only,i mean if i have two or more forms in the application then only one form wil be closed.
:confused:
:cry: my another problem is that how do i can check whether the text entered in the text box is in uppercase or in lower case.

i know that i'll get my answers as soon as possible.
so mnay thanx for all the gurus in advance. :wave:

thanx

vishal

BigEvil
February 13th, 2005, 12:20 PM
To close a form, use this.Close() in the close button's OnClick function

void btnClose(object sender, System.EventArgs e)
{
this.Close();
}

You can use regex to check if there are any uppercase and/or lowecase characters in the string.
Match m = Regex.Match(str, @"^[A-Z]+$");
if(m.Success)
...
The above will check if the entire string is in uppercase. For "[A-Z]+" , m.Success will be true if there is atleast one uppercase character in the string. Use whichever suits your needs.

To combine the two statements, you can use

if(Regex.Match(str, @"^[A-Z]+$").Success)
...;

The ^ and $ mean the beginning and end of the string respectively. + means one or more of the previous characters, * would mean 0 or more occurrences of the previous characters, just in case you don't know regular expressions. There might be a simpler way, but this is the only way I know, I too am a newbie in C# ;)

Regex is defined in System.Text.RegularExpressions, so don't forget to include this namespace.

swamivishal1
February 14th, 2005, 10:46 AM
thanx dear,

i'll try both of them

thanx again :wave: