Comment on paramètre le acceptbutton dans un form

Lucasd Messages postés 76 Date d'inscription lundi 21 février 2005 Statut Membre Dernière intervention 18 mai 2006 - 10 mars 2006 à 11:50
Nikoui Messages postés 794 Date d'inscription vendredi 24 septembre 2004 Statut Membre Dernière intervention 19 août 2008 - 10 mars 2006 à 17:29
Salut , j'ai un form avec 2 boutons (ok et cancel)
J'ai biens dit que le boutton ok (btok) et le boutton de acceptboutton mais quand je clique dessus, j'ai tj annuler qui reviens quand je fais un writeline du résultat!!

voilà le code:
***************************************************************

public partial class queue_conf : Form
{
private int mytimerval;
private string inputfolder;
private string outputfolder;
private string mailuser;
private string mailpasswd;
private bool ok;
private bool ismail;
private bool startnow;



public queue_conf()
{
InitializeComponent();
mytimerval = 5000;
inputfolder = "";
outputfolder = "";
mailuser = "";
mailpasswd = "";
ok = false;
ismail = false;
startnow = true;
AcceptButton = btok; // Je définis l'accept boutton içi!
CancelButton = btcancel;

}

....

private void button1_Click(object sender, EventArgs e)
{

string errormsg = "The following error(s) occured:\n\n";
bool iserror = false;
int x=0;

//1. Test of the timer value validity
if (txtbxtday.Text != "")
{
x += Convert.ToInt32(txtbxtday.Text) * 86400000;
}
if (txtbxthour.Text != "")
{
x += Convert.ToInt32(txtbxthour.Text) * 3600000;
}
if (txtbxtmin.Text != "")
{
x += Convert.ToInt32(txtbxtmin.Text) * 60000;
}
if (txtbxtsec.Text != "")
{
x +=Convert.ToInt32(txtbxtsec.Text) * 1000;
}

if (x > 2073600000 || x < 5000)
{
iserror = true;
errormsg += "-Timer value must be between 5 second and 24 days\n";
}

//2.checking errors in the folder or mail paramaters
//First, we check if folder radio button is checked
if (fileradioButton.Checked == true)
{
if (txtbxinputfile.Text == "")
{
iserror = true;
errormsg += "-You must select an input folder\n";
}
if (txtbxoutputfile.Text == "")
{
iserror = true;
errormsg += "-You must select an output folder\n";
}
}
else
{
if (txtbxinputmail.Text == "")
{
iserror = true;
errormsg += "-You must select an output folder\n";
}
if (txtbxmail.Text == "")
{
iserror = true;
errormsg += "-You must enter an E-mail adress\n";
}
if (txtbxpasswd.Text == "")
{
iserror = true;
errormsg += "-You must enter a password\n";
}

}

//3. If no error we exit, else, we continue
if (iserror == true)
{
ok = false;
MessageBox.Show(errormsg, "Configuration error(s)", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{

ok = true;

startnow = chkbxstart.Checked;
if (fileradioButton.Checked == true)
{
inputfolder = txtbxinputfile.Text;
outputfolder = txtbxoutputfile.Text;
}
else
{
outputfolder = txtbxinputmail.Text;
mailuser = txtbxmail.Text;
mailpasswd = txtbxpasswd.Text;
}

mytimerval = x;
this.AcceptButton = btok;
this.Hide();

}

}
*******************************************************

Je précise que button1_click fais bien référence à l'évènement btok_click

1 réponse

Nikoui Messages postés 794 Date d'inscription vendredi 24 septembre 2004 Statut Membre Dernière intervention 19 août 2008 13
10 mars 2006 à 17:29
Vérifie les TabOrder de tes boutons... Ton bouton btCancel doit avoir le focus à l'ouverture de ta Form, alors que ca devrait être btOk
0
Rejoignez-nous