代碼如下:
創(chuàng)新互聯(lián)建站專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務,包含不限于成都做網(wǎng)站、網(wǎng)站設計、外貿營銷網(wǎng)站建設、鄄城網(wǎng)絡推廣、微信小程序、鄄城網(wǎng)絡營銷、鄄城企業(yè)策劃、鄄城品牌公關、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務,您的肯定,是我們最大的嘉獎;創(chuàng)新互聯(lián)建站為所有大學生創(chuàng)業(yè)者提供鄄城建站搭建服務,24小時服務熱線:18980820575,官方網(wǎng)址:www.cdcxhl.com
/// summary
/// 連接到窗體:通過密碼保護信息找回密碼!
/// /summary
/// param name="sender"/param
/// param name="e"/param
private void lbl_mibao_Click(object sender, EventArgs e)
{
Getbackpwd getbackpwd = new Getbackpwd();
getbackpwd.Show();
}
/// summary
/// 當該窗體加載時從xml文件中讀取用戶信息并加載到combox的Items中
/// /summary
/// param name="sender"/param
/// param name="e"/param
private void Addresslist_Load(object sender, EventArgs e)
{
XmlTextReader reader = new XmlTextReader(@"E:\面向對象--C#練習\通訊錄\address list\address list\user.xml");
while (reader.Read())
{
//if (reader.LocalName.Equals("Name") || reader.LocalName.Equals("Number"))
if (reader.LocalName.Equals("username"))
{
this.cmbUserName.Items.Add(reader.ReadString());
}
//if (reader.LocalName.Equals("Number"))
//{
// this.label2.Text += reader.ReadString() + "\n";\
//}
}
reader.Close();
}
/// summary
/// 保存用戶名到user.xml
/// /summary
//在listcontol上更改SelectedValue時執(zhí)行從數(shù)據(jù)庫讀取密碼的事件
private void cmbUserName_SelectedValueChanged(object sender, EventArgs e)
{
string username = cmbUserName.Text.Trim();
string sql = string.Format("select pwd from Admin where Username='{0}'", username);
try
{
SqlCommand command = new SqlCommand(sql, DBHelper.connection);
DBHelper.connection.Open();
SqlDataReader dataReader = command.ExecuteReader();
while (dataReader.Read())
{
txtpwd.Text = (string)dataReader["pwd"];
checkBoxpwd.Checked = true;
}
}
catch
{
MessageBox.Show("數(shù)據(jù)庫操作出錯!");
}
finally
{
DBHelper.connection.Close();
}
}
/// summary
/// 記住密碼操作
/// /summary
/// param name="sender"/param
/// param name="e"/param
private void checkBoxpwd_Enter(object sender, EventArgs e)
{
bool check = true;
check = checkinput(cmbUserName.Text.Trim());
if ((string)cmbUserName.Text.Trim() == "")
{
MessageBox.Show("請輸入用戶名", "輸入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
cmbUserName.Focus();
}
else
{
if (txtpwd.Text.Trim() == "")
{
MessageBox.Show("請輸入密碼", "輸入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtpwd.Focus();
}
else
{
bool isValidUser = false; // 標識是否為合法用戶
string message = ""; // 如果登錄失敗,顯示的消息提示
// 如果驗證通過,就顯示相應的用戶窗體,并將當前窗體設為不可見
if (ValidateInput())
{
// 調用用戶驗證方法
isValidUser = ValidateUser(cmbUserName.Text, txtpwd.Text, ref message);
// 如果是合法用戶,顯示相應的窗體
if (isValidUser)
{
if (check == true)
{
XmlDocument doc = new XmlDocument();
doc.Load(@"E:\面向對象--C#練習\通訊錄\address list\address list\user.xml");//(@"E:\面向對象--C#練習\通訊錄\address list\address list\user.xml");
XmlElement node = doc.CreateElement("user");
XmlNode xnode = (XmlNode)doc.CreateElement("username");
xnode.InnerText = cmbUserName.Text.Trim();
node.AppendChild(xnode);
doc.DocumentElement.InsertAfter(node, doc.DocumentElement.LastChild);
doc.Save(@"E:\面向對象--C#練習\通訊錄\address list\address list\user.xml");
//doc.Load (@"E:\面向對象--C#練習\通訊錄\address list\address list\user.xml");
}
}
// 如果登錄失敗,顯示相應的消息
else
{
MessageBox.Show(message, "記住密碼失?。?, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
}
/// summary
/// 驗證當前combox中內容是否已經(jīng)存在于xml文件中
/// /summary
/// param name="text"/param
/// returns/returns
private bool checkinput(string text)
{
int count;
bool c = true;
for (count = 0; count cmbUserName.Items.Count;count ++ )
{
if (text ==(string )cmbUserName .Items [count])
{
c=false;
}
}
return c;
}
xml文件內容如下:?xml version="1.0" encoding="utf-8"?
person
user
虛擬機上一般有的會附帶數(shù)據(jù)庫,有的需要另外花錢購置,然后你在虛擬機上創(chuàng)建一個數(shù)據(jù)庫,把你代碼連接數(shù)據(jù)庫的IP等設置,設置到你虛擬機上的地址
Imports?System.Text
Imports?System.Runtime.InteropServices
Public?Class?Form1
'?相關API函數(shù)聲明,注釋掉的這里沒用到,但是也比較常用吧,這些函數(shù)的功能都能搜到。
Private?Declare?Function?FindWindow?Lib?"user32"?Alias?"FindWindowA"?(ByVal?lpClassName?As?String,?ByVal?lpWindowName?As?String)?As?IntPtr
Private?Declare?Function?FindWindowEx?Lib?"user32"?Alias?"FindWindowExA"?(ByVal?hWnd1?As?IntPtr,?ByVal?hWnd2?As?IntPtr,?ByVal?lpsz1?As?String,?ByVal?lpsz2?As?String)?As?IntPtr
Private?Delegate?Function?EnumChildProc(ByVal?hWnd?As?IntPtr,?ByVal?lParam?As?Integer)?As?Boolean
Private?Declare?Function?EnumChildWindows?Lib?"user32.dll"?(ByVal?hWndParent?As?IntPtr,?ByVal?lpEnumFunc?As?EnumChildProc,?ByVal?lParam?As?Integer)?As?Boolean
Private?Declare?Auto?Function?SendMessage?Lib?"User32.dll"?(ByVal?hWnd?As?IntPtr,?ByVal?Msg?As?Integer,?ByVal?wParam?As?Integer,?ByVal?lParam?As?String)?As?Integer
'Private?Declare?Function?CheckDlgButton?Lib?"user32"?Alias?"CheckDLGButtonA"?(ByVal?hDlg?As?IntPtr,?ByVal?nIDButton?As?IntPtr,?ByVal?wCheck?As?Integer)?As?Integer
Private?Declare?Function?GetClassName?Lib?"user32"?Alias?"GetClassNameA"?(ByVal?hWnd?As?IntPtr,?ByVal?lpClassName?As?StringBuilder,?ByVal?nMaxCount?As?Integer)?As?Integer
'Private?Declare?Function?GetWindowThreadProcessId?Lib?"user32"?Alias?"GetWindowThreadProcessId"?(ByVal?hwnd?As?IntPtr,?ByVal?lpdwProcessId?As?Long)?As?Integer
Private?Declare?Auto?Function?GetWindowTextLength?Lib?"user32"?Alias?"GetWindowTextLength"?(ByVal?hwnd?As?IntPtr)?As?Integer
Private?Declare?Function?GetWindowText?Lib?"user32"?Alias?"GetWindowTextA"?(ByVal?hwnd?As?IntPtr,?ByVal?lpString?As?StringBuilder,?ByVal?cch?As?Integer)?As?Integer
'?相關消息定義,也有沒用到的
Const?WM_SETTEXT?=?HC
Const?WM_GETTEXT?=?HD
'Const?WM_SETFOCUS?=?H7
'Const?WM_KILLFOCUS?=?H8
'Const?WM_CLOSE?=?H10
'Const?WM_SYSCOMMAND?=?H112
'Const?SC_CLOSE?=?HF060
'Const?SC_MINIMIZE?=?HF020
Const?BM_GETCHECK?=?HF0
Const?BM_SETCHECK?=?HF1
Const?BM_GETSTATE?=?HF2
Const?BM_SETSTATE?=?HF3
Const?BM_SETSTYLE?=?HF4
Const?BM_CLICK?=?HF5
'Const?BM_GETIMAGE?=?HF6
'Const?BM_SETIMAGE?=?HF7
Const?BST_UNCHECKED?=?O0
Const?BST_CHECKED?=?O1
Const?BST_INDETERMINATE?=?O2
'?儲存窗口句柄
Dim?WindowHandle?As?IntPtr
'?儲存兩個(或者多個)編輯框句柄
Dim?EditHandle?As?New?List(Of?IntPtr)
Dim?EditWindowsText?As?List(Of?String)
'?儲存復選框句柄
Dim?CheckHandle?As?IntPtr?=?0
Private?Sub?Form1_Load(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?MyBase.Load
Button1_Click(sender,?e)
End?Sub
'?EnumChildWindows?回調函數(shù),該函數(shù)名作為API函數(shù)EnumChildWindows?的一個參數(shù)
'?該函數(shù)實現(xiàn)了枚舉各個子窗口,找出編輯框屬性的功能
Public?Function?EnumChildProcC(ByVal?hwnd?As?IntPtr,?ByVal?lParam?As?Integer)?As?Boolean
Dim?dwWindowClass?As?StringBuilder?=?New?StringBuilder(100)
'?獲得某一個句柄的類名
GetClassName(hwnd,?dwWindowClass,?100)
If?dwWindowClass.ToString.Contains("EDIT")?Or?dwWindowClass.ToString.Contains("Edit")?Then?????'?類名包含EDIT的為編輯框
EditHandle.Add(hwnd)????????????????????????'?存儲該句柄
End?If
'?返回?True?一直枚舉完
Return?True
End?Function
Private?Sub?Button1_Click(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?Button1.Click
WindowHandle?=?FindWindow(vbNullString,?"登陸")
If?WindowHandle.ToInt32?=?0?Then
MsgBox("未捕獲到窗口"?+?"登陸")
Return
End?If
'?枚舉所有主窗口的子窗口(控件),枚舉時自動調用回調函數(shù),完成編輯框句柄的獲取
EnumChildWindows(WindowHandle,?AddressOf?EnumChildProcC,?0)
'?尋找復選框
CheckHandle?=?FindWindowEx(WindowHandle,?IntPtr.Zero,?vbNullString,?"記住密碼")
Dim?str?As?New?StringBuilder
Dim?j?As?Integer?=?0
'?對編輯框文本賦值
For?j?=?0?To?EditHandle.Count?-?1
SendMessage(EditHandle(j),?WM_SETTEXT,?0,?"Text")
'GetWindowText(EditHandle(j),?str,?20)
'EditWindowsText.Add(Str.ToString)
'Str.Clear()
Next
If?EditHandle.Count?=?0?Then
MsgBox("未找到輸入框!")
End?If????????
If?CheckHandle.ToInt32??0?Then
'CheckDlgButton(WindowHandle,?id,?1)
'?對復選框進行鼠標單擊操作
SendMessage(CheckHandle,?BM_CLICK,?0,?0)
'SendMessage(CheckHandle,?BM_SETCHECK,?True,?0)
End?If
End?Sub
End?Class
.net 取寬帶賬號和密碼的我沒,如果你想實現(xiàn)撥號和斷網(wǎng)的話 ,我有現(xiàn)成的模塊