Example #1
0
        public FileDialog()
        {
#if !UNITY_STANDALONE && !UNITY_ANDROID
            throw new NotSupportedException();
#endif
            BackColor       = Color.White;
            HeaderTextAlign = ContentAlignment.MiddleCenter;
            Filter          = "All files|*.*";
            MinimumSize     = new Drawing.Size(240, 240);
            Padding         = new Padding(12, 12, 12, 12);
            ResizeIcon      = true;
            Text            = "File Dialog";

            handleFormSize = false;
            Size           = savedFormSize;
            handleFormSize = true;

            #region Button Back.
            buttonBack = new Button();
            buttonBack.BackgroundImageLayout = ImageLayout.Center;
            buttonBack.Enabled     = false;
            buttonBack.Font        = new Drawing.Font("Arial", 16, FontStyle.Bold);
            buttonBack.Image       = FolderNavBack;
            buttonBack.Location    = new Point(Padding.Left, HeaderHeight + Padding.Top);
            buttonBack.BackColor   = Color.Transparent;
            buttonBack.BorderColor = Color.Transparent;
            buttonBack.Size        = new Size(22, 22);
            if (buttonBack.Image == null)
            {
                buttonBack.Text = "◀";
            }
            buttonBack.Click += (sender, args) =>
            {
                buttonBack.Enabled = fileRender.Back() && fileRender.prevPathes.Count > 0;
                textBoxPath.Text   = fileRender.currentPath;
            };
            Controls.Add(buttonBack);

            ToolTip buttonBackTooltip = new ToolTip();
            buttonBackTooltip.SetToolTip(buttonBack, "Back");
            #endregion ;

            #region Button Up.
            buttonUp = new Button();
            buttonUp.BackgroundImageLayout = ImageLayout.Center;
            buttonUp.Font        = new Drawing.Font("Arial", 16, FontStyle.Bold);
            buttonUp.Image       = FolderNavUp;
            buttonUp.Location    = new Point(buttonBack.Location.X + buttonBack.Width + 8, buttonBack.Location.Y);
            buttonUp.BackColor   = Color.Transparent;
            buttonUp.BorderColor = Color.Transparent;
            buttonUp.Size        = new Drawing.Size(22, 22);
            if (buttonUp.Image == null)
            {
                buttonUp.Text = "▲";
            }
            buttonUp.Click += (sender, args) =>
            {
                fileRender.Up();
            };
            Controls.Add(buttonUp);

            ToolTip buttonUpTooltip = new ToolTip();
            buttonUpTooltip.SetToolTip(buttonUp, "Up");
            #endregion

            #region Button Refresh.
            buttonRefresh             = new Button();
            buttonRefresh.Anchor      = AnchorStyles.Top | AnchorStyles.Right;
            buttonRefresh.Image       = FolderNavRefresh;
            buttonRefresh.BackColor   = Color.Transparent;
            buttonRefresh.BorderColor = Color.Transparent;
            buttonRefresh.Size        = new Size(22, 22);
            buttonRefresh.Location    = new Point(Width - Padding.Right - buttonRefresh.Width, buttonUp.Location.Y);
            buttonRefresh.Click      += (sender, args) =>
            {
                fileRender.SetDirectory(fileRender.currentPath);
            };
            if (buttonRefresh.Image == null)
            {
                buttonRefresh.Text = "R";
            }
            Controls.Add(buttonRefresh);

            ToolTip buttonRefreshTooltip = new ToolTip();
            buttonRefreshTooltip.SetToolTip(buttonRefresh, "Refresh");
            #endregion

            #region Textbox Path.
            textBoxPath          = new TextBox();
            textBoxPath.Anchor   = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            textBoxPath.Font     = new Drawing.Font("Arial", 14);
            textBoxPath.Location = new Point(buttonUp.Location.X + buttonUp.Width + 8, buttonUp.Location.Y);
            textBoxPath.Size     = new Drawing.Size(Width - textBoxPath.Location.X - Padding.Right - buttonRefresh.Width - 8, buttonBack.Height);
            Controls.Add(textBoxPath);
            #endregion

            #region Button Cancel.
            buttonCancel          = new Button();
            buttonCancel.Anchor   = AnchorStyles.Right | AnchorStyles.Bottom;
            buttonCancel.Location = new Point(Width - Padding.Right - buttonCancel.Width, Height - Padding.Bottom - buttonCancel.Height);
            buttonCancel.Text     = "Cancel";
            buttonCancel.Click   += (sender, args) =>
            {
                DialogResult = Forms.DialogResult.Cancel;
                Close();
            };
            Controls.Add(buttonCancel);
            #endregion

            #region Button Ok.
            buttonOk          = new Button();
            buttonOk.Anchor   = AnchorStyles.Bottom | AnchorStyles.Right;
            buttonOk.Location = new Point(buttonCancel.Location.X - buttonOk.Width - 8, buttonCancel.Location.Y);
            buttonOk.Text     = "Ok";
            buttonOk.Click   += (sender, args) => { OpenFile(); };
            Controls.Add(buttonOk);
            #endregion

            #region Label Filename.
            labelFilename           = new Label();
            labelFilename.Anchor    = AnchorStyles.Bottom | AnchorStyles.Left;
            labelFilename.Location  = new Point(8, buttonOk.Location.Y - 30);
            labelFilename.Size      = new Drawing.Size(64, 22);
            labelFilename.Text      = "File: ";
            labelFilename.TextAlign = ContentAlignment.MiddleRight;
            Controls.Add(labelFilename);
            #endregion

            #region Textbox Filename.
            textBoxFilename          = new TextBox();
            textBoxFilename.Anchor   = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
            textBoxFilename.Location = new Point(labelFilename.Location.X + labelFilename.Width, labelFilename.Location.Y);
            textBoxFilename.Size     = new Drawing.Size(Width - 32 - (buttonOk.Width + 8 + buttonCancel.Width) - labelFilename.Width, 22);
            Controls.Add(textBoxFilename);
            #endregion

            #region Combobox Filter.
            comboFilter          = new ComboBox();
            comboFilter.Anchor   = AnchorStyles.Bottom | AnchorStyles.Right;
            comboFilter.Size     = new Drawing.Size(buttonOk.Width + 8 + buttonCancel.Width, 22);
            comboFilter.Location = new Point(Width - Padding.Right - comboFilter.Width, textBoxFilename.Location.Y);
            Controls.Add(comboFilter);
            #endregion

            #region File Render.
            fileRender                     = new FileRender(this);
            fileRender.Anchor              = AnchorStyles.All;
            fileRender.Location            = new Point(Padding.Left, buttonBack.Location.Y + buttonBack.Height + 8);
            fileRender.Name                = "fileRender";
            fileRender.Size                = new Drawing.Size(Width - Padding.Left - Padding.Right, textBoxFilename.Location.Y - buttonBack.Location.Y - buttonBack.Height - 16);
            fileRender.OnDirectoryChanged += () =>
            {
                if (fileRender.prevPathes.Count > 0)
                {
                    buttonBack.Enabled = true;
                }
                textBoxPath.Text = fileRender.currentPath;
            };
            fileRender.OnSelectedFileChanged += (file) =>
            {
                textBoxFilename.Text = file.ToString();
            };
            fileRender.OnFileOpen += (file) =>
            {
                OpenFile();
            };
            Controls.Add(fileRender);
            #endregion

            textBoxPath.Text         = fileRender.currentPath;
            textBoxPath.TextChanged += (sender, args) =>
            {
                fileRender.SetDirectory(textBoxPath.Text);
            };

            fileRender.filesTree.NodeMouseClick += filesTree_NodeMouseClick;

            this.AcceptButton = buttonOk;
            this.Shown       += FileDialog_Shown;
        }
Example #2
0
        public FileDialog()
        {
#if !UNITY_STANDALONE && !UNITY_ANDROID
            throw new NotSupportedException();
#endif
            BackColor = Color.White;
            HeaderTextAlign = ContentAlignment.MiddleCenter;
            Filter = "All files|*.*";
            MinimumSize = new Drawing.Size(240, 240);
            Padding = new Padding(12, 12, 12, 12);
            ResizeIcon = true;
            Size = new Drawing.Size(540, 320);
            Text = "File Dialog";

            #region Button Back.
            buttonBack = new Button();
            buttonBack.BackgroundImageLayout = ImageLayout.Center;
            buttonBack.Enabled = false;
            buttonBack.Font = new Drawing.Font("Arial", 16, FontStyle.Bold);
            buttonBack.Image = FolderNavBack;
            buttonBack.Location = new Point(Padding.Left, HeaderHeight + Padding.Top);
            buttonBack.BackColor = Color.Transparent;
            buttonBack.BorderColor = Color.Transparent;
            buttonBack.Size = new Size(22, 22);
            if (buttonBack.Image == null) buttonBack.Text = "◀";
            buttonBack.Click += (sender, args) =>
            {
                buttonBack.Enabled = fileRender.Back() && fileRender.prevPathes.Count > 0;
                textBoxPath.Text = fileRender.currentPath;
            };
            Controls.Add(buttonBack);

            ToolTip buttonBackTooltip = new ToolTip();
            buttonBackTooltip.SetToolTip(buttonBack, "Back");
            #endregion;

            #region Button Up.
            buttonUp = new Button();
            buttonUp.BackgroundImageLayout = ImageLayout.Center;
            buttonUp.Font = new Drawing.Font("Arial", 16, FontStyle.Bold);
            buttonUp.Image = FolderNavUp;
            buttonUp.Location = new Point(buttonBack.Location.X + buttonBack.Width + 8, buttonBack.Location.Y);
            buttonUp.BackColor = Color.Transparent;
            buttonUp.BorderColor = Color.Transparent;
            buttonUp.Size = new Drawing.Size(22, 22);
            if (buttonUp.Image == null) buttonUp.Text = "▲";
            buttonUp.Click += (sender, args) =>
            {
                fileRender.Up();
            };
            Controls.Add(buttonUp);

            ToolTip buttonUpTooltip = new ToolTip();
            buttonUpTooltip.SetToolTip(buttonUp, "Up");
            #endregion

            #region Button Refresh.
            buttonRefresh = new Button();
            buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Right;
            buttonRefresh.Image = FolderNavRefresh;
            buttonRefresh.BackColor = Color.Transparent;
            buttonRefresh.BorderColor = Color.Transparent;
            buttonRefresh.Size = new Size(22, 22);
            buttonRefresh.Location = new Point(Width - Padding.Right - buttonRefresh.Width, buttonUp.Location.Y);
            buttonRefresh.Click += (sender, args) =>
            {
                fileRender.SetDirectory(fileRender.currentPath);
            };
            if (buttonRefresh.Image == null) buttonRefresh.Text = "R";
            Controls.Add(buttonRefresh);

            ToolTip buttonRefreshTooltip = new ToolTip();
            buttonRefreshTooltip.SetToolTip(buttonRefresh, "Refresh");
            #endregion

            #region Textbox Path.
            textBoxPath = new TextBox();
            textBoxPath.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            textBoxPath.Font = new Drawing.Font("Arial", 14);
            textBoxPath.Location = new Point(buttonUp.Location.X + buttonUp.Width + 8, buttonUp.Location.Y);
            textBoxPath.Size = new Drawing.Size(Width - textBoxPath.Location.X - Padding.Right - buttonRefresh.Width - 8, buttonBack.Height);
            Controls.Add(textBoxPath);
            #endregion

            #region Button Cancel.
            buttonCancel = new Button();
            buttonCancel.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            buttonCancel.Location = new Point(Width - Padding.Right - buttonCancel.Width, Height - Padding.Bottom - buttonCancel.Height);
            buttonCancel.Text = "Cancel";
            buttonCancel.Click += (sender, args) =>
            {
                DialogResult = Forms.DialogResult.Cancel;
                Close();
            };
            Controls.Add(buttonCancel);
            #endregion

            #region Button Ok.
            buttonOk = new Button();
            buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
            buttonOk.Location = new Point(buttonCancel.Location.X - buttonOk.Width - 8, buttonCancel.Location.Y);
            buttonOk.Text = "Ok";
            buttonOk.Click += (sender, args) => { OpenFile(); };
            Controls.Add(buttonOk);
            #endregion

            #region Label Filename.
            labelFilename = new Label();
            labelFilename.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
            labelFilename.Location = new Point(8, buttonOk.Location.Y - 30);
            labelFilename.Size = new Drawing.Size(64, 22);
            labelFilename.Text = "File: ";
            labelFilename.TextAlign = ContentAlignment.MiddleRight;
            Controls.Add(labelFilename);
            #endregion

            #region Textbox Filename.
            textBoxFilename = new TextBox();
            textBoxFilename.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
            textBoxFilename.Location = new Point(labelFilename.Location.X + labelFilename.Width, labelFilename.Location.Y);
            textBoxFilename.Size = new Drawing.Size(Width - 32 - (buttonOk.Width + 8 + buttonCancel.Width) - labelFilename.Width, 22);
            Controls.Add(textBoxFilename);
            #endregion

            #region Combobox Filter.
            comboFilter = new ComboBox();
            comboFilter.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
            comboFilter.Size = new Drawing.Size(buttonOk.Width + 8 + buttonCancel.Width, 22);
            comboFilter.Location = new Point(Width - Padding.Right - comboFilter.Width, textBoxFilename.Location.Y);
            Controls.Add(comboFilter);
            #endregion

            #region File Render.
            fileRender = new FileRender(this);
            fileRender.Anchor = AnchorStyles.All;
            fileRender.Location = new Point(Padding.Left, buttonBack.Location.Y + buttonBack.Height + 8);
            fileRender.Name = "fileRender";
            fileRender.Size = new Drawing.Size(Width - Padding.Left - Padding.Right, textBoxFilename.Location.Y - buttonBack.Location.Y - buttonBack.Height - 16);
            fileRender.OnDirectoryChanged += () =>
            {
                if (fileRender.prevPathes.Count > 0)
                    buttonBack.Enabled = true;
                textBoxPath.Text = fileRender.currentPath;
            };
            fileRender.OnSelectedFileChanged += (file) =>
            {
                textBoxFilename.Text = file.ToString();
            };
            fileRender.OnFileOpen += (file) =>
            {
                OpenFile();
            };
            Controls.Add(fileRender);
            #endregion

            textBoxPath.Text = fileRender.currentPath;
            textBoxPath.TextChanged += (sender, args) =>
            {
                fileRender.SetDirectory(textBoxPath.Text);
            };

            fileRender.filesTree.NodeMouseClick += filesTree_NodeMouseClick;

            this.Shown += FileDialog_Shown;
        }