扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
|
|
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.saveasToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.printToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.printPreToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); |
#region //辅助方法 /// <summary> /// 当在浏览器地址栏敲"回车"时当前浏览器重定向到指定url(tscbUrl.Tex) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tscbUrl_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { newCurrentPageUrl(tscbUrl.Text); } } /// <summary> /// 新建空白页 /// </summary> private void newPage() { tscbUrl.Text = "about:blank"; TabPage mypage = new TabPage(); WebBrowser tempBrowser = new WebBrowser(); tempBrowser.Navigated += new WebBrowserNavigatedEventHandler(tempBrowser_Navigated); tempBrowser.NewWindow += new CancelEventHandler(tempBrowser_NewWindow); tempBrowser.ProgressChanged += new WebBrowserProgressChangedEventHandler(tempBrowser_ProgressChanged); tempBrowser.StatusTextChanged += new EventHandler(tempBrowser_StatusTextChanged); tempBrowser.Dock = DockStyle.Fill; mypage.Controls.Add(tempBrowser); tabControl1.TabPages.Add(mypage); tabControl1.SelectedTab = mypage; } /// <summary> /// 临时浏览器进度变化事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void tempBrowser_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e) { toolStripProgressBar1.Maximum = (int)e.MaximumProgress; toolStripProgressBar1.Value = (int)e.CurrentProgress; } /// <summary> /// 新建一页并定向到指定url /// </summary> /// <param name="address">新一页的浏览器重新定向到的url</param> private void newPage(string address) { TabPage mypage = new TabPage(); WebBrowser tempBrowser = new WebBrowser(); tempBrowser.Navigated += new WebBrowserNavigatedEventHandler(tempBrowser_Navigated); tempBrowser.NewWindow += new CancelEventHandler(tempBrowser_NewWindow); tempBrowser.StatusTextChanged += new EventHandler(tempBrowser_StatusTextChanged); tempBrowser.ProgressChanged += new WebBrowserProgressChangedEventHandler(tempBrowser_ProgressChanged); tempBrowser.Url = getUrl(address); tempBrowser.Dock = DockStyle.Fill; mypage.Controls.Add(tempBrowser); tabControl1.TabPages.Add(mypage); } /// <summary> /// 获取当前浏览器 /// </summary> /// <returns>当前浏览器</returns> private WebBrowser getCurrentBrowser() { WebBrowser currentBrowser = (WebBrowser)tabControl1.SelectedTab.Controls[0]; return currentBrowser; } /// <summary> /// 处理字符串为合法url /// </summary> /// <param name="address"></param> /// <returns></returns> private Uri getUrl(string address) { string tempaddress = address; if ((!address.StartsWith("http://")) && (!address.StartsWith("https://")) && (!address.StartsWith("ftp://"))) { tempaddress = "http://" + address; } Uri myurl; try { myurl = new Uri(tempaddress); } catch { myurl = new Uri("about:blank"); } return myurl; } /// <summary> /// 截取字符串为指定长度 /// </summary> /// <param name="oldstring"></param> /// <returns></returns> private string newstring(string oldstring) { string temp; if (oldstring.Length < TITLE_COUNT) { temp = oldstring; } else { temp = oldstring.Substring(0, TITLE_COUNT); } return temp; } /// <summary> /// 设置"前进","后退"button的可用状态 /// </summary> private void setStatusButton() { backButton.Enabled = getCurrentBrowser().CanGoBack; forwordButton.Enabled = getCurrentBrowser().CanGoForward; } #endregion |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者