次のように、クリック イベントをサブスクライブするカスタム popupNotifier を使用するコードがいくつかあります。
popupNotifier1.Click += new EventHandler(PopUpClicked);
つまり、誰かがポップアップをクリックして開くと、URL 文字列が起動します。_url
当分の間、グローバルであると仮定します。
私は PopUpClicked でこれを行います:
public void PopUpClicked(object sender, EventArgs e)
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(_url);
proc.StartInfo = startInfo;
proc.Start();
}
URL に_url
は、次のような文字列が含まれます。
http://mysite/mypage.aspx?MyID=100
これで問題なく動作します。ページが開きますが、同じページの複数のタブが開くことに気付きました。私はなぜ理解できないのですか?
編集
さらにコードを追加するために、毎分ヒットするタイマー イベントからこれを呼び出しますが、if 条件に注意してください。データがある場合にのみイベントにサブスクライブします。
private void timer1_Tick(object sender, EventArgs e)
{
SqlDataReader sr;
string ticketInfo = String.Empty;
string url = String.Empty;
bool hasData = false;
using (SqlConnection sc = new SqlConnection(_connString))
{
using (SqlCommand scmd = new SqlCommand("select_poll"))
{
scmd.Connection = sc;
scmd.CommandType = CommandType.StoredProcedure;
scmd.Parameters.Add("LoginID", SqlDbType.BigInt).Value = _userLoginID;
scmd.Parameters.Add("FacilityID", SqlDbType.BigInt).Value = _userFacilityID;
sc.Open();
sr = scmd.ExecuteReader(CommandBehavior.CloseConnection);
if (sr != null)
{
while (sr.Read())
{
hasData = true;
ticketInfo += sr["TicketID"].ToString() + " - " + sr["Ticket"].ToString() + Environment.NewLine;
_url = "http://mysite/mypage.aspx?ID=" + sr["TicketID"].ToString();
}
}
}
}
if (hasData)
{
popupNotifier1.TitleColor = System.Drawing.Color.Green;
popupNotifier1.ContentText = ticketInfo;
popupNotifier1.Scroll = true;
popupNotifier1.TitlePadding = new System.Windows.Forms.Padding(2);
popupNotifier1.ContentPadding = new System.Windows.Forms.Padding(2);
popupNotifier1.Image = Properties.Resources.medical;
popupNotifier1.ImagePadding = new System.Windows.Forms.Padding(10);
popupNotifier1.Click += new EventHandler(PopUpClicked);
popupNotifier1.Popup();
}
}
public void PopUpClicked(object sender, EventArgs e)
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(_url);
proc.StartInfo = startInfo;
proc.Start();
}