I have a message box that pops up when a user click a button. when user click yes it's run an insert
function.
what i want is to add or start a count down when a messagebox
pop up, the default yes button
was disabled. and after 5 second
the yes button
, become enable
and ready to click by user.
if (MessageBox.Show("log", "test", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
insert();
}
As suggested in the comment, you need to have your own implementation for this functionality. Below is partial code that you will need to modify normal form to make it appear like dialogue box:
Add new Form
to your project. Open the porperties tab. Set properties as give below in point 2.
Modify form in designer to change following properties to given values:
this.AcceptButton = this.btnYes;//To simulate clicking *ENTER* (Yes)
this.CancelButton = this.button2; //to close form on *ESCAPE* button
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
//FROM CODEPROJECT ARTICLE LINK
this.ShowInTaskBar = false;
this.StartPosition = CenterScreen;
Add a timer to form. Set its interval to 5000 (5 seconds). Write code to start timer on Shown
event of form:
private void DialogBox_Shown(object sender, EventArgs e)
{
timer1.Start();
}
Handle ticking of Timer:
public DialogBox()
{
InitializeComponent();
//bind Handler to tick event. You can double click in
//properrties>events tab in designer
timer1.Tick += Timer1_Tick;
}
private void Timer1_Tick(object sender, EventArgs e)
{
btnYes.Enabled = true;
timer1.Stop();
}
Set Yes button handler:
private void btnYes_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Yes;
}
From where you are showing this custom message box, you can check if Yes
or No
is clicked as follows:
var d=new DialogBox();
var result=d.ShowDialog();
if(result==DialogResult.Yes)
//here you go....