c#语言的简约浏览器,多标签网页浏览器,html网页浏览器,界面简约,符合现代审美,网页浏览很快,不卡顿,感兴趣的朋友可以下载来研究一下
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;
using System.Net;
using 简约浏览器.CYH_CL;
using 简约浏览器.CYH_OP;
using System.Runtime.InteropServices;
using System.Threading;
namespace 简约浏览器.CYH_UI
{
public partial class Frm_Main : Form
{
Skin skin = new Skin();
Setting setting = new Setting();
Image[] Favicon = new Image[50];//存储网站logo
//在主窗体类中定义一个静态数据成员,来保存当前主窗体对象
public static Frm_Main pMainWin = null;
//WebBrowser数组
public List<ExtendedWebBrowser> WebBrowserArr;
//浏览历史文件,记录
public string HisXml = "History.xml";
//默认皮肤
private static Bitmap initBg;
public Frm_Main()
{
InitializeComponent();
//加载默认值
//浏览器数组
WebBrowserArr = new List<ExtendedWebBrowser>();
WebBrowserArr.Add(this.webMain);
//加载浏览历史
if (!File.Exists(HisXml))
{
CreateConfigXml(HisXml);
}
else
{
string[] urls = ReadConfigXml(HisXml);
if (urls.Length > 0)
{
for (int i = 0; i < urls.Length; i )
{
textBox1.AutoCompleteCustomSource.Add(urls[i]);
textBox1.Items.Add(urls[i]);
}
}
}
//加载皮肤
if (InitImage())
{
this.BackgroundImage = initBg;
button3_Click(null, null);
}
//进度条进度显示
WebBrowserArr[tabMain.SelectedIndex].ProgressChanged = new WebBrowserProgressChangedEventHandler(Frm_Main_ProgressChanged);
//状态栏更新
WebBrowserArr[tabMain.SelectedIndex].StatusTextChanged = new EventHandler(Frm_Main_StatusTextChanged);
}
#region 窗体调用辅助属性
/// <summary>
/// 当前Url
/// </summary>
private static string url;
public static string Url
{
get { return url; }
set { url = value; }
}
/// <summary>
/// 当前所选选项卡的索引
/// </summary>
public int TabSelectedIndex
{
get { return tabMain.SelectedIndex; }
}
#endregion 窗体调用辅助属性
#region 辅助方法
//加载皮肤
bool InitImage()
{
int i = int.Parse(skin.getBgConfig());
try
{
initBg = new Bitmap(@"skin/bg/" i ".jpg");
this.Icon = new Icon(@"skin/ico/Logo.ico");
return true;
}
catch
{
MessageBox.Show("目前暂不支持打开其他文件-简约浏览器");
return false;
}
}
/// <summary>
/// 删除指定索引的页面
/// </summary>
/// <param name="index">要删除页面的索引</param>
void DeleteTag(int index)
{
if (this.tabMain.TabPages.Count <= 1 || index < 0)
{
return;
}
//移除Logo链表(tb.SelectedIndex 1根据先前保留0的决定)
#region 移除对应logo
Image[] img = new Image[imgLstfavicon.Images.Count];//保存所选选卡后面的Logo
int len = imgLstfavicon.Images.Count;
for (int j = index 1; j < len; j )
{
img[j] = imgLstfavicon.Images[index 1];
Favicon[j - 1] = imgLstfavicon.Images[index 1];//使Favicon与对应选项卡Logo依旧保持一一对应关系
imgLstfavicon.Images.RemoveAt(index 1);
}
if (Favicon[index] != null)
{
imgLstfavicon.Images.Add(Favicon[index]);
}
else
{
imgLstfavicon.Images.Add(imgLstfavicon.Images[0]);
}
for (int j = index 2; j < img.Length; j )
{
imgLstfavicon.Images.Add(img[j]);
}
#endregion
//imgLstfavicon.Images.RemoveAt(tabMain.SelectedIndex 1);
if (index == this.tabMain.TabPages.Count - 1)
{
tabMain.Visible = false;
WebBrowserArr[index].Dispose(); //释放资源
WebBrowserArr.RemoveAt(index);
tabMain.TabPages.RemoveAt(index);
tabMain.SelectedIndex = index - 1;
tabMain.Visible = true;
}
else
{
tabMain.Visible = false;
WebBrowserArr[index].Dispose(); //释放资源
WebBrowserArr.RemoveAt(index);
tabMain.TabPages.RemoveAt(index);
tabMain.SelectedIndex = index;
tabMain.Visible = true;
}
}
/// <summary>
/// 获取网站的标题图片
/// </summary>
/// <param name="strUrl">网址</param>
/// <returns></returns>
private Image GetFavicon(string strUrl)
{
var uri = new Uri(strUrl);
HttpWebRequest vHttpWebRequest = (HttpWebRequest)WebRequest.Create(
@"http://" uri.Host @"/favicon.ico");
HttpWebResponse vHttpWebResponse = (HttpWebResponse)vHttpWebRequest.GetResponse();
Image vFavicon = Image.FromStream(vHttpWebResponse.GetResponseStream());
vHttpWebResponse.Close();
if (vFavicon != null)
{
return vFavicon;
}
else
{
return imgLstfavicon.Images[0];
}
}
/// <summary>
/// 处理字符串为合法url
/// </summary>
/// <param name="address"></param>
/// <returns></returns>
private Uri getUrl(string strSite)
{
string site = strSite;
if ((!strSite.StartsWith("http://"))
&& (!strSite.StartsWith("https://"))
&& (!strSite.StartsWith("ftp://"))
&& (!strSite.StartsWith("file://")))
{
if (site.IndexOf(':') == 1)//打开本地磁盘文件时
{
site = "file:///" strSite.Replace(@"\", "/");
}
else
{
site = "http://" strSite;
}
}
Uri uri;
try
{
uri = new Uri(site);
}
catch
{
uri = new Uri("about:blank");
}
return uri;
}
//创建xml文件
void CreateConfigXml(string xmlFile)
{
XmlTextWriter xmlW = new XmlTextWriter(xmlFile, Encoding.UTF8);
xmlW.WriteStartDocument();
xmlW.WriteStartElement("Histories");
xmlW.WriteEndElement();
xmlW.Close();
}
//读历史文件
string[] ReadConfigXml(string xmlFile)
{
if (File.Exists(xmlFile))
{
XmlDocument doc = new XmlDocument();
doc.Load(xmlFile);
XmlElement root = doc.DocumentElement;
if (root.HasChildNodes)
{
string[] xmlHis = new string[root.ChildNodes.Count];
for (int i = 0; i < root.ChildNodes.Count; i )
{
xmlHis[i] = root.ChildNodes[i].ChildNodes[0].InnerText;
}
return xmlHis;
}
else
{
return new string[] { };
}
}
else
{
return new string[] { };
}
}
//记录历史信息
private void RecordUrls(string strUrl)
{
if (textBox1.Items.Count >= 1)
{
if (textBox1.Items.IndexOf(strUrl) < 0)
{
if (!File.Exists(HisXml))
CreateConfigXml(HisXml);
WriteConfigXml(HisXml, "Url", "Address", strUrl);
}
}
else
{
WriteConfigXml(HisXml, "Url", "Address", strUrl);
textBox1.Items.Add(strUrl);
textBox1.AutoCompleteCustomSource.Add(strUrl);
}
}
//写入Xml文件里
void WriteConfigXml(string xmlFile, string strUrl, string strAddress, string strText)
{
XmlDocument doc = new XmlDocument();
doc.Load(xmlFile);
XmlElement root = doc.DocumentElement;
XmlElement url = doc.CreateElement(strUrl);
XmlElement addr = doc.CreateElement(strAddress);
XmlText txt = doc.CreateTextNode(strText);
addr.AppendChild(txt);
url.AppendChild(addr);
root.AppendChild(url);
doc.Save(xmlFile);
}
#endregion
private GraphicsPath GetRoundedRectPath(Rectangle rect, int radius)
{
int diameter = radius;
Rectangle arcRect = new Rectangle(rect.Location, new Size(diameter, diameter));
GraphicsPath path = new GraphicsPath();
// 左上角
path.AddArc(arcRect, 180, 90);
// 右上角
arcRect.X = rect.Right - diameter;
path.AddArc(arcRect, 270, 90);
// 右下角
arcRect.Y = rect.Bottom - diameter;
path.AddArc(arcRect, 0, 90);
// 左下角
arcRect.X = rect.Left;
path.AddArc(arcRect, 90, 90);
path.CloseFigure();//闭合曲线
return path;
}
/// <summary>
/// 当窗口改变时调动SetWindowsRegion函数改变窗口形象
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Frm_Main_Resize(object sender, EventArgs e)
{
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
this.Refresh();
}
#region 只差拖动和拖拽大小了
const int WM_NCHITTEST = 0x0084;
const int HT_LEFT = 10;
const int HT_RIGHT = 11;
const int HT_TOP = 12;
const int HT_TOPLEFT = 13;
const int HT_TOPRIGHT = 14;
const int HT_BOTTOM = 15;
const int HT_BOTTOMLEFT = 16;
const int HT_BOTTOMRIGHT = 17;
const int HT_CAPTION = 2;
protected override void WndProc(ref Message Msg)
{
if (Msg.Msg == WM_NCHITTEST)
{
//获取鼠标位置
int nPosX = (Msg.LParam.ToInt32() & 65535);
int nPosY = (Msg.LParam.ToInt32() >> 16);
//右下角
if (nPosX >= this.Right - 6 && nPosY >= this.Bottom - 6)
{
Msg.Result = new IntPtr(HT_BOTTOMRIGHT);
return;
}
//左上角
else if (nPosX <= this.Left 6 && nPosY <= this.Top 6)
{
Msg.Result = new IntPtr(HT_TOPLEFT);
return;
}
//左下角
else if (nPosX <= this.Left 6 && nPosY >= this.Bottom - 6)
{
Msg.Result = new IntPtr(HT_BOTTOMLEFT);
return;
}
//右上角
else if (nPosX >= this.Right - 6 && nPosY <= this.Top 6)
{
Msg.Result = new IntPtr(HT_TOPRIGHT);
return;
}
else if (nPosX >= this.Right - 2)
{
Msg.Result = new IntPtr(HT_RIGHT);
return;
}
else if (nPosY >= this.Bottom - 2)
{
Msg.Result = new IntPtr(HT_BOTTOM);
return;
}
else if (nPosX <= this.Left 2)
{
Msg.Result = new IntPtr(HT_LEFT);
return;
}
else if (nPosY <= this.Top 2)
{
Msg.Result = new IntPtr(HT_TOP);
return;
}
else
{
Msg.Result = new IntPtr(HT_CAPTION);
return;
}
}
base.WndProc(ref Msg);
}
/// <summary>
/// 自定义窗口最小化按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Mnmized_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
/// <summary>
/// 自定义窗口最大化按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Mmmized_Click(object sender, EventArgs e)
{
if (this.btn_Mmmized.ImageIndex == 2)
{
this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
this.WindowState = FormWindowState.Maximized;
this.btn_Mmmized.ImageIndex = 1;
}
else
{
this.WindowState = FormWindowState.Normal;
this.btn_Mmmized.ImageIndex = 2;
}
}
/// <summary>
/// 退出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Close_Click(object sender, EventArgs e)
{
if (setting.getExitConfig())
{
AniWindow a = new AniWindow(this.Handle, 7, 200, this);//从四周向中间隐藏
this.Dispose();
Application.Exit();
}
else
{
Frm_Exit_Dialog frm_Exit = new Frm_Exit_Dialog();
frm_Exit.ShowDialog();
}
}
#endregion 只差拖动和拖拽大小了
#region 主窗体按钮事件
/// <summary>
/// 转入按钮事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_go_Click(object sender, EventArgs e)
{
if (this.textBox1.Text.Trim().Length > 0)
{
NavToUrl(this.textBox1.Text.ToString().Trim());
}
}
/// <summary>
/// 刷新按钮事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_refresh_Click(object sender, EventArgs e)
{
WebBrowserArr[tabMain.SelectedIndex].Refresh();
}
/// <summary>
/// 主页点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_home_Click(object sender, EventArgs e)
{
if (setting.getHomepages().Trim() == "IE")
{
WebBrowserArr[tabMain.SelectedIndex].GoHome();
}
else
{
NavToUrl(setting.getHomepages().Trim());
}
}
/// <summary>
/// 后退键点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_previous_Click(object sender, EventArgs e)
{
WebBrowserArr[tabMain.SelectedIndex].GoBack();
}
/// <summary>
/// 前进按钮点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_next_Click(object sender, EventArgs e)
{
WebBrowserArr[tabMain.SelectedIndex].GoForward();
}
/// <summary>
/// 主搜索按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Search_Click(object sender, EventArgs e)
{
StringBuilder strB = new StringBuilder();
strB.Append(setting.getSearch_Engine().Replace("CYH", textBox1.Text.Trim()));
//WebBrowserArr[tabMain.SelectedIndex].GoSearch();
NavToUrl(strB.ToString());
//保存搜索历史
setting.saveSearchHis(textBox1.Text.Trim());
}
/// <summary>
/// 停止按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_stop_Click(object sender, EventArgs e)
{
WebBrowserArr[tabMain.SelectedIndex].Stop();
}
private void btnNew_Click(object sender, EventArgs e)
{
CreateNewTabPage();
}
/// <summary>
/// 设置菜单
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Menu_Click(object sender, EventArgs e)
{
if (Application.OpenForms["frm_mMenu"] == null)
{
Frm_mMenu frm_mMenu = new Frm_mMenu();
frm_mMenu.Location = new Point(btn_Menu.Location.X
Frm_Main.pMainWin.Location.X - frm_mMenu.Width, btn_Menu.Location.Y
Frm_Main.pMainWin.Location.Y btn_Menu.Height);
frm_mMenu.Show();
}
}
/// <summary>
/// 更换皮肤
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Skin_Click(object sender, EventArgs e)
{
if (Application.OpenForms["frm_Skin"] == null)
{
Frm_Skin frm_Skin = new Frm_Skin();
frm_Skin.Location = new Point(btn_Skin.Location.X
Frm_Main.pMainWin.Location.X - frm_Skin.Width,
btn_Skin.Location.Y Frm_Main.pMainWin.Location.Y btn_Skin.Height);
frm_Skin.Show();
}
}
private void btn_Blank_Click(object sender, EventArgs e)
{
if (Application.OpenForms["frm_About"] == null)
{
Frm_About frm_About = new Frm_About();
frm_About.Show();
}
}
private void btn_DownLoad_Click(object sender, EventArgs e)
{
if (Application.OpenForms["frm_Download"] == null)
{
Frm_DownLoad frm_Download = new Frm_DownLoad();
frm_Download.Show();
}
//if (Application.OpenForms["frm_Download_Dialog"] == null)
//{
// Frm_Download_Dialog frm_Download_Dialog = new Frm_Download_Dialog();
// frm_Download_Dialog.Show();
//}
}
#endregion 主窗体按钮事件
#region 主窗体事件
private void Frm_Main_Load(object sender, EventArgs e)
{
////进首页
//if (false)//读取配置文件
//{
// WebBrowserArr[tabMain.SelectedIndex].GoHome();
//}
this.panelSeach.Visible = false;
AniWindow a = new AniWindow(this.Handle, 6, 200, this);//Win7打开效果(个人全部加载后再调用效果较好)
}
/// <summary>
/// 进度条更新
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Frm_Main_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)
{
progressBar1.Visible = true;
if ((e.CurrentProgress > 0) && (e.MaximumProgress > 0))
{
pictureBox17.Visible = true;
progressBar1.Maximum = Convert.ToInt32(e.MaximumProgress);
progressBar1.Step = Convert.ToInt32(e.CurrentProgress);
progressBar1.PerformStep();
pictureBox19.Visible = true;
label2.Visible = true;
label1.Visible = true;
}
else if (WebBrowserArr[tabMain.SelectedIndex].ReadyState == WebBrowserReadyState.Complete)
{
pictureBox17.Visible = false;
progressBar1.Value = 0;
progressBar1.Visible = false;
pictureBox19.Visible = false;
label2.Visible = false;
label1.Visible = false;
}
}
/// <summary>
/// 状态栏更新
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void Frm_Main_StatusTextChanged(object sender, EventArgs e)
{
}
/// <summary>
/// 发生导航
/// </summary>
/// <param name="strUrl">地址</param>
public void NavToUrl(string strUrl)
{
WebBrowserArr[tabMain.SelectedIndex].Navigate(getUrl(strUrl));
}
//监听Enter键
//双击选项卡 删除页面
private void tabMain_DoubleClick(object sender, EventArgs e)
{
DeleteTag(this.tabMain.SelectedIndex);
}
private void tabMain_Selected(object sender, TabControlEventArgs e)
{
if (tabMain.TabCount > 0 && e.TabPageIndex > 0)
{
if (WebBrowserArr[e.TabPageIndex].Document != null)
{
string t = WebBrowserArr[e.TabPageIndex].Document.Title;
this.textBox1.Text = WebBrowserArr[e.TabPageIndex].Document.Url.ToString();
this.Text = (t.Length > 0 ? t : this.Text);
}
else
{
textBox1.Text = "";
}
}
}
void webMain_BeforeNewWindow(object sender, System.EventArgs e)
{
CreateNewTabPage();
WebBrowserExtendedNavigatingEventArgs eventArgs = e as WebBrowserExtendedNavigatingEventArgs;
WebBrowserArr[tabMain.TabCount - 1].Navigate(eventArgs.Url);
eventArgs.Cancel = true;
}
//可外部调用的新建空白页
public void pCreateNewTabge()
{
CreateNewTabPage();
}
private void CreateNewTabPage()
{
ExtendedWebBrowser web = new ExtendedWebBrowser();
web.Name = "WebBroswer" WebBrowserArr.Count.ToString();
web.Dock = DockStyle.Fill;
web.Margin = new Padding(0, 0, 0, 0);
web.DocumentCompleted = new WebBrowserDocumentCompletedEventHandler(webMain_DocumentCompleted);
web.BeforeNewWindow = new EventHandler(webMain_BeforeNewWindow);
WebBrowserArr.Add(web);
TabPage tbp = new TabPage();
tbp.Name = "TablePage" tabMain.TabCount.ToString();
tbp.Text = "新建标签页 ";
tbp.Padding = new Padding(0, 3, 0, 0);
tbp.Margin = new Padding(0, 3, 0, 0);
tbp.ImageIndex = 0;
tbp.Controls.Add(web);
this.tabMain.Controls.Add(tbp);
this.tabMain.SelectedIndex = this.tabMain.TabPages.Count - 1;
tbp.BorderStyle = tbpMain.BorderStyle;
//进度条进度显示
WebBrowserArr[tabMain.SelectedIndex].ProgressChanged = new WebBrowserProgressChangedEventHandler(Frm_Main_ProgressChanged);
//状态栏更新
WebBrowserArr[tabMain.SelectedIndex].StatusTextChanged = new EventHandler(Frm_Main_StatusTextChanged);
}
//页面加载完毕后
private void webMain_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
ExtendedWebBrowser web = (ExtendedWebBrowser)(sender);
string tit = web.Document.Title.Trim();
TabPage tb = (TabPage)web.Parent;
tb.Text = tit.Length > 6 ? tit.Substring(0, 6) "..." : tit;
if (tabMain.SelectedTab == tb)
{
this.Text = tit @" - 简约浏览器";
}
//XML方式保存Url访问地址
RecordUrls(web.Url.ToString());
//文本方式保存Url访问历史
setting.saveUrlHis(tit, web.Url.ToString());
textBox1.Text = web.Url.ToString(); //地址显示当前地址
//显示网站Logo
try
{
Favicon[tabMain.SelectedIndex] = GetFavicon(WebBrowserArr[tabMain.SelectedIndex].Document.Url @"\favico.ico");
Image[] img = new Image[imgLstfavicon.Images.Count];//保存所选选卡后面的Logo
int len = imgLstfavicon.Images.Count;
for (int i = tabMain.SelectedIndex 1; i < len; i )
{
img[i] = imgLstfavicon.Images[tabMain.SelectedIndex 1];
imgLstfavicon.Images.RemoveAt(tabMain.SelectedIndex 1);
}
imgLstfavicon.Images.Add(Favicon[tabMain.SelectedIndex]);
for (int i = tabMain.SelectedIndex 2; i < img.Length; i )
{
imgLstfavicon.Images.Add(img[i]);
}
this.tabMain.SelectedTab.ImageIndex = tabMain.SelectedIndex 1;//第n个选项卡的图标为List图标中的第n 1个(0号为空)
}
catch
{
imgLstfavicon.Images.Add(imgLstfavicon.Images[0]);
}
}
////双击空白处 创建空白页
////此处会有一个bug 就是 必须最大化窗口 双击才有效果
//private void panel2_DoubleClick(object sender, EventArgs e)
//{
// if ((MousePosition.X > 1 && MousePosition.X < this.panel2.Width) && (MousePosition.Y > this.panel2.Location.Y && MousePosition.Y < this.panel2.Location.Y 40))
// {
// CreateNewTabPage();
// }
//}
/// <summary>
/// 导航发生后发生
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void webMain_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
Url = this.WebBrowserArr[tabMain.SelectedIndex].Url.ToString();
this.textBox1.Text = Url;
if (!Url.EndsWith(".html") && !Url.EndsWith(".htm") && !Url.EndsWith(".jsp")
&& !Url.EndsWith(".aspx") && !Url.EndsWith(".asp") && !Url.EndsWith("/")
&& Url.Substring(Url.Length - 6, 5).Contains("."))
{
Frm_Download_Dialog frm_Download_Dialog = new Frm_Download_Dialog();
frm_Download_Dialog.Show();
WebBrowserArr[tabMain.SelectedIndex].Stop();//停止导航
}
}
//文件下载时发生
private void webMain_FileDownload(object sender, EventArgs e)
{
Url = this.WebBrowserArr[tabMain.SelectedIndex].Url.ToString();
//MessageBox.Show("文件下载发生时");
}
private void btn_Menu_MouseHover(object sender, EventArgs e)
{
btn_Menu_Click(sender, e);
this.btn_Menu.FlatStyle = FlatStyle.Popup;
}
private void btn_Menu_MouseLeave(object sender, EventArgs e)
{
this.btn_Menu.FlatStyle = FlatStyle.Flat;
}
private void btn_Skin_MouseHover(object sender, EventArgs e)
{
btn_Skin_Click(sender, e);
this.btn_Skin.FlatStyle = FlatStyle.Popup;
}
private void btn_Skin_MouseLeave(object sender, EventArgs e)
{
this.btn_Skin.FlatStyle = FlatStyle.Flat;
}
#endregion 主窗体事件
#region 高级搜索功能
/// <summary>
/// 伸缩导航条,显示高级搜索
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void lbl_Search_Exp_Swch_Click(object sender, EventArgs e)
{
this.panelSeach.Visible = true;
int width = this.panelTop.Width;
int height = this.panelTop.Height;
int x = this.panelTop.Location.X;
int y = this.panelTop.Location.Y;
if (this.lbl_Search_Exp_Swch.Text == "<<")
{
this.panelTop.Visible = false;//保证伸缩过程没有残影
this.panelTop.SetBounds(x, y, width - this.panelSeach.Width - 5, height);
this.panelTop.Visible = true;
this.lbl_Search_Exp_Swch.Text = ">>";
}
else
{
this.panelTop.Visible = false;
this.panelTop.SetBounds(x, y, width this.panelSeach.Width 5, height);
this.panelTop.Visible = true;
this.lbl_Search_Exp_Swch.Text = "<<";
}
//cmbBox_SearchText加载搜索记录
cmbBox_SearchTxt.DataSource = setting.getSearchHis();
//cmbBox_Engine加载搜索引擎
cmbBox_Engine.DataSource = setting.getListEngine();
}
private void cmbBox_Engine_SelectedIndexChanged(object sender, EventArgs e)
{
//通过选择设置搜索引擎
List<string[]> lstArr = setting.getListEngineArr();
foreach (var item in lstArr)
{
if (item[0] == this.cmbBox_Engine.Text)
{
setting.setSearch_Engine(item[1]);
return;
}
}
}
/// <summary>
/// 高级搜索按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Search_Exp_Click(object sender, EventArgs e)
{
StringBuilder strB = new StringBuilder();
strB.Append(setting.getSearch_Engine());
if (rdBtn_DOC.Checked)
{
strB = strB.Replace("CYH", "CYH filetype:DOC");
}
if (rdBtn_PPT.Checked)
{
strB = strB.Replace("CYH", "CYH filetype:PPT");
}
if (rdnBtn_PDF.Checked)
{
strB = strB.Replace("CYH", "CYH filetype:PDF");
}
if (txtBox_Site.Text.Contains("."))
{
strB.Append(" site:" txtBox_Site.Text.Trim());
}
//WebBrowserArr[tabMain.SelectedIndex].GoSearch();
// C# Url传递中文 转义编码
//百度的编码
//System.Web.HttpUtility.UrlEncode( "中文 ", System.Text.UnicodeEncoding.GetEncoding( "GB2312 ")).ToUpper()
//Google的编码
//System.Web.HttpUtility.UrlEncode( "中文 ")
//得到值
//System.Web.HttpUtility.UrlDecode( "%BA%AB%B9%FA%D3%EF%D1%A7%CF%B0%D7%CA%C1%CF ", System.Text.UnicodeEncoding.GetEncoding( "GB2312 "))
NavToUrl(strB.Replace("CYH", cmbBox_SearchTxt.Text.Trim()).ToString());
//保存搜索历史
setting.saveSearchHis(this.cmbBox_SearchTxt.Text.Trim());
}
#endregion 高级搜索功能
#region 标签右键快捷菜单
private void 新建标签ToolStripMenuItem_Click(object sender, EventArgs e)
{
CreateNewTabPage();
}
private void 刷新当前ToolStripMenuItem_Click(object sender, EventArgs e)
{
WebBrowserArr[tabMain.SelectedIndex].Refresh();
}
private void 关闭当前标签ToolStripMenuItem_Click(object sender, EventArgs e)
{
DeleteTag(tabMain.SelectedIndex);
}
private void 关闭所有标签ToolStripMenuItem_Click(object sender, EventArgs e)
{
int flag = tabMain.TabPages.Count;
for (int i = 0; i < flag; i )
{
DeleteTag(0);
}
}
private void 关闭右边标签ToolStripMenuItem_Click(object sender, EventArgs e)
{
int flag = tabMain.SelectedIndex;
int len = tabMain.TabPages.Count;
for (int i = flag 1; i < len; i )
{
DeleteTag(flag 1);
}
}
private void 关闭左边标签ToolStripMenuItem_Click(object sender, EventArgs e)
{
int flag = tabMain.SelectedIndex;
for (int i = flag - 1; i > -1; i--)
{
DeleteTag(tabMain.SelectedIndex - 1);
}
}
private void cmbBox_SearchTxt_Click(object sender, EventArgs e)
{
if (cmbBox_SearchTxt.Text.Equals("这里输入要搜索的内容"))
{
cmbBox_SearchTxt.Text = "";
}
}
private void txtBox_Site_Click(object sender, EventArgs e)
{
if (txtBox_Site.Text.Equals("站点"))
{
txtBox_Site.Text = "cnblogs.com";
}
}
#endregion 标签右键快捷菜单
#region 按钮功能提示
private void ShowMgByLoaction(Button btn, string strMg)
{
if (Application.OpenForms["frm_Message"] == null)
{
Frm_Message frm_Message = new Frm_Message();
frm_Message.strMg = strMg;
frm_Message.Show();
}
}
private void btn_Search_MouseHover(object sender, EventArgs e)
{
}
private void btn_Search_MouseLeave(object sender, EventArgs e)
{
Frm_Message.IsClose = true;
}
private void btn_Add_MouseHover(object sender, EventArgs e)
{
}
private void btn_Add_MouseLeave(object sender, EventArgs e)
{
Frm_Message.IsClose = true;
}
private void btn_DownLoad_MouseHover(object sender, EventArgs e)
{
}
private void btn_DownLoad_MouseLeave(object sender, EventArgs e)
{
Frm_Message.IsClose = true;
}
private void btn_stop_MouseHover(object sender, EventArgs e)
{
}
private void btn_stop_MouseLeave(object sender, EventArgs e)
{
Frm_Message.IsClose = true;
}
private void btn_go_MouseHover(object sender, EventArgs e)
{
}
private void btn_go_MouseLeave(object sender, EventArgs e)
{
Frm_Message.IsClose = true;
}
private void btn_refresh_MouseHover(object sender, EventArgs e)
{
}
private void btn_refresh_MouseLeave(object sender, EventArgs e)
{
Frm_Message.IsClose = true;
}
private void btn_next_MouseHover(object sender, EventArgs e)
{
}
private void btn_next_MouseLeave(object sender, EventArgs e)
{
Frm_Message.IsClose = true;
}
private void btn_previous_MouseHover(object sender, EventArgs e)
{
}
private void btn_previous_MouseLeave(object sender, EventArgs e)
{
Frm_Message.IsClose = true;
}
private void btn_Search_Exp_Swch_MouseLeave(object sender, EventArgs e)
{
Frm_Message.IsClose = true;
}
private void btn_Search_Exp_MouseHover(object sender, EventArgs e)
{
}
private void btn_Search_Exp_MouseLeave(object sender, EventArgs e)
{
Frm_Message.IsClose = true;
}
private void lbl_Search_Exp_Swch_MouseHover(object sender, EventArgs e)
{
this.lbl_Search_Exp_Swch.BorderStyle = BorderStyle.Fixed3D;
}
private void lbl_Search_Exp_Swch_MouseLeave(object sender, EventArgs e)
{
this.lbl_Search_Exp_Swch.BorderStyle = BorderStyle.None;
}
#endregion 按钮功能提示
private void contextMenuStripTag_Opening(object sender, System.ComponentModel.CancelEventArgs e)
{
Bitmap bitmap = new Bitmap(this.BackgroundImage);
this.BackColor = bitmap.GetPixel(20, 15);
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox1_TextChanged_1(object sender, EventArgs e)
{
}
private void cmbBoxUrl_SelectedIndexChanged(object sender, EventArgs e)
{
button3_Click(null, null);
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
}
private void textBox2_TextChanged_1(object sender, EventArgs e)
{
}
private void btn_Search_KeyDown(object sender, KeyEventArgs e)
{
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
btn_Search_Click(null, null);
}
}
private void toolTip1_Popup(object sender, PopupEventArgs e)
{
}
private void tbpMain_Click(object sender, EventArgs e)
{
}
private void pictureBox5_Click(object sender, EventArgs e)
{
}
private void panelTop_Paint(object sender, PaintEventArgs e)
{
}
private void button2_Click_1(object sender, EventArgs e)
{
btn_Mmmized_Click(null, null);
}
private void button3_Click(object sender, EventArgs e)
{
btn_Mmmized_Click(null, null);
button2_Click_1(null, null);
}
private void button4_Click(object sender, EventArgs e)
{
button3_Click(null, null);
}
private void pictureBox12_MouseEnter(object sender, EventArgs e)
{
button3_Click(null, null);
pictureBox12.Visible = false;
if (setting.getHomepages().Trim() == "IE")
{
WebBrowserArr[tabMain.SelectedIndex].GoHome();
}
else
{
NavToUrl(setting.getHomepages().Trim());
}
}
private void button1_Click(object sender, EventArgs e)
{
panelTop.Visible = false;
button1.Visible = false;
}
private void pictureBox12_Click(object sender, EventArgs e)
{
}
private void tabMain_MouseUp(object sender, MouseEventArgs e)
{
DeleteTag(tabMain.SelectedIndex);
}
private void tabMain_ControlAdded(object sender, ControlEventArgs e)
{
//添加
pictureBox11.Location = new Point(pictureBox11.Location.X 124, pictureBox11.Location.Y);
pictureBox13.Location = new Point(pictureBox13.Location.X 124, pictureBox13.Location.Y);
pictureBox14.Location = new Point(pictureBox14.Location.X 124, pictureBox14.Location.Y);
pictureBox15.Location = new Point(pictureBox15.Location.X 124, pictureBox15.Location.Y);
}
private void tabMain_ControlRemoved(object sender, ControlEventArgs e)
{
//移除
pictureBox11.Location = new Point(pictureBox11.Location.X - 124, pictureBox11.Location.Y);
pictureBox13.Location = new Point(pictureBox13.Location.X - 124, pictureBox13.Location.Y);
pictureBox14.Location = new Point(pictureBox14.Location.X - 124, pictureBox14.Location.Y);
pictureBox15.Location = new Point(pictureBox15.Location.X - 124, pictureBox15.Location.Y);
}
private void pictureBox11_Click(object sender, EventArgs e)
{
DeleteTag(tabMain.SelectedIndex);
}
private void pictureBox11_MouseEnter(object sender, EventArgs e)
{
pictureBox11.Visible = false;
pictureBox17.Visible = true;
label14.Visible = true;
}
private void pictureBox13_MouseLeave(object sender, EventArgs e)
{
pictureBox11.Visible = true;
pictureBox17.Visible = false;
label14.Visible = false;
}
private void pictureBox14_Click(object sender, EventArgs e)
{
CreateNewTabPage();
}
private void pictureBox14_MouseEnter(object sender, EventArgs e)
{
pictureBox14.Visible = false;
pictureBox17.Visible = true;
label15.Visible = true;
}
private void pictureBox13_Click(object sender, EventArgs e)
{
DeleteTag(tabMain.SelectedIndex);
}
private void pictureBox15_Click(object sender, EventArgs e)
{
CreateNewTabPage();
}
private void pictureBox15_MouseLeave_1(object sender, EventArgs e)
{
pictureBox14.Visible = true;
pictureBox17.Visible = false;
label15.Visible = false;
}
private void button4_Click_1(object sender, EventArgs e)
{
WebBrowserArr[tabMain.SelectedIndex].GoBack();
}
private void button5_Click(object sender, EventArgs e)
{
WebBrowserArr[tabMain.SelectedIndex].GoForward();
}
private void button6_Click(object sender, EventArgs e)
{
WebBrowserArr[tabMain.SelectedIndex].Refresh();
}
private void button7_Click(object sender, EventArgs e)
{
if (setting.getHomepages().Trim() == "IE")
{
WebBrowserArr[tabMain.SelectedIndex].GoHome();
}
else
{
NavToUrl(setting.getHomepages().Trim());
}
}
private void btn_previous_MouseEnter(object sender, EventArgs e)
{
btn_previous.Visible = false;
label3.Visible = true;
pictureBox17.Visible = true;
}
private void btn_next_MouseEnter(object sender, EventArgs e)
{
btn_next.Visible = false;
label4.Visible = true;
pictureBox17.Visible = true;
}
private void btn_refresh_MouseEnter(object sender, EventArgs e)
{
btn_refresh.Visible = false;
label5.Visible = true;
pictureBox17.Visible = true;
}
private void btn_home_MouseEnter(object sender, EventArgs e)
{
btn_home.Visible = false;
label9.Visible = true;
pictureBox17.Visible = true;
}
private void button4_MouseLeave(object sender, EventArgs e)
{
btn_previous.Visible = true;
label3.Visible = false;
pictureBox17.Visible = false;
}
private void button5_MouseLeave(object sender, EventArgs e)
{
btn_next.Visible = true;
label4.Visible = false;
pictureBox17.Visible = false;
}
private void button6_MouseLeave(object sender, EventArgs e)
{
btn_refresh.Visible = true;
label5.Visible = false;
pictureBox17.Visible = false;
}
private void button7_MouseLeave(object sender, EventArgs e)
{
btn_home.Visible = true;
label9.Visible = false;
pictureBox17.Visible = false;
}
private void btn_DownLoad_MouseEnter(object sender, EventArgs e)
{
pictureBox17.Visible = true;
btn_DownLoad.Visible = false;
label10.Visible = true;
}
private void btn_Blank_MouseEnter(object sender, EventArgs e)
{
pictureBox17.Visible = true;
btn_Blank.Visible = false;
label11.Visible = true;
}
private void button10_MouseEnter(object sender, EventArgs e)
{
label12.Visible = true;
pictureBox17.Visible = true;
}
private void button8_MouseLeave(object sender, EventArgs e)
{
btn_DownLoad.Visible = true;
label10.Visible = false;
pictureBox17.Visible = false;
}
private void button9_MouseLeave(object sender, EventArgs e)
{
btn_Blank.Visible = true;
label11.Visible = false;
pictureBox17.Visible = false;
}
private void button10_MouseLeave(object sender, EventArgs e)
{
label12.Visible = false;
pictureBox17.Visible = false;
}
private void button8_Click(object sender, EventArgs e)
{
if (Application.OpenForms["frm_Download"] == null)
{
Frm_DownLoad frm_Download = new Frm_DownLoad();
frm_Download.Show();
}
//if (Application.OpenForms["frm_Download_Dialog"] == null)
//{
// Frm_Download_Dialog frm_Download_Dialog = new Frm_Download_Dialog();
// frm_Download_Dialog.Show();
//}
}
private void button9_Click(object sender, EventArgs e)
{
if (Application.OpenForms["frm_About"] == null)
{
Frm_About frm_About = new Frm_About();
frm_About.Show();
}
}
private void button10_Click(object sender, EventArgs e)
{
panelTop.Visible = false;
}
private void tabMain_MouseEnter(object sender, EventArgs e)
{
pictureBox17.Visible = true;
label13.Visible = true;
}
private void tabMain_MouseLeave(object sender, EventArgs e)
{
pictureBox17.Visible = false;
label13.Visible = false;
}
private void button12_Click(object sender, EventArgs e)
{
if (setting.getExitConfig())
{
AniWindow a = new AniWindow(this.Handle, 7, 200, this);//从四周向中间隐藏
this.Dispose();
Application.Exit();
}
else
{
Frm_Exit_Dialog frm_Exit = new Frm_Exit_Dialog();
frm_Exit.ShowDialog();
}
}
private void btn_Close_MouseEnter(object sender, EventArgs e)
{
pictureBox17.Visible = true;
btn_Close.Visible = false;
label16.Visible = true;
}
private void button12_MouseLeave(object sender, EventArgs e)
{
pictureBox17.Visible = false;
btn_Close.Visible = true;
label16.Visible = false;
}
private void button11_Click(object sender, EventArgs e)
{
panelTop.Visible = true;
button1.Visible = true;
}
private void button10_Click_1(object sender, EventArgs e)
{
if (Application.OpenForms["frm_Setting"] == null)
{
Frm_Setting frm_Setting = new Frm_Setting();
frm_Setting.Show();
this.Dispose();
this.Close();
}
}
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (Application.OpenForms["frm_About"] == null)
{
Frm_About frm_About = new Frm_About();
frm_About.Show();
}
}
}
}
评论