新聞中心
vb.net /c# winform窗體小程序,問題my.settings不能使用。
很有可能開發(fā)者寫的是電腦的絕對路徑,而這個絕對路徑在客戶電腦上這個文件不存在的;
成都創(chuàng)新互聯(lián)擁有一支富有激情的企業(yè)網(wǎng)站制作團隊,在互聯(lián)網(wǎng)網(wǎng)站建設(shè)行業(yè)深耕十年,專業(yè)且經(jīng)驗豐富。十年網(wǎng)站優(yōu)化營銷經(jīng)驗,我們已為上1000+中小企業(yè)提供了成都網(wǎng)站設(shè)計、網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)解決方案,專業(yè)公司,設(shè)計滿意,售后服務(wù)無憂。所有客戶皆提供一年免費網(wǎng)站維護!
其實開發(fā)者可以判斷路徑和文件是否存在,如果不存在則創(chuàng)建這個文件的。
這是個Bug
VB.net 如何實現(xiàn)記住密碼 自動登錄
代碼如下:
/// 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:\面向?qū)ο?-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 = ""; // 如果登錄失敗,顯示的消息提示
// 如果驗證通過,就顯示相應(yīng)的用戶窗體,并將當前窗體設(shè)為不可見
if (ValidateInput())
{
// 調(diào)用用戶驗證方法
isValidUser = ValidateUser(cmbUserName.Text, txtpwd.Text, ref message);
// 如果是合法用戶,顯示相應(yīng)的窗體
if (isValidUser)
{
if (check == true)
{
XmlDocument doc = new XmlDocument();
doc.Load(@"E:\面向?qū)ο?-C#練習\通訊錄\address list\address list\user.xml");//(@"E:\面向?qū)ο?-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:\面向?qū)ο?-C#練習\通訊錄\address list\address list\user.xml");
//doc.Load (@"E:\面向?qū)ο?-C#練習\通訊錄\address list\address list\user.xml");
}
}
// 如果登錄失敗,顯示相應(yīng)的消息
else
{
MessageBox.Show(message, "記住密碼失敗!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
}
/// summary
/// 驗證當前combox中內(nèi)容是否已經(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文件內(nèi)容如下:?xml version="1.0" encoding="utf-8"?
person
user
如何用VB.NET制作賬號自動登陸的程序
Private Sub SendBlogTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendBlogTimer.Tick
Dim textboxUserId As HtmlElement
Dim textboxPassword As HtmlElement
Dim buttonSubmit As HtmlElement
textboxUserId = SendBlogBrowser.Document.All("username")'獲取用戶名輸入框
textboxPassword = SendBlogBrowser.Document.All("password")'獲取密碼輸入框
buttonSubmit = SendBlogBrowser.Document.All("btnLogin")'獲取登陸按鈕
textboxUserId.SetAttribute("value","用戶名")'給用戶名輸入框賦值
textboxPassword.SetAttribute("value","密碼")'給密碼框賦值
buttonSubmit.InvokeMember("click")’執(zhí)行登陸按鈕的單擊
End Sub
其中的SendBlogBrowser為WebBrowser控件
當前文章:vb.net記住賬戶的簡單介紹
文章路徑:http://www.ef60e0e.cn/article/docoepc.html