winform窗体 小程序【登录窗体】【恶搞程序】
登录窗体
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Text; namespace WindowsFormsApplication2.App_Code { public class UserData { SqlConnection conn = null; SqlCommand cmd = null; public UserData() { conn = new SqlConnection("server=.;database=Data0216;user=sa;pwd=123"); cmd = conn.CreateCommand(); } public bool HasUser(string uname, string pwd) { bool has = false; cmd.CommandText = "select *from Users where UserName = @a and PassWord = @b"; cmd.Parameters.Clear(); cmd.Parameters.Add("@a", uname); cmd.Parameters.Add("@b", pwd); conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { has = true; } conn.Close(); return has; } } }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using WindowsFormsApplication2.App_Code; namespace WindowsFormsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { if (new UserData().HasUser(textBox1.Text, textBox2.Text)) MessageBox.Show("登录成功!"); else MessageBox.Show("失败!!!"); } } }
恶搞程序
步骤
1、启动最大化 -- WindowState : Maximized
2、去边框 -- FormBorderStyle : none
3、置顶(最高层级) -- TopMost : true
4、不在任务栏显示 -- ShowInTaskbar : false
5、不在任务管理器中显示 -- Text 变为空
6-1、背景无图片,设置透明度为 1%
-- Opacity : 1%
6-2、背景有图片,屏蔽 alt + f4 屏蔽 win键
屏蔽之前先设置退出的快捷键
MenuStrip --菜单栏
在菜单栏按钮中设置 this Close(); -- 退出
在按钮的 ShortcutKeys 属性中 设置 快捷键
MenuStrip 的属性 Visible : false -- 是否可见