delphi--自带控件,Tcheckbox、TComBobox、TpageControl、TDBGrid,TScrollBox,TEdit

一、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;

添加新页签:右击“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;

选择行: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;