導航:首頁 > 軟體知識 > form代碼是用哪個程序編寫

form代碼是用哪個程序編寫

發布時間:2023-07-01 08:03:04

㈠ C# 寫一個winform登錄與注冊的應用程序

登錄就是判斷你輸入的值和資料庫中的值是否相同,而注冊其實就是往資料庫中插入用戶名和密碼,比如注冊代碼如下,導入命名空間using System.Data.SqlClient;
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "server=.;database=資料庫名;uid=用戶名;pwd=密碼;";
string strcmd = "insert into 用戶表 values('" + TextBox1.Text + "','" + TextBox2.Text + "')";
SqlCommand mycommand = new SqlCommand(strcmd, conn);
try
{
conn.Open();
mycommand.ExecuteNonQuery();
MessageBox.Show(" 注冊成功 ");
}
catch
{

MessageBox.Show("注冊發生錯誤");}
finally
{
conn.Close();
}

㈡ 求VS2010 C#FORM編寫強制關機代碼 只要關機的

using System.Runtime.InteropServices; // 提供DllImport等特性,是P/Invoke的關鍵

// 這個結構體將會傳遞給API。使用StructLayout(...特性,確保其中的成員是按順序排列的,C#編譯器不會對其進行調整。

[StructLayout(LayoutKind.Sequential, Pack = 1)]
internal struct TokPriv1Luid
{
public int Count;
public long Luid;
public int Attr;
}

// 以下使用DllImport特性導入了所需的Windows API。

// 導入的方法必須是static extern的,並且沒有方法體。調用這些方法就相當於調用Windows API。

[DllImport("kernel32.dll", ExactSpelling = true)]
internal static extern IntPtr GetCurrentProcess();

[DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok);

[DllImport("advapi32.dll", SetLastError = true)]
internal static extern bool LookupPrivilegeValue(string host, string name, ref long pluid);

[DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall,
ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen);

[DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
internal static extern bool ExitWindowsEx(int flg, int rea);

// 以下定義了在調用WinAPI時需要的常數。這些常數通常可以從Platform SDK的包含文件(頭文件)中找到

internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
internal const int TOKEN_QUERY = 0x00000008;
internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
internal const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
internal const int EWX_LOGOFF = 0x00000000;
internal const int EWX_SHUTDOWN = 0x00000001;
internal const int EWX_REBOOT = 0x00000002;
internal const int EWX_FORCE = 0x00000004;
internal const int EWX_POWEROFF = 0x00000008;
internal const int EWX_FORCEIFHUNG = 0x00000010;

// 通過調用WinAPI實現關機,主要代碼再最後一行ExitWindowsEx,這調用了同名的WinAPI,正好是關機用的。

private static void DoExitWin(int flg)
{
bool ok;
TokPriv1Luid tp;
IntPtr hproc = GetCurrentProcess();
IntPtr htok = IntPtr.Zero;
ok = OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok);
tp.Count = 1;
tp.Luid = 0;
tp.Attr = SE_PRIVILEGE_ENABLED;
ok = LookupPrivilegeValue(null, SE_SHUTDOWN_NAME, ref tp.Luid);
ok = AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero);
ok = ExitWindowsEx(flg, 0);
}

private void button1_Click(object sender, EventArgs e)
{
DoExitWin(EWX_SHUTDOWN);
}

閱讀全文

與form代碼是用哪個程序編寫相關的資料

熱點內容
vivo哪裡管理後台程序 瀏覽:176
傳遞文字信息的動物有哪些 瀏覽:211
快捷交易是哪個支付軟體 瀏覽:917
獨奏騎士數據怎麼刷的 瀏覽:858
dnf游戲信用低於多少不能交易 瀏覽:482
河北邢台菜市場什麼好賣 瀏覽:450
五愛市場怎麼上貨 瀏覽:332
美股交易明細是什麼意思 瀏覽:476
洗衣服都用什麼產品 瀏覽:250
陳程序員和設計師哪個工資高 瀏覽:357
買房後交易需要什麼資料 瀏覽:785
花鳥市場裡面有什麼好吃的 瀏覽:475
專利代理費入什麼科目 瀏覽:542
怎麼才能實時顯示數據 瀏覽:878
如何看自己的公會信息 瀏覽:856
手機代理在什麼地方關閉 瀏覽:905
無錫自愈系精油代理需要什麼條件 瀏覽:515
率土之濱魅族端如何交易 瀏覽:877
數據批發商哪裡找 瀏覽:155
正宇電子產品怎麼樣 瀏覽:189