Пример #1
0
        private void openFilesBackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            var state = (OpenFileProgressState)e.UserState;

            var oldValue = toolStripProgressBar.Value;
            var oldText  = toolStripStatusLabel.Text;

            var newValue = e.ProgressPercentage;
            var newText  = "Loading file " + state.FileName;

            bool needRefresh = false;

            if (oldValue != newValue)
            {
                toolStripProgressBar.Visible = true;
                toolStripProgressBar.Value   = e.ProgressPercentage;
                needRefresh = true;
            }

            if (oldText != newText)
            {
                toolStripStatusLabel.Text = newText;
                needRefresh = true;
            }

            if (needRefresh)
            {
                statusStrip.Refresh();
            }

            if (state.Document != null)
            {
                DocumentWindow window = null;;
                if (state.Document is TwoDADocument)
                {
                    var twoDAWindow = new TwoDADocumentWindow();
                    twoDAWindow.Document = (TwoDADocument)state.Document;
                    window = twoDAWindow;
                }
                else
                {
                    var tlkWindow = new TlkDocumentWindow();
                    tlkWindow.Document = (TlkDocument)state.Document;
                    window             = tlkWindow;
                }

                if (window != null)
                {
                    window.MdiParent   = this;
                    window.FileName    = state.FileName;
                    window.WindowState = FormWindowState.Maximized;
                    RegisterDocumentWindow(window);
                    window.Show();
                }
            }
        }
Пример #2
0
        private void RegisterDocumentWindow(DocumentWindow window)
        {
            mdiToolStrip.Visible = true;

            var mdiButton    = new ToolStripButton(window.Text);
            var mdiSeparator = new ToolStripSeparator();

            mdiButton.Tag         = window;
            mdiButton.ToolTipText = window.FileName;
            mdiButton.Image       = new Icon(window.Icon, new Size(16, 16)).ToBitmap();
            mdiButton.Padding     = new Padding(6, 2, 2, 6);
            mdiButton.Click      +=
                delegate
            {
                if (window.WindowState == FormWindowState.Minimized)
                {
                    window.WindowState = FormWindowState.Normal;
                }
                window.Activate();
            };

            mdiToolStrip.Items.Add(mdiButton);
            mdiToolStrip.Items.Add(mdiSeparator);

            window.TextChanged += delegate { mdiButton.Text = window.Text; };
            window.Closed      +=
                delegate
            {
                mdiToolStrip.Items.Remove(mdiButton);
                mdiToolStrip.Items.Remove(mdiSeparator);

                if (mdiToolStrip.Items.Count == 0)
                {
                    mdiToolStrip.Visible = false;
                }
            };
            window.Activated +=
                delegate
            {
                foreach (var button in mdiToolStrip.Items.OfType <ToolStripButton>())
                {
                    button.Checked = (button == mdiButton);
                }
            };
        }