Parth48
asked on
i can't close the form when textbox validation is there , what can i do now ??
currently i am working on C#.net windows application ...
in my application i can't close the form when textbox validation is there , what can i do now ??
please refer the below code ...
anything wrong on the above code ,
how can i close form when textbox validation is there ??
in my application i can't close the form when textbox validation is there , what can i do now ??
please refer the below code ...
private void Admin_Load(object sender, EventArgs e)
{
//Get Form Properties
Form objform = this.FindForm();
objGeneral.GetFormProperties(objform);
pctBoxLogin2.Visible = false;
lblmsg.Visible = false;
}
private void btnFlashObject_Click(object sender, EventArgs e)
{
//add constructor logic here ...
}
private void txtPasskey_TextChanged(object sender, EventArgs e)
{
//add constructor logic here ...
Form objform = this.FindForm();
pctBoxLogin2.Visible = false;
objform.CausesValidation = true;
}
private void txtPasskey_Validating(object sender, CancelEventArgs e)
{
//add constructor logic here ...
Form objform = this.FindForm();
if (!ValidText(txtPasskey.Text))
{
// Cancel the event and select the text to be corrected by the user.
objform.CausesValidation = false;
e.Cancel = true;
txtPasskey.Select(0, txtPasskey.Text.Length);
pctBoxLogin2.Visible = true;
}
}
public bool ValidText(string stringvalue)
{
if (stringvalue == "pILy^caffs")
{
return true;
}
return false;
}
private void btnEnter_Click(object sender, EventArgs e)
{
//add some logic here
if (txtPasskey.Text == "pILy^caffs")
{
Results objResults = new Results();
objResults.Show();
}
else
{
lblmsg.Visible = true;
lblmsg.Text = "Please Enter Valid Pass Key";
}
}
anything wrong on the above code ,
how can i close form when textbox validation is there ??
First off, this code is pointless:
Form objform = this.FindForm();
You're asking for the Form that contains "this"...which already is the Form!
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.findform(VS.80).aspx
"Retrieves the form that the control is on."
So everywhere you obtain the form using that construct you could simply use "this" directly.
Try this out to allow the form to be closed:
Form objform = this.FindForm();
You're asking for the Form that contains "this"...which already is the Form!
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.findform(VS.80).aspx
"Retrieves the form that the control is on."
So everywhere you obtain the form using that construct you could simply use "this" directly.
Try this out to allow the form to be closed:
public partial class Admin_Load : Form
{
private bool UserClosing = false;
public Admin_Load()
{
InitializeComponent();
}
protected override void WndProc(ref Message m)
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_CLOSE = 0xF060;
if (m.Msg == WM_SYSCOMMAND && (int)m.WParam == SC_CLOSE)
{
UserClosing = true;
}
base.WndProc(ref m);
}
private void txtPasskey_Validating(object sender, CancelEventArgs e)
{
if (!UserClosing && !ValidText(txtPasskey.Text))
{
e.Cancel = true;
txtPasskey.SelectAll();
pctBoxLogin2.Visible = true;
}
}
public bool ValidText(string stringvalue)
{
if (stringvalue == "pILy^caffs")
{
return true;
}
return false;
}
}
how could it be possible if set
objform.CausesValidation = true;
check this code.
objform.CausesValidation = true;
check this code.
ASKER
hi @Idle_Mind: u r right , but coding is some complex , can u tell me the easy way ??
the below code i can't understand ....
please tell me the easy way ...
the below code i can't understand ....
protected override void WndProc(ref Message m)
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_CLOSE = 0xF060;
if (m.Msg == WM_SYSCOMMAND && (int)m.WParam == SC_CLOSE)
{
UserClosing = true;
}
base.WndProc(ref m);
}
please tell me the easy way ...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks @Idle_Mind: for the help .....
Open in new window
Try that anyway, see if it works.