1.1。
学生向けの別の管理ページ:
Political Appearance LabelコントロールがComboBoxコントロールになった後、右上隅にある小さな三角形をクリックして、内部のアイテムを編集します。
ラベルの後の年齢コントロールは、年齢を加算または減算できるNumericUpDownコントロールです。
Interests and hobbiesはGroupBoxコントロールであり、Textプロパティはinterests and hobbiesに変更され、5つのCheckBoxコントロールがあり、Textプロパティは応答の名前に変更されます。
ボタンをダブルクリックして確認し、コードを記述します。
private void btnOk_Click(object sender, EventArgs e)
{
string no = txtStuNo.Text;
string name = txtName.Text;
string address = txtJG.Text;
string sex;
if (radbtnMan.Checked == true)
{
sex = radbtnMan.Text;
}
else
{
sex = radbtnWoman.Text;
}
string zhengzhi = cboZZ.Text;
string aihao = "";
if (cekRead.Checked== true)
{
aihao = cekRead.Text;
}
if (cekSport.Checked == true)
{
aihao += cekSport.Text;
}
if (cekTravel.Checked == true)
{
aihao += cekTravel.Text;
}
if (cekGame.Checked == true)
{
aihao += cekGame.Text;
}
if (cekAnother.Checked == true)
{
aihao += cekAnother.Text;
}
MessageBox.Show(no + name + address + sex + zhengzhi + aihao);
}
この機能は、次の情報の入力を求めるプロンプトを表示します。
[OK]をクリックします。
終了コードをダブルクリックします。
private void btnClose_Click(object sender, EventArgs e)
{
this.Hide();
}
ページ読み込みの男性がデフォルトで選択されており、ページの周囲をダブルクリックして、コードを入力します。
private void frmInformation_Load(object sender, EventArgs e)
{
radbtnMan.Checked= true;
}
2.2。
クラスページの編集:
DataGridViewデータコントロールを追加し、右上隅にある小さな三角形をクリックして、データベースのテーブルに接続します。
ダブルクリックして更新します。内部のコードは次のとおりです。
private void btnNew_Click(object sender, EventArgs e)
{
try
{
DBhelp.conn.Open();
string sqlstr = string.Format("update tb_Class set ClassName='{0}' where ClassID='{1}'", txtClassName.Text, txtClassID.Text);
DBhelp.comm.CommandText = sqlstr;
DBhelp.comm.Connection = DBhelp.conn;
if ((int)DBhelp.comm.ExecuteNonQuery() > 0)
{
MessageBox.Show("更新成功");
}
else
{
MessageBox.Show("更新失败");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
DBhelp.conn.Close();
}
}
1を2に変更します
ダブルクリックして、中のコードを削除します。
private void btnDelete_Click(object sender, EventArgs e)
{
try
{
DBhelp.conn.Open();
string sqlstr = string.Format("delete from tb_Class where ClassID='{0}'", txtClassID.Text);
DBhelp.comm.CommandText = sqlstr;
DBhelp.comm.Connection = DBhelp.conn;
if ((int)DBhelp.comm.ExecuteNonQuery() > 0)
{
MessageBox.Show("删除成功");
}
else
{
MessageBox.Show("删除失败");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
DBhelp.conn.Close();
}
}
ダブルクリックして閉じ、コード:
private void btnClose_Click(object sender, EventArgs e)
{
this.Hide();
}
下の入力ボックスに表示するデータをクリックするときは、DataGridViewコントロールのCellClickプロパティにクリックイベントを追加し、そのプロパティをダブルクリックする必要があります。
コードは次のように表示されます。
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
txtClassID.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
txtClassName.Text = this.dataGridView1.CurrentRow.Cells[1].Value.ToString();
}
学生情報編集ページ:
2つのGroupBoxグループコントロールには他のコントロールが含まれています。グループコントロールの名前を表示したくない場合は、Textプロパティの内容を削除してください。
ダブルプラスクエリ、内部のコード:
private void btnSelect_Click(object sender, EventArgs e)
{
string conn = "Data Source=.;Initial Catalog=studentInf;Integrated Security=True";
SqlConnection a = new SqlConnection(conn);
try
{
a.Open();
string sqlstr = string.Format("select * from tb_Student where StudentID='{0}'", txtStudentNo.Text);
SqlCommand comm = new SqlCommand();
comm.Connection = a;
comm.CommandText = sqlstr;
SqlDataReader read = comm.ExecuteReader();
if (read.Read())
{
txtStudentID.Text = read[0].ToString();
txtStudentName.Text = read[1].ToString();
txtStudentGender.Text = read[2].ToString();
txtBirthday.Text = read[3].ToString();
txtClassID.Text = read[4].ToString();
txtMobilePhone.Text = read[5].ToString();
txtAddress.Text = read[6].ToString();
}
else
{
MessageBox.Show("学号不存在!");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
a.Close();
}
}
ダブルクリックして変更します。内部のコードは次のとおりです。
private void btnAlter_Click(object sender, EventArgs e)
{
try
{
DBhelp.conn.Open();
string sqlstr = string.Format("update tb_Student set StudentName='{0}',Birthday='{1}',ClassID='{2}',MobilePhone='{3}',Gender='{4}',Address='{5}' where StudentID='{6}'", txtStudentName.Text, txtBirthday.Text, txtClassID.Text, txtMobilePhone.Text, txtStudentGender.Text, txtAddress.Text, txtStudentNo.Text);
DBhelp.comm.CommandText = sqlstr;
DBhelp.comm.Connection = DBhelp.conn;
if ((int)DBhelp.comm.ExecuteNonQuery() > 0)
{
MessageBox.Show("修改成功");
}
else
{
MessageBox.Show("修改失败");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
DBhelp.conn.Close();
}
}
電話を変更します。
ダブルクリックして、中のコードを削除します。
private void btnDelete_Click(object sender, EventArgs e)
{
try
{
DBhelp.conn.Open();
string sqlstr = string.Format("delete from tb_Student where StudentID='{0}'", txtStudentNo.Text);
DBhelp.comm.CommandText = sqlstr;
DBhelp.comm.Connection = DBhelp.conn;
if ((int)DBhelp.comm.ExecuteNonQuery() > 0)
{
MessageBox.Show("删除成功");
}
else
{
MessageBox.Show("删除失败");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
DBhelp.conn.Close();
}
}
ダブルクリックして閉じます。中のコードは次のとおりです。
private void btnClose_Click(object sender, EventArgs e)
{
this.Hide();
}
3.3。
ユーザーのパスワード変更ページ:
ダブルクリックして変更を確認します。コードは次のとおりです。
private void btnOK_Click(object sender, EventArgs e)
{
try
{
DBhelp.conn.Open();
string sqlstr = string.Format("update tb_User set UserName='{0}',UserPasswd='{1}' where UserID='{2}'", txtUserName.Text,txtUserPasswd.Text, txtUserID.Text);
DBhelp.comm.CommandText = sqlstr;
DBhelp.comm.Connection = DBhelp.conn;
if ((int)DBhelp.comm.ExecuteNonQuery() > 0)
{
MessageBox.Show("修改成功");
}
else
{
MessageBox.Show("修改失败");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
DBhelp.conn.Close();
}
}
4.4。
ホームページ:
GroupBoxコントロールは、コントロールのグループを論理的にグループ化するためによく使用されます。コンテナ パネルコントロール:パーティション分割にも使用されます。
TabControlコントロール:マルチタブ、マルチパーティションコントロールプロパティTabPagesは複数のメンバーを追加できます
RadioButton:無線制御はrbtnで始まります
RadioButtonのプロパティ:
- テキスト:コントロールに表示するテキスト
- チェック済み:このプロパティは、RadioButtonのチェック済み状態を読み取りまたは変更するために読み取りまたは設定できます。
チェックボックス:複数選択コントロール
- プロパティとイベント:
- テキストプロパティ
- チェックされたプロパティ
- CheckedChangedイベント
ComboBoxコントロール:ユーザーは、コントロールにリストされているオプション、アイテム編集アイテム、ドロップダウンボックスオプションを選択します
NumericUpDownコントロール:数値選択コントロール(NumericUpDownコントロール)は、数値を表示および入力するためのコントロールです。コントロールには上下の矢印のペアがあり、ユーザーは上下の矢印をクリックして値を選択するか、直接入力することができます
ListBoxコントロール:リストコントロールは、ユーザーが1つ以上のアイテムを選択できるリストを表示するために使用されます。オプションの総数が表示可能なアイテムの数を超えると、コントロールは自動的にスクロールバーを追加します
Tablcontrol:ページングオプション
メニューバーのコントロール:MenuStripはmusにちなんで名付けられています
プロジェクト名はtsmで始まりますプロジェクト内のプロジェクトの名前はtsmiです
ツールバーコントロール:ToolStripアイテムは、プロパティDisplayStyleを変更するための画像とテキストを表示します。ツールバー:tstで開始
ステータスバーコントロール:StatusStrip、ステータスバー:tssの名前で始まります
最初にメニューバーコントロールMenuStripを追加します:アイテムを追加します
別のツールバーコントロールを追加します。ToolStrip:アイテムを追加します。
ボタンを選択すると、表示されるフォントが設定されます。
ステータスバーコントロール:StatusStrip、次から選択できます:
TreeViewコントロールを追加して、階層情報を表示します
ノードを編集するには、右上の小さな三角形をクリックします
別のDataGridViewコントロールを追加します。データベース内のテーブルを表示します。
右上隅にある小さな三角形をクリックします。
データベース内のテーブル:
..。