http://stackoverflow.com/questions/937573/changing-the-useragent-of-the-webbrowser-control-winforms-c
public class ExtendedWebBrowser : WebBrowser
{
bool renavigating = false;
public string UserAgent { get; set; }
public ExtendedWebBrowser()
{
DocumentCompleted += SetupBrowser;
//this will cause SetupBrowser to run (we need a document object)
Navigate("about:blank");
}
void SetupBrowser(object sender, WebBrowserDocumentCompletedEventArgs e)
{
DocumentCompleted -= SetupBrowser;
SHDocVw.WebBrowser xBrowser = (SHDocVw.WebBrowser)ActiveXInstance;
xBrowser.BeforeNavigate2 += BeforeNavigate;
DocumentCompleted += PageLoaded;
}
void PageLoaded(object sender, WebBrowserDocumentCompletedEventArgs e)
{
}
void BeforeNavigate(object pDisp, ref object url, ref object flags, ref object targetFrameName,
ref object postData, ref object headers, ref bool cancel)
{
if (!string.IsNullOrEmpty(UserAgent))
{
if (!renavigating)
{
headers += string.Format("User-Agent: {0}\r\n", UserAgent);
renavigating = true;
cancel = true;
Navigate((string)url, (string)targetFrameName, (byte[])postData, (string)headers);
}
else
{
renavigating = false;
}
}
}
}
Note: To use the method above you’ll need to add a COM reference to “Microsoft Internet Controls”.
Sunday, May 16, 2010
Saturday, December 12, 2009
email address
IMAP
http://www.fastmail.fm/
* Server: mail.messagingengine.com
* Port: 143 (or SSL IMAP port 993)
* Username: your FastMail.FM username/login name/email address (must include @fastmail.fm part)
* Password: your FastMail.FM password
* Root folder/path: INBOX
* Folder separator: . (period)
no pop,no IMAP access
http://secure.zapak.com/mail/zapakmail.php
http://www.fastmail.fm/
* Server: mail.messagingengine.com
* Port: 143 (or SSL IMAP port 993)
* Username: your FastMail.FM username/login name/email address (must include @fastmail.fm part)
* Password: your FastMail.FM password
* Root folder/path: INBOX
* Folder separator: . (period)
no pop,no IMAP access
http://secure.zapak.com/mail/zapakmail.php
Monday, December 7, 2009
C#调用其他的应用程序
System.Diagnostics.Process.Start("notepad.exe","c:\\readme.txt");
//最小化方式启动
Info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Minimized;
//最小化方式启动
Info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Minimized;
Saturday, December 5, 2009
c# 窗体最小化到托盘
转:http://www.cnblogs.com/qfb620/archive/2009/10/22/1587971.html
c# winform最小化到托盘,也就是最小化到右下角,其实很简单,winform中有专门的控件。
下面是完整的代码,没太多需要解释的。
先在winform中添加notifyIcon控件,然后激活相应事件,添加代码。因为屏蔽了关闭窗体事件,可以设定一个全局变量bool变量来分辨是哪里引起的close事件。
注意添加Form的SizeChanged事件和NotifyIcon控件的DoubleClick事件
//全家变量bool closeTag = true;
//最小化
private void form1_Resize(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
NormalToMinimized();
}
}
//close时最小化
private void form1_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
NormalToMinimized();
}
//单击显示窗体
private void notifyIcon_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.MinimizedToNormal();
}
}
private void MinimizedToNormal()
{
this.Visible = true;
this.WindowState = FormWindowState.Normal;
notifyIcon.Visible = false;
}
private void NormalToMinimized()
{
this.WindowState = FormWindowState.Minimized;
this.Visible = false;
this.notifyIcon.Visible = true;
}
private void frmMain_FormClosing(object sender, FormClosingEventHandler e)
{
if (closeTag)
{
e.Cancel = true;
NormalToMinimized();
}
}
//托盘右键关闭事件
private void 退出XToolStripMenuItem_Click(object sender, EventArgs e)
{
closeTag = false;
Application.Exit();
}
c# winform最小化到托盘,也就是最小化到右下角,其实很简单,winform中有专门的控件。
下面是完整的代码,没太多需要解释的。
先在winform中添加notifyIcon控件,然后激活相应事件,添加代码。因为屏蔽了关闭窗体事件,可以设定一个全局变量bool变量来分辨是哪里引起的close事件。
注意添加Form的SizeChanged事件和NotifyIcon控件的DoubleClick事件
//全家变量bool closeTag = true;
//最小化
private void form1_Resize(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
NormalToMinimized();
}
}
//close时最小化
private void form1_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
NormalToMinimized();
}
//单击显示窗体
private void notifyIcon_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.MinimizedToNormal();
}
}
private void MinimizedToNormal()
{
this.Visible = true;
this.WindowState = FormWindowState.Normal;
notifyIcon.Visible = false;
}
private void NormalToMinimized()
{
this.WindowState = FormWindowState.Minimized;
this.Visible = false;
this.notifyIcon.Visible = true;
}
private void frmMain_FormClosing(object sender, FormClosingEventHandler e)
{
if (closeTag)
{
e.Cancel = true;
NormalToMinimized();
}
}
//托盘右键关闭事件
private void 退出XToolStripMenuItem_Click(object sender, EventArgs e)
{
closeTag = false;
Application.Exit();
}
怎样保证一个窗体始终是处在最顶层的
[C#]
public bool TopMost {get; set;}
属性值
如果为 true,则将窗体显示为最顶层窗体;否则,为 false。默认为 false。
TopMost只是设置窗口为本程序的最顶层窗口。
而不是系统的,要设置系统的,可以用API:setwindowspos:
[DllImport("user32.dll")]
private static extern int SetWindowPos (int hwnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags);
//int x:窗口新的x坐标。如hwnd是一个子窗口,则x用父窗口的客户区坐标表示
//int y:窗口新的y坐标。如hwnd是一个子窗口,则y用父窗口的客户区坐标表示
//int cx:指定新的窗口宽度
//int cy:指定新的窗口高度
private const int HWND_TOPMOST = -1;
private const int SWP_SHOWWINDOW = 0x40;
SetWindowPos(this.Handle, HWND_TOPMOST, 0, 0, 500, 500, 0x40);
public bool TopMost {get; set;}
属性值
如果为 true,则将窗体显示为最顶层窗体;否则,为 false。默认为 false。
TopMost只是设置窗口为本程序的最顶层窗口。
而不是系统的,要设置系统的,可以用API:setwindowspos:
[DllImport("user32.dll")]
private static extern int SetWindowPos (int hwnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags);
//int x:窗口新的x坐标。如hwnd是一个子窗口,则x用父窗口的客户区坐标表示
//int y:窗口新的y坐标。如hwnd是一个子窗口,则y用父窗口的客户区坐标表示
//int cx:指定新的窗口宽度
//int cy:指定新的窗口高度
private const int HWND_TOPMOST = -1;
private const int SWP_SHOWWINDOW = 0x40;
SetWindowPos(this.Handle, HWND_TOPMOST, 0, 0, 500, 500, 0x40);
Form in corner of screen
Location = new Point(Screen.PrimaryScreen.WorkingArea.Right - Width,
Screen.PrimaryScreen.WorkingArea.Bottom - Height);
Screen.PrimaryScreen.WorkingArea.Bottom - Height);
Tuesday, December 1, 2009
C#连接MySQL数据库方法
转:http://kinghongchen.blog.163.com/blog/static/71647228200871114425689/
1、用MySQLDriverCS连接MySQL数据库
先下载和安装MySQLDriverCS,地址:
http://sourceforge.net/projects/mysqldrivercs
在安装文件夹下面找到MySQLDriver.dll,然后将MySQLDriver.dll添加引用到项目中
注:我下载的是版本是 MySQLDriverCS-n-EasyQueryTools-4.0.1-DotNet2.0.exe
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Odbc;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySQLDriverCS;
namespace mysql
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
MySQLConnection conn = null;
conn = new MySQLConnection(new MySQLConnectionString("localhost", "inv", "root", "831025").AsString);
conn.Open();
MySQLCommand commn = new MySQLCommand("set names gb2312", conn);
commn.ExecuteNonQuery();
string sql = "select * from exchange ";
MySQLDataAdapter mda = new MySQLDataAdapter(sql, conn);
DataSet ds = new DataSet();
mda.Fill(ds, "table1");
this.dataGrid1.DataSource = ds.Tables["table1"];
conn.Close();
}
}
}
2、通过ODBC访问mysql数据库:
参考:http://www.microsoft.com/china/community/Column/63.mspx
1. 安装Microsoft ODBC.net:我安装的是mysql-connector-odbc-3.51.22-win32.msi
2. 安装MDAC 2.7或者更高版本:我安装的是mdac_typ.exe 2.7简体中文版
3. 安装MySQL的ODBC驱动程序:我安装的是 odbc_net.msi
4. 管理工具 -> 数据源ODBC –>配置DSN…
5. 解决方案管理中添加引用 Microsoft.Data.Odbc.dll(1.0.3300)
6. 代码中增加引用 using Microsoft.Data.Odbc;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq; //vs2005好像没有这个命名空间,在c#2008下测试自动生成的
using System.Text;
using System.Windows.Forms;
using Microsoft.Data.Odbc;
namespace mysql
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" +
"SERVER=localhost;" +
"DATABASE=inv;" +
"UID=root;" +
"PASSWORD=831025;" +
"OPTION=3";
OdbcConnection MyConnection = new OdbcConnection(MyConString);
MyConnection.Open();
Console.WriteLine("\n success, connected successfully !\n");
string query = "insert into test values( 'hello', 'lucas', 'liu')";
OdbcCommand cmd = new OdbcCommand(query, MyConnection);
//处理异常:插入重复记录有异常
try{
cmd.ExecuteNonQuery();
}
catch(Exception ex){
Console.WriteLine("record duplicate.");
}finally{
cmd.Dispose();
}
//***********************用read方法读数据到textbox**********************
string tmp1 = null;
string tmp2 = null;
string tmp3 = null;
query = "select * from test ";
OdbcCommand cmd2 = new OdbcCommand(query, MyConnection);
OdbcDataReader reader = cmd2.ExecuteReader();
while (reader.Read())
{
tmp1 = reader[0].ToString();
tmp2 = reader[1].ToString();
tmp3 = reader[2].ToString();
}
this.textBox1.Text = tmp1 + " " + tmp2 + " " + tmp3;
*/
//************************用datagridview控件显示数据表**************************
string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" +
"SERVER=localhost;" +
"DATABASE=inv;" +
"UID=root;" +
"PASSWORD=831025;" +
"OPTION=3";
OdbcConnection MyConnection = new OdbcConnection(MyConString);
OdbcDataAdapter oda = new OdbcDataAdapter("select * from customer ", MyConnection);
DataSet ds = new DataSet();
oda.Fill(ds, "employee");
this.dataGridView1.DataSource = ds.Tables["employee"];
*/
MyConnection.Close();
}
}
}
1、用MySQLDriverCS连接MySQL数据库
先下载和安装MySQLDriverCS,地址:
http://sourceforge.net/projects/mysqldrivercs
在安装文件夹下面找到MySQLDriver.dll,然后将MySQLDriver.dll添加引用到项目中
注:我下载的是版本是 MySQLDriverCS-n-EasyQueryTools-4.0.1-DotNet2.0.exe
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Odbc;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySQLDriverCS;
namespace mysql
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
MySQLConnection conn = null;
conn = new MySQLConnection(new MySQLConnectionString("localhost", "inv", "root", "831025").AsString);
conn.Open();
MySQLCommand commn = new MySQLCommand("set names gb2312", conn);
commn.ExecuteNonQuery();
string sql = "select * from exchange ";
MySQLDataAdapter mda = new MySQLDataAdapter(sql, conn);
DataSet ds = new DataSet();
mda.Fill(ds, "table1");
this.dataGrid1.DataSource = ds.Tables["table1"];
conn.Close();
}
}
}
2、通过ODBC访问mysql数据库:
参考:http://www.microsoft.com/china/community/Column/63.mspx
1. 安装Microsoft ODBC.net:我安装的是mysql-connector-odbc-3.51.22-win32.msi
2. 安装MDAC 2.7或者更高版本:我安装的是mdac_typ.exe 2.7简体中文版
3. 安装MySQL的ODBC驱动程序:我安装的是 odbc_net.msi
4. 管理工具 -> 数据源ODBC –>配置DSN…
5. 解决方案管理中添加引用 Microsoft.Data.Odbc.dll(1.0.3300)
6. 代码中增加引用 using Microsoft.Data.Odbc;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq; //vs2005好像没有这个命名空间,在c#2008下测试自动生成的
using System.Text;
using System.Windows.Forms;
using Microsoft.Data.Odbc;
namespace mysql
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" +
"SERVER=localhost;" +
"DATABASE=inv;" +
"UID=root;" +
"PASSWORD=831025;" +
"OPTION=3";
OdbcConnection MyConnection = new OdbcConnection(MyConString);
MyConnection.Open();
Console.WriteLine("\n success, connected successfully !\n");
string query = "insert into test values( 'hello', 'lucas', 'liu')";
OdbcCommand cmd = new OdbcCommand(query, MyConnection);
//处理异常:插入重复记录有异常
try{
cmd.ExecuteNonQuery();
}
catch(Exception ex){
Console.WriteLine("record duplicate.");
}finally{
cmd.Dispose();
}
//***********************用read方法读数据到textbox**********************
string tmp1 = null;
string tmp2 = null;
string tmp3 = null;
query = "select * from test ";
OdbcCommand cmd2 = new OdbcCommand(query, MyConnection);
OdbcDataReader reader = cmd2.ExecuteReader();
while (reader.Read())
{
tmp1 = reader[0].ToString();
tmp2 = reader[1].ToString();
tmp3 = reader[2].ToString();
}
this.textBox1.Text = tmp1 + " " + tmp2 + " " + tmp3;
*/
//************************用datagridview控件显示数据表**************************
string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" +
"SERVER=localhost;" +
"DATABASE=inv;" +
"UID=root;" +
"PASSWORD=831025;" +
"OPTION=3";
OdbcConnection MyConnection = new OdbcConnection(MyConString);
OdbcDataAdapter oda = new OdbcDataAdapter("select * from customer ", MyConnection);
DataSet ds = new DataSet();
oda.Fill(ds, "employee");
this.dataGridView1.DataSource = ds.Tables["employee"];
*/
MyConnection.Close();
}
}
}
Subscribe to:
Posts (Atom)