mbshareat
دوشنبه 27 شهریور 1391, 12:12 عصر
سلام
من میخوام یه پنجره انتخاب شاخه داشته باشم که یه Edit هم داشته باشه که اگه از یه جا آدرس رو کپی گرفته بودم بتونم توش الصاق کنم!
می دونم SelectDirectory برای انتخاب شاخه داریم اما اون Edit که گفتم رو نداره!
خواستم خودم پنجره شون پیاده سازی کنم؛ اما توی تعیین شاخه پیشفرض و حتی CurrentDirectory مشکل دارم. این کد رو نگاه کنین:
Uses
FileCtrl,ComCtrls, ShellCtrls;
Function SelectDir(DefaultDir:String;Var OutDir:String):Boolean;
procedure SmoothFont(F: TFont);
var
tagLOGFONT: TLogFont;
begin
GetObject(F.Handle, SizeOf(TLogFont), @tagLOGFONT);
tagLOGFONT.lfQuality := 5;
F.Handle := CreateFontIndirect(tagLOGFONT);
end;
Var
F:TForm;
TV:TShellTreeView;
DirEdit:TEdit;
begin
If DirectoryExists(DefaultDir) then
SetCurrentDirectory(PChar(DefaultDir));
F:=TForm.Create(Application);
With F Do
Begin
Font.Name:='Tahoma';
Font.Size:=12;
Width:=380;
Height:=500;
BorderStyle:=bsDialog;
with TLabel.Create(F) do
begin
Parent := F;
AlignMent:=taRightJustify;
SetBounds(10, 10, 350, 30);
Caption := ':لطفاً شاخه مورد نظر خود را انتخاب نماييد';
Font.Color:=clBlue;
SmoothFont(Font);
end;
TV := TShellTreeView.Create(F);
with TV do
begin
Parent := F;
Font.Size:=10;
SetBounds(10, 40, 350,350);
TabOrder := 0;
TabStop := True;
Path:=DefaultDir;
SmoothFont(Font);
end;
DirEdit:=TEdit.Create(F);
with DirEdit do
begin
Parent := F;
Font.Size:=10;
Font.Color:=clBlue;
SetBounds(10, 395, 350, 20);
Text:='';
SmoothFont(Font);
end;
with TButton.Create(F) do
begin
Parent := F;
SetBounds(10, 425,100 ,30);
Caption := 'تأييد';
Default:=True;
ModalResult:=mrOk ;
SmoothFont(Font);
end;
with TButton.Create(F) do
begin
Parent := F;
SetBounds(260, 425,100 ,30);
Caption := 'انصراف';
Cancel:=True;
ModalResult:=mrCancel;
SmoothFont(Font);
end;
if ShowModal = mrOk then
Begin
Result:=True;
If DirEdit.Text<>'' then
OutDir:=Trim(DirEdit.Text)
Else
OutDir:=TV.Path;
End;
End;
F.Free;
end;
این هم نحوه استفاده:
if SelectDir(Dir,Dir) then
FileListBox1.Directory:=Dir;
SetCurrentDirectory و همچنین تعیین Path برای ShellTreeView کمکی برای منتقل شدن به شاخه مورد نظر در پنجره ایجاد شده نمیکنه!
من میخوام یه پنجره انتخاب شاخه داشته باشم که یه Edit هم داشته باشه که اگه از یه جا آدرس رو کپی گرفته بودم بتونم توش الصاق کنم!
می دونم SelectDirectory برای انتخاب شاخه داریم اما اون Edit که گفتم رو نداره!
خواستم خودم پنجره شون پیاده سازی کنم؛ اما توی تعیین شاخه پیشفرض و حتی CurrentDirectory مشکل دارم. این کد رو نگاه کنین:
Uses
FileCtrl,ComCtrls, ShellCtrls;
Function SelectDir(DefaultDir:String;Var OutDir:String):Boolean;
procedure SmoothFont(F: TFont);
var
tagLOGFONT: TLogFont;
begin
GetObject(F.Handle, SizeOf(TLogFont), @tagLOGFONT);
tagLOGFONT.lfQuality := 5;
F.Handle := CreateFontIndirect(tagLOGFONT);
end;
Var
F:TForm;
TV:TShellTreeView;
DirEdit:TEdit;
begin
If DirectoryExists(DefaultDir) then
SetCurrentDirectory(PChar(DefaultDir));
F:=TForm.Create(Application);
With F Do
Begin
Font.Name:='Tahoma';
Font.Size:=12;
Width:=380;
Height:=500;
BorderStyle:=bsDialog;
with TLabel.Create(F) do
begin
Parent := F;
AlignMent:=taRightJustify;
SetBounds(10, 10, 350, 30);
Caption := ':لطفاً شاخه مورد نظر خود را انتخاب نماييد';
Font.Color:=clBlue;
SmoothFont(Font);
end;
TV := TShellTreeView.Create(F);
with TV do
begin
Parent := F;
Font.Size:=10;
SetBounds(10, 40, 350,350);
TabOrder := 0;
TabStop := True;
Path:=DefaultDir;
SmoothFont(Font);
end;
DirEdit:=TEdit.Create(F);
with DirEdit do
begin
Parent := F;
Font.Size:=10;
Font.Color:=clBlue;
SetBounds(10, 395, 350, 20);
Text:='';
SmoothFont(Font);
end;
with TButton.Create(F) do
begin
Parent := F;
SetBounds(10, 425,100 ,30);
Caption := 'تأييد';
Default:=True;
ModalResult:=mrOk ;
SmoothFont(Font);
end;
with TButton.Create(F) do
begin
Parent := F;
SetBounds(260, 425,100 ,30);
Caption := 'انصراف';
Cancel:=True;
ModalResult:=mrCancel;
SmoothFont(Font);
end;
if ShowModal = mrOk then
Begin
Result:=True;
If DirEdit.Text<>'' then
OutDir:=Trim(DirEdit.Text)
Else
OutDir:=TV.Path;
End;
End;
F.Free;
end;
این هم نحوه استفاده:
if SelectDir(Dir,Dir) then
FileListBox1.Directory:=Dir;
SetCurrentDirectory و همچنین تعیین Path برای ShellTreeView کمکی برای منتقل شدن به شاخه مورد نظر در پنجره ایجاد شده نمیکنه!