C# 機房合作程式碼塊
阿新 • • 發佈:2019-01-05
一、dataGridView
1.右鍵出快捷選單
if (e.Button == MouseButtons.Right) { if (e.RowIndex >= 0) { //若行已是選中狀態就不再進行設定 if (DGVInfo.Rows[e.RowIndex].Selected == false) { DGVInfo.ClearSelection(); DGVInfo.Rows[e.RowIndex].Selected = true; } //只選中一行時設定活動單元格 if (DGVInfo.SelectedRows.Count == 1) { DGVInfo.CurrentCell = DGVInfo.Rows[e.RowIndex].Cells[e.ColumnIndex]; } //彈出操作選單 contextMenuStrip2.Show(MousePosition.X, MousePosition.Y); } }
2.datagridview怎麼操作完之後重新整理
DGVInfo.DataSource = dt;
DGVInfo.Refresh();
二、介面
1.messbox
選擇是否執行對話方塊
if (MessageBox.Show("您確定要退出系統嗎?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{}
2.點選一個按鈕執行另一個按鈕
btnOffLine_Click(sender,e);
3.清空Text文字
foreach (Control Ctrol in this.Controls)
{
if (Ctrol is TextBox)
{
Ctrol.Text = "";
}
}
4.PasswordChar 為0
txt_Password.PasswordChar = '\0';
5. 控制元件隨窗體變大
this.WindowState = FormWindowState.Maximized; panel1.Width = this.Width; ```