This code comes from an application that contains a list box and three labels, each with a different font and color. The DragMode property for each of the labels is dmAutomatic. The user can select a label and drag it to a list box and drop it. When the label is dropped, the items in the list box assume the color and font of the dropped label.
This OnDragOver event handler permits the list box to accept a dropped label:procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);begin
Accept := Source is TLabel;end;This OnDragDrop event handler implements the drop behavior.procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);begin
if (Sender is TListBox) and (Source is TLabel) then
begin
with Sender as TListBox do
begin
Font := (Source as TLabel).Font;
Color := (Source as TLabel).Color;
end;
end;
end;
This OnDragOver event handler permits the list box to accept a dropped label:procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);begin
Accept := Source is TLabel;end;This OnDragDrop event handler implements the drop behavior.procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);begin
if (Sender is TListBox) and (Source is TLabel) then
begin
with Sender as TListBox do
begin
Font := (Source as TLabel).Font;
Color := (Source as TLabel).Color;
end;
end;
end;
解决方案 »
- 有点郁闷
- 请问用delphi如何实现线程池?
- 高手,请进
- 100分!高手进来:如何在DELPHI等编程语言里使用ACCESS数据库的MSysObjects系统表?????
- 关于DELPHI注销的问题请教
- 怎么样让子窗体在程序一运行时不出现,直到在主窗体菜单中调用它
- 关于TreeView的使用
- 怎么把MessageDlg中的mtwarning,[mbyes,mbno]改成中文的“确定”和“取消”?
- csdn的网页保存后怎么看不了,打开以后只有几行字:无法显示 XML 页
- 级别:特级,关于dbexpress存取jpeg图片到sql2000中
- 如何在程序中作出windows xp 风格的窗体,希望各位大哥多多指教!
- 各位老大谁用过控件duckbarcode,那里有得下载?
菜鸟点了半天没有任何反应,怎么回事啊?help我有看不懂!
procedure TForm8.selTVDragOver(Sender, Source: TObject; X,
Y: Integer; State: TDragState; var Accept: Boolean);
var
Snode,Tnode:Ttreenode;
begin
if source=seltv then
begin
Snode:=seltv.Selected;
Tnode:=seltv.GetNodeAt(x,y);
if (Tnode<>nil) and (Tnode<>Snode) and (Tnode<>Snode.Parent) then
accept:=true
else
accept:=false;
end
else
accept:=false;
end;procedure TForm8.selLVDragDrop(Sender, Source: TObject; X,
Y: Integer);
var
Snode:TTreeNode;
ListItem:TListItem;
begin
sellv.Items.Clear;
if source=seltv then
begin
Snode:=seltv.Selected;
sellv.Items.BeginUpdate;
ListItem:=sellv.Items.Add ;
ListItem.Caption:=snode.Text;
sellv.Items.EndUpdate;
Idelnode(snode);
end;
end;procedure TForm8.selLVDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
sellv.SetFocus;
end;procedure TForm8.RzBitBtn1Click(Sender: TObject);
var
Text:TextFile;
AppPath,s,textname,x,y,z:string;
i:integer;
begin
{ Datamodule3.ADOTable1.Filtered:=true;
Datamodule3.ADOTable1.Filter:='';
Datamodule3.ADOTable1.Filtered:=false;
Datamodule3.ADOTable2.Filtered:=true;
Datamodule3.ADOTable2.Filter:='';
Datamodule3.ADOTable2.Filtered:=false;
}
textname:=DateTimeToStr(Now);
x:=copy(textname,17,2);
y:=copy(textname,20,2);
z:=copy(textname,23,2);
textname:=sellv.TopItem.Caption+copy(textname,1,10)+'-'+x+y+z+'.txt';
grouptextname:=textname;
AppPath:=ExtractFileDir(Application.ExeName);
textname:=AppPath+'\text\'+textname;
AssignFile(Text,textname);
Rewrite(Text);
try
for i:=0 to sellv.Items.Count-1 do
begin
s:=sellv.Items[i].Caption;
Writeln(Text,s);
end;
finally
CloseFile(Text);
showmessage('组合选择完成,文件创建成功!');
end;
close();
end;