標籤:index ons 菜單 .exe 表單 調整 item isp size
一.Application.Exit()和this.Close()的區別
Application.Exit()
1.應用程式類Application的靜態方法,用於退出當前應用程式
2.如果當前應用程式開啟了多個表單,則關閉所有表單
3.當關閉表單時,不會觸發表單的FromClising和FormClosed事件
this.Close()
1.執行個體方法,用於關閉當前表單,如果當前表單為系統啟動的表單,則執行該方法表單關閉後,整個應用程式退出
2.如果當前應用程式開啟了多個表單,則只關閉當前表單
3.當前表單關閉時,會觸發表單的FromClising和FormClosed事件
二.ToolStrip和MenuStrip控制項
2.1 菜單控制項的主要屬性
Name 代碼中菜單對象的名稱
Items 在菜單中顯示項目的集合
Text 與功能表項目關聯的文本
2.2 功能表項目的主要屬性和事件
Name 代碼中功能表項目對象的,形成
DropDownItems 在子功能表中顯示的項的集合
Text 與功能表項目相關聯的文本
Click 選中該功能表項目時,觸發該事件
2.3 工具列中的主要屬性
ImageScalingSize 工具列中的項顯示的映像的大小
Items 在工具列上顯示的項的集合
2.4 工具列上的按鈕和標籤的主要屬性和時間
DispalyStyle 設定映像和文本的顯示方式,包括顯示文本,顯示映像,顯示映像和文本或者什麼都不顯示
Image 按鈕/標籤上顯示的圖片
ImageScaling 是否調整按鈕.標籤上顯示圖片的大小
Text 按鈕/標籤上顯示的文本
TextImageRelation 按鈕.標籤像與文本的相對位置
Click 當單擊按鈕.標籤時觸發該事件
三.控制項相片順序
Anchor
Dock
四.設定MDI表單
1.父表單的 IsMDIContainer 屬性設為true
2.子表單的 MdiParent 屬性設為父表單
ChildForm childForm = new ChildForm();
childForm.MdiParent = this;
childForm.Show();
五.綁定下拉框資料
//在表單Show()之前執行的方法
private void FrmEditStudent_Load(object sender, EventArgs e)
{
//1.建立資料庫連接字串
string constr = "Data Source=.;Initial Catalog=SchoolDB;User=sa;Pwd=.";
//2.建立連線物件Connection
SqlConnection con = new SqlConnection(constr);
try
{
//3.開啟資料庫連接
con.Open();
//4.建立SQL
string sql = "select * from Grade";
//5.建立Command對象發送請求
SqlCommand cmd = new SqlCommand(sql,con);
SqlDataReader dr=cmd.ExecuteReader();
if (dr.HasRows) {
while (dr.Read()) {
//怎麼綁定到下拉框當中
this.cbograde.Items.Add(dr["GradeName"]);
}
}
}
catch (Exception x)
{
MessageBox.Show(x.ToString());
}
finally {
con.Close();
}
//預設選中第一項
this.cbograde.SelectedIndex = 0;
}
構建布局良好的Windows程式