コード例 #1
0
            public FormFileInfo(string path)
            {
#if UNITY_STANDALONE
                Size            = new Drawing.Size(320, 120);
                Location        = new Point(Screen.PrimaryScreen.WorkingArea.Width / 2 - Width / 2, Screen.PrimaryScreen.WorkingArea.Height / 2 - Height / 2);
                FormBorderStyle = FormBorderStyle.FixedSingle;
                Text            = "Properties: ";

                if (global::System.IO.File.Exists(path) == false)
                {
                    return;
                }

                var    info   = new global::System.IO.FileInfo(path);
                var    bytes  = info.Length;
                string sbytes = bytes.ToString() + " bytes";
                if (bytes >= 1000000000)
                {
                    sbytes = (bytes / 1000000000) + " gb";
                }
                if (bytes >= 1000000)
                {
                    sbytes = (bytes / 1000000) + " mb";
                }
                else if (bytes >= 1000)
                {
                    sbytes = (bytes / 1000) + " kb";
                }

                Label labelSize = new Label();
                labelSize.Location = new Point(16, 32);
                labelSize.Text     = "Size: " + sbytes;
                Controls.Add(labelSize);

                Label labelCreationDate = new Label();
                labelCreationDate.Location = new Point(16, 64);
                labelCreationDate.Text     = "Date creation: " + info.CreationTime.ToString("dd.MM.yyyy");
                Controls.Add(labelCreationDate);

                Label labelModDate = new Label();
                labelModDate.Location = new Point(16, 86);
                labelModDate.Text     = "Date modified: " + info.LastWriteTime.ToString();
                Controls.Add(labelModDate);

                string fileName = global::System.IO.Path.GetFileName(path);
                Text += fileName;
#endif
            }
コード例 #2
0
        internal FileDialog()
        {
#if !UNITY_STANDALONE && !UNITY_ANDROID
            throw new NotSupportedException();
#endif

            BackColor     = Color.White;
            Filter        = "All files|*.*";
            MinimumSize   = new Drawing.Size(240, 240);
            KeyPreview    = true;
            Padding       = new Padding(12, 12, 12, 12);
            SizeGripStyle = SizeGripStyle.Show;
            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, uwfHeaderHeight + Padding.Top);
            buttonBack.BackColor      = Color.Transparent;
            buttonBack.uwfBorderColor = Color.Transparent;
            buttonBack.Size           = new Size(22, 22);
            if (buttonBack.Image == null)
            {
                buttonBack.Text = "◀";
            }
            buttonBack.Click += (sender, args) => ButtonBack();
            Controls.Add(buttonBack);

            ToolTip buttonBackTooltip = new ToolTip();
            buttonBackTooltip.SetToolTip(buttonBack, "Back (ALT + Left Arrow)");
            #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.uwfBorderColor = Color.Transparent;
            buttonUp.Size           = new Drawing.Size(22, 22);
            if (buttonUp.Image == null)
            {
                buttonUp.Text = "▲";
            }
            buttonUp.Click += (sender, args) => ButtonUp();
            Controls.Add(buttonUp);

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

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

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

            #region Textbox Path.
            textBoxPath          = new PathTextBox(this);
            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 = global::UWinForms.System.Windows.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.DropDownStyle = ComboBoxStyle.DropDownList;
            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.
            fileRenderer                     = new FileRenderer(this);
            fileRenderer.Anchor              = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;
            fileRenderer.Location            = new Point(Padding.Left, buttonBack.Location.Y + buttonBack.Height + 8);
            fileRenderer.Name                = "fileRenderer";
            fileRenderer.Size                = new Drawing.Size(Width - Padding.Left - Padding.Right, textBoxFilename.Location.Y - buttonBack.Location.Y - buttonBack.Height - 16);
            fileRenderer.OnDirectoryChanged += () =>
            {
                if (fileRenderer.prevPathes.Count > 0)
                {
                    buttonBack.Enabled = true;
                }
                textBoxPath.Text = fileRenderer.currentPath;
            };
            fileRenderer.OnSelectedFileChanged += (file) =>
            {
                textBoxFilename.Text = file.ToString();
            };
            fileRenderer.OnFileOpen += (file) =>
            {
                OpenFile();
            };
            Controls.Add(fileRenderer);
            #endregion

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

            fileRenderer.filesTree.NodeMouseClick += filesTree_NodeMouseClick;

            AcceptButton = buttonOk;
            Shown       += FileDialog_Shown;
        }