问题一:密码确认。好比一个注册表。密码和密码确认填完后如果密码确认和密码不一致的话不可以进行下边的操作。求例题代码。问题二:好比QQ登录器,如果你以前登录过,那他那个文本框里就会有存。然后你输入开头的几个,他就会直接吧以前你登录过的列出来求例题代码。问题三:我想让窗口启动后上边某个按钮上的字体循环变换颜色不停止。...是按钮不是图片框求解问题四:用哪个按钮可以点击后出来一个比如另存为那样的对话框?。。求解。。
解决方案 »
- C#绑定事件问题
- 在C#中使用反射执行另一个C#的exe文件问题
- aspnetmvc1-rc2 跟ASPNetExtMVC2008.exe 是一个组件吗
- 菜鸟求教:杀QQ游戏进程问题
- C#如何导入CSV文件?
- 根据Session状态不的不同iframe中src跳转不同的页面!
- 用过Infragistics NetAdvantage 2005 Volume 这个.NET控件既高手进来一下
- c#中如何异步触发对象的事件?
- 怎么样把窗体编译成dll并在另一个主窗体中调用?
- 在线等:谁熟悉用C#做RSA和DES加密的?
- 急求 多个结构体信息的归并问题~~~
- C#中DataGridView控件和数据库的问题
2、登录验证通过(登录成功),保存用户名到一个文件(txt,xml,注册表)都可以,窗口加载,读取文件中的用户名,供用户选择就可以了
3、timer 很容易搞定
4、系统有保存文件对话框,和 打开文件对话框最后:建议楼主还是多看看书
目前你问题四是可以解决用SaveFileDialog
当然你也可以用其他方式,例如XML,反序列化等
请研究使用ComboBox的AutoCompleteMode,AutoCompleteSource,AutoCompleteCustomerSource属性
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;namespace WindowsFormsApplication7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 登陆单击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
Login();
}
/// <summary>
/// 登陆
/// </summary>
private void Login()
{
//获得用户输入的用户名
String name = this.cboName.Text;
//储存数据库中的密码
String paw = null;
bool isExists = false;
//创建查询语句
String sql = String.Format("select uPass from dbo.TBL_User where uName = '{0}'", name);
SqlConnection con = null;
SqlDataReader dr = null;
try
{
//创建连接
con = new SqlConnection("Data Source=.;Initial Catalog=XX;Integrated Security=True");
//打开数据库
con.Open();
//创建sqlcommand对象
SqlCommand com = new SqlCommand(sql, con);
dr = com.ExecuteReader();
if (dr.Read())
{
paw = dr["uPass"].ToString();
isExists = true;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
dr.Close();
con.Close();
}
if (isExists)
{
if (this.txtPaw.Text == paw)
{
MessageBox.Show("登陆成功!");
//登陆成功保存登陆信息
SaveName();
}
else
{
MessageBox.Show("密码错误!");
}
}
else
{
MessageBox.Show("用户名有误!");
}
}
/// <summary>
/// 保存登陆成功的用户名称
/// </summary>
private void SaveName()
{
try
{
FileStream fs = new FileStream("config.text", FileMode.Open);
StreamWriter sw = new StreamWriter(fs,Encoding.UTF8);
foreach (String item in this.cboName.Items)
{
sw.WriteLine(item);
}
sw.WriteLine(this.cboName.Text);
sw.Close();
fs.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
} }
/// <summary>
/// 读取登陆信息
/// </summary>
private void ReadName()
{
try
{
FileStream fs = new FileStream("config.text", FileMode.Open);
StreamReader sw = new StreamReader(fs, Encoding.UTF8);
while (!sw.EndOfStream)
{
this.cboName.Items.Add(sw.ReadLine());
}
sw.Close();
fs.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
/// <summary>
/// 加载登陆信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_Load(object sender, EventArgs e)
{
ReadName();
//最后一次登陆的人
this.cboName.SelectedIndex = this.cboName.Items.Count - 1;
}
/// <summary>
/// button变色
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer1_Tick(object sender, EventArgs e)
{
int r = 0,g=0,b=0; Random rd = new Random();
r =rd.Next(0,255);
g = rd.Next(0, 255);
b = rd.Next(0, 255);
this.button1.ForeColor = Color.FromArgb(r, g, b);
}
/// <summary>
///
/// 另存为.....
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.ShowDialog();
} }
}
四个问题都解决了,唯一没解决的就是那个按下键盘就弹出对应的值这个貌似ComBoBox没这么强大--!别的方法倒是有~懒的写将就下
进行判断是否合乎要求来显示ComBox里的值
我也想到过,但是你在输入的时候如何弹出下拉表!像QQ那种登陆方法comboBox貌似实现不了!不知道这位兄弟能搞定不?