C#窗體的重要屬性

1. 窗體與控件

窗體的重要屬性

屬性

說明

Name

窗體對象的名字,用於在代碼中進行標示

BackColor

窗體的背景色

BackgroundImage

窗體的背景圖像

FormBorderStyle

窗體的邊框樣式,7個可選的值,默認是Sizable

MaximizeBox

確定窗體標題欄的右上角是否有最大化

ShowInTaskbar

確定窗體是否出現在Windows任務欄中

StartPosition

確定窗體第一次出現的位置

Text

窗體標題欄中顯示的文本

TopMost

只是窗體是否始終顯示在此屬性爲TRUE的所有窗體之上,默認爲False

WindowState

確定窗體的初始化狀態,包括Normal(普通),Maximized(最大化),Minimized(最小化)

IsMiContatiner

設定窗體是否爲父窗體

:

子窗體.Mdiparent = this;

在菜單空間的MdiWindowListItem屬性爲窗口菜單項

事件

Load

窗體加載事件

MouseClick

鼠標單擊事件

MouseDoubleClick

鼠標雙擊事件

MouseMove

鼠標移動事件

KeyDown

鍵盤按下事件

KeyUp

鍵盤釋放事件

控件命名規範以及一般用法

控件名

簡寫(前綴)

用途及說明說明

Label

lbl

TextBox

txt

Button

btn

LinkButton

inkbtn

ImageButton

imgbtn

ListBox

lst

DropDownList

ddl

DateGrid

dg

DataList

dl

CheckBox

chk

CheckBoxList

chklst

RadioButton

rdo

RadioButtonList

rdolst

Image

img

Panel

pnl

Calender

cal

AdRotator

ar

Table

tab

RequiredFieldValidator

rfv

CompareValidator

cv

RangeValidator

rv

RegularExpressionValidator

rev

ValidatorSummar

vs

CrystalReportViewer

rptvew

ComboBox

cbo

使用數據集直接填充下拉列表

cbo.DisplayMember = ds.Tables[].Columns[];

cbo.ValueMember = ds.Tables[].Columns[];

comboBox1.DataSource = ds.Tables[];

:

DisplayMember在下列表中的顯示

ValueMembercbo.SelectedValue(相當與Tag)

DataGridView

dgv

使用它只要在代碼中添加它的數據源就OK

控件名.DataSource = 數據集中的表;

dgv.SelectRows[0].Cell[列名].Value

:

SelectRows[0]表示選中的第一行

Cell[列名]列的單元格

Value單元格中的值

DataGridViewColumn

col

GroupBox

grp

ImageList

il

ListView

lv

ListViewItem lv = new ListViewItem(第1行第1列);

lv.Tag = 第1行第1列;

listView.Items.Add(lv);

lv.SubItems.AddRange(new string[] {子項});

ListViewColumnHeader

col

MenuStrip

ms

ToolStripMenuItem

tsmi

PictureBox

pic

StatusStrip

ss

StatusLabel

slbl

TabControl

tab

Tabpage

tp

Timer

tmr

ToolStrip

ts

ToolStripLabel

tslbl

ToolStripDropDownButton

tsddb

DomainUpDown

dud

TreeView

tv  tvw

WebBrowser

wb

ObjectDataSource

ods

FileUpload

ful

HiddenField

hf

GridView

gv

PagedDataSource

pds

Repeater

rpt

contextMenuStrip

cms

選擇使用右鍵控件屬性中的contextMenuStrip屬性

2. ADO.NET的使用

.NET Framework

NET Framework數據提供程序是專美爲數據處理以及快速地只進,制度訪問數據而設計的組建.使用它,我們可以連接到數據庫,執行命令和檢索結果,直到對數據庫進行操作

ü .NET Framework數據提供程序的四個核心對象

對象

說明

使用方法

Connection

建立與特定數據源的連接

1. 定義連接字符串

string connstring = string.Format(連接字符串);

2. 創建Connection對象

SqlConnection con new SqlConnection(connstring);

:

con.Open()打開數據庫

con.Close()關閉數據庫

Command

對數據源執行命令

創建Command對象

SqlCommand com = new SqlCommand(sql,con);

:

sql查詢用SQL語句

屬性

說明

Connection

使用的數據庫連接,同上 con

CommandText

執行SQL語句

方法

說明

ExecuteNonQuery();

返回受影響的行數

ExecuteReader()

屬性

逐行讀取數據

HasRows

:是否返回結果

FieldCount

:當前行中列數

方法

Read

:前進下一行記錄

Close

:關閉對象

ExecuteScalar();

返回第一行第一列

DataReader

從數據源中讀取只進且只讀的數據流

SqlCommand com = new SqlCommand(sql, DBHelp.con);

SqlDataReader dr = com.ExecuteReader();

DataAdapter

用數據源填充DataSet並解析更新

DataSet ds = new DataSet();

SqlDataAdapter da = new SqlDataAdapter(sql,DBHelp.con);

da.Fill(ds,"用戶表");//填充數據集

控件名.DataSource = ds.Tables[0];//指定數據源

SqlCommandBuilder cb = new SqlCommandBuilder(da);

da.Update(ds,"用戶表");

發佈了1 篇原創文章 · 獲贊 12 · 訪問量 17萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章