一、TCheckBox
使CheckBox選中CheckBox1.Checked := True;選擇發生變化 ,OnClick事件
if CheckBox1.Checked thenbegin
//...選中要執行的代碼endelse begin
//...未選中要執行的代碼end;
二、TComBobox
1、添加
TComBobox就是下拉框,供選擇用的.它有個Items屬性,就是下拉的內容,你可以給它添加下拉內容.比如:
combobox1.Items.add('張三'); combobox1.Items.add('李四');
三、TpageControl
添加新頁簽:右擊“New Page”。修改頁簽名字:選擇PageControl的單獨某一標簽(如:TabSheet1或TabSheet2),找到其Caption屬性進行修改就可以了。
四、TDBGrid
選擇行:TDBGrid屬性properties面板,設置Options-->dgRowSelect及dgRowAlwaysShowSelection設為true;
選中TDBGrid一行,對應其數據集中的一行自動呈選中狀態,可直接操作數據集,即操作的是所選中的行列數據,如:
str:= DBGrid1.DataSource.DataSet.FieldByName('數據ID').Value ;
多選:options->dgMultiSelect:true
顯示選中一行的樣式:dgRowSelect:True
五、TScrollBox
1)清除里面里的控件
for i:=Self.ScrollBox1.ControlCount-1 downto 0 do Self.ScrollBox1.Controls[i].Free;
2)鼠標滾動
//Delphi為滾輪滾動提供OnMouseWheel事件
procedure TFMW_010302_SJTBTX.scrlboxMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); begin if WheelDelta < 0 then SendMessage(scrlbox.Handle,WM_VSCROLL, SB_LINEDOWN, 0) //向下滾 else SendMessage(scrlbox.Handle,WM_VSCROLL, SB_LINEUP, 0); //向上滾 end;
//鼠標按下觸發的事件,獲取scrollbox的焦點
procedure TFMW_010302_SJTBTX.scrlboxMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin scrlbox.SetFocus end;
六、TEdit
1)只能輸入數字
procedure TFrm_020101_devAdd.edt_sizeKeyPress(Sender: TObject; var Key: Char); begin if not(Key in['0'..'9','.',#8]) then begin Key := #0; end; end;