zoukankan      html  css  js  c++  java
  • DELPHI

    DELPHI - How to use opendialog1 for choosing a folder?

    On Vista and up you can show a more modern looking dialog using TFileOpenDialog.

    var
      OpenDialog: TFileOpenDialog;
      SelectedFolder: string;
    .....
    OpenDialog := TFileOpenDialog.Create(MainForm);
    try
      OpenDialog.Options := OpenDialog.Options + [fdoPickFolders];
      if not OpenDialog.Execute then
        Abort;
      SelectedFolder := OpenDialog.FileName;
    finally
      OpenDialog.Free;
    end;
    
    if SelectedFolder[ Length( SelectedFolder ) ] <> '' then
      SelectedFolder := SelectedFolder + '';

     

    uses FileCtrl;
    const
      SELDIRHELP = 1000;
    procedure TForm1.Button1Click(Sender: TObject);
    var
      Dir: string;
    begin
      Dir := 'C:Windows';
      if FileCtrl.SelectDirectory(Dir, [sdAllowCreate, sdPerformCreate, sdPrompt],SELDIRHELP) then
        Label1.Caption := Dir;
    end;

    Selecting a directory with TOpenDialog

    ust found the code below that seems to work fine in XP and Vista, Win7.

    It provides a UI for a user to select a directory.

    It uses TOpenDialog, but sends it a few messages to clean up the appearance for the purposes of selecting a directory.

    After suffering from the limited capabilities provided by Windows itself,

    it's a pleasure to be able to give my users a familiar UI where they can browse and select a folder comfortably.

    I'd been looking for something like this for a long time so thought I'd post it here so others can benefit from it.

    Here's what it looks like in Win 7:

    function GimmeDir(var Dir: string): boolean;
    var
      OpenDialog: TOpenDialog;
      OpenDir: TOpenDir;
    begin
      //The standard dialog...
      OpenDialog:= TOpenDialog.Create(nil);
      //Objetc that holds the OnShow code to hide controls
      OpenDir:= TOpenDir.create;
      try
        //Conect both components...
        OpenDir.Dialog:= OpenDialog;
        OpenDialog.OnShow:= OpenDir.HideControls;
        //Configure it so only folders are shown (and file without extension!)...
        OpenDialog.FileName:= '*.';
        OpenDialog.Filter:=   '*.';
        OpenDialog.Title:=    'Chose a folder';
        //No need to check file existis!
        OpenDialog.Options:= OpenDialog.Options + [ofNoValidate];
        //Initial folder...
        OpenDialog.InitialDir:= Dir;
        //Ask user...
        if OpenDialog.Execute then begin
          Dir:= ExtractFilePath(OpenDialog.FileName);
          result:= true;
        end else begin
          result:= false;
        end;
      finally
        //Clean up...
        OpenDir.Free;
        OpenDialog.Free;
      end;
    end;
  • 相关阅读:
    计算机组成原理 04 认识各个硬件部件
    计算机组成原理 02 计算机的发展
    计算机组成原理 01 你好,计组
    蓝桥杯-2020-B组 &#183; 题解/解析(4/17)
    「HTML 5」1.HTML简介
    「易语言」主题颜色配置方案
    「易语言」那些年,我们经历的故事
    彻底解决Ubuntu中 “检测到系统程序错误”
    FFMPEG 的简单使用介绍 —— 合并音视频
    oh-my-zsh 中 agnoster主题 之 隐藏用户名信息
  • 原文地址:https://www.cnblogs.com/shangdawei/p/4791215.html
Copyright © 2011-2022 走看看