问题描述:

I have this code:

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

Dim num As String

Dim message As String

Dim name As String

message = txtMessage.Text

Dim count As Integer = Me.TblContactsBindingSource.Count

If i < TblContactsDataGridView.Rows.Count - 1 Then 'stay within bounds

i = i + 1 ' for all rows except Row0

TblContactsDataGridView.Rows(i - 1).DefaultCellStyle.BackColor = Color.White ' restore previous highlight

TblContactsDataGridView.Rows(i).DefaultCellStyle.BackColor = Color.Bisque 'new highlight

num = Me.TblContactsDataGridView.Rows(i).Cells(1).Value.ToString()

name = Me.TblContactsDataGridView.Rows(i).Cells(0).Value.ToString()

If SerialPort1.IsOpen() Then

SerialPort1.Write("AT" & vbCrLf)

SerialPort1.Write("AT+CMGF=1" & vbCrLf)

SerialPort1.Write("AT+CMGS=" & Chr(34) & num & Chr(34) & vbCrLf)

SerialPort1.Write(message & Chr(26))

MessageBox.Show("Message has been successfully sent to " & vbNewLine & name & " (" & num & ") ", "Message Sent", MessageBoxButtons.OK, MessageBoxIcon.Information)

End If

Else 'next row is off the bottom so

'i = 0 'reset index

'TblSmsDataGridView.Rows(TblSmsDataGridView.Rows.Count - 1).DefaultCellStyle.BackColor = Color.White 'restore bottom row

'TblSmsDataGridView.Rows(i).DefaultCellStyle.BackColor = Color.Bisque 'highlight top row

End If

In a command button I have this:

Timer1.Interval = 2000

Timer1.Enabled = True 'no need to enable it and start it; one or t'other

What happen is, the message box appears over and over. How can i trigger message box to automatically close once it is finished? I commented the code in the "else" because the it repeats over and over.

网友答案:

You have to use a custom message box. Normal message box wont do the thing you wanted. It will pop up every 2 second. best choice is to make a new form and show it as a message box. :)

网友答案:

You need to set timer1.enabled = false in the timer1.tick handler.

相关阅读:
Top