控件的拖曳

来源:互联网 发布:初级程序员考试大纲 编辑:程序博客网 时间:2024/05/16 04:36

这是一个从ListBox控件拖曳内容至Panel控件的动作
其中S1DragOver和S1DragDrop事件都是Panel控件的,PortList为ListBox控件,设置其属性DragMode=dmAutomatic

//设置数据源控件procedure TForm1.S1DragOver(Sender, Source: TObject; X, Y: Integer;  State: TDragState; var Accept: Boolean);begin  //设定能接受的控件  if TObject(Source)=PortList then     Accept := True;end;//鼠标提起事件procedure TForm1.S1DragDrop(Sender, Source: TObject; X, Y: Integer);var  i,j,z:Integer;begin  z:=PortList.ItemIndex;  if z<0 then Exit;  //将串口列表选中的值赋予串口窗口  for i:=1 to PortNum do  begin    if TWinControl(Sender).Name='S'+InttoStr(i) then    begin      (FindComponent('U'+InttoStr(i)) as TRzGroupBox).Caption:=PortList.Items.Strings[z];      TRzPanel(FindComponent('S'+InttoStr(i))).Caption:='Port OK';      Break;    end;  end;  //若此串口值被其他窗口占用,则清除其值  for j:=1 to PortNum do  begin    if (j<>i) and ((FindComponent('U'+InttoStr(j)) as TRzGroupBox).Caption=PortList.Items.Strings[z]) then    begin      (FindComponent('U'+InttoStr(j)) as TRzGroupBox).Caption:='';      TRzPanel(FindComponent('S'+InttoStr(i))).Caption:='Port Nil';    end;  end;end;
0 0
原创粉丝点击