我有一些使用自定义 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();
}