Exemple #1
0
 /// <summary>
 ///     Background worker checks for updates.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The event args.</param>
 private void BackgroundUpdateCheckerDoWork(object sender, DoWorkEventArgs e)
 {
     try
     {
         _state = UpdaterState.Checking;
         OnCheckingForUpdate(new UpdaterStateEventArgs(GetEntryAssembly, _installOptions, _updateServerPackagePath, _state));
     }
     catch (Exception exception)
     {
         VisualExceptionDialog.Show(exception);
     }
 }
Exemple #2
0
 /// <summary>Loads a <see cref="Theme" /> from resources.</summary>
 /// <param name="theme">The theme.</param>
 private void LoadThemeFromResources(Themes theme)
 {
     try
     {
         _rawTheme = ResourceManager.ReadResource(Assembly.GetExecutingAssembly().Location, $"VisualPlus.Resources.Themes.{theme.ToString()}.xml");
         XDocument _resourceDocumentTheme = XDocument.Parse(_rawTheme);
         Deserialize(_resourceDocumentTheme);
     }
     catch (Exception e)
     {
         VisualExceptionDialog.Show(e);
     }
 }
        /// <summary>Loads the assembly file.</summary>
        /// <param name="file">The file path.</param>
        /// <returns>The <see cref="Assembly" />.</returns>
        private static Assembly LoadAssembly(string file)
        {
            if (string.IsNullOrEmpty(file))
            {
                VisualExceptionDialog.Show(new NoNullAllowedException(ExceptionMessenger.IsNullOrEmpty(file)));
            }

            if (!File.Exists(file))
            {
                VisualExceptionDialog.Show(new NoNullAllowedException(ExceptionMessenger.FileNotFound(file)));
            }

            return(Assembly.LoadFile(file));
        }
Exemple #4
0
        /// <summary>
        ///     Deserialize the settings file.
        /// </summary>
        /// <param name="settingsFile">The settings document.</param>
        private void Deserialize(XContainer settingsFile)
        {
            try
            {
                _updaterSettings.AutoUpdate                 = Convert.ToBoolean(string.Concat(settingsFile.Descendants("AutoUpdate").Nodes()));
                _updaterSettings.DisplayWelcomePage         = Convert.ToBoolean(string.Concat(settingsFile.Descendants("DisplayWelcomePage").Nodes()));
                _updaterSettings.NotifyUpdateAvailable      = Convert.ToBoolean(string.Concat(settingsFile.Descendants("NotifyUpdateAvailable").Nodes()));
                _updaterSettings.NotifyUpdateReadyToInstall = Convert.ToBoolean(string.Concat(settingsFile.Descendants("NotifyBeforeInstallingUpdates").Nodes()));

                _applicationSettings.MaxRecentProjects = Convert.ToInt32(string.Concat(settingsFile.Descendants("MaxRecentProjects").Nodes()));
            }
            catch (Exception e)
            {
                VisualExceptionDialog.Show(e);
            }
        }
Exemple #5
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            try
            {
                Graphics _graphics = e.Graphics;
                _graphics.Clear(Parent.BackColor);
                _graphics.SmoothingMode     = SmoothingMode.HighQuality;
                _graphics.TextRenderingHint = TextStyle.TextRenderingHint;
                Rectangle _clientRectangle = new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 1);
                ControlGraphicsPath = VisualBorderRenderer.CreateBorderTypePath(_clientRectangle, _border);
                _graphics.FillRectangle(new SolidBrush(BackColor), new Rectangle(ClientRectangle.X - 1, ClientRectangle.Y - 1, ClientRectangle.Width + 1, ClientRectangle.Height + 1));

                Color _backColor = ControlColorState.BackColorState(BackColorState, Enabled, MouseState);

                e.Graphics.SetClip(ControlGraphicsPath);
                VisualBackgroundRenderer.DrawBackground(e.Graphics, _backColor, BackgroundImage, MouseState, _clientRectangle, _border);

                Color _textColor = Enabled ? ForeColor : TextStyle.Disabled;

                if (_image != null)
                {
                    VisualControlRenderer.DrawContent(e.Graphics, ClientRectangle, Text, Font, _textColor, _image, _image.Size, _textImageRelation);
                }
                else
                {
                    StringFormat _stringFormat = new StringFormat
                    {
                        Alignment     = _textAlignment,
                        LineAlignment = _textLineAlignment
                    };

                    VisualControlRenderer.DrawContentText(e.Graphics, ClientRectangle, Text, Font, _textColor, _stringFormat);
                }

                VisualBorderRenderer.DrawBorderStyle(e.Graphics, _border, ControlGraphicsPath, MouseState);
                DrawAnimation(e.Graphics);
                e.Graphics.ResetClip();
            }
            catch (Exception exception)
            {
                VisualExceptionDialog.Show(exception);
            }
        }
Exemple #6
0
        public void UpdateTheme(Theme theme)
        {
            try
            {
                ForeColor          = theme.TextSetting.Enabled;
                TextStyle.Enabled  = theme.TextSetting.Enabled;
                TextStyle.Disabled = theme.TextSetting.Disabled;

                Font = theme.TextSetting.Font;
            }
            catch (Exception e)
            {
                VisualExceptionDialog.Show(e);
            }

            Invalidate();
            OnThemeChanged(new ThemeEventArgs(theme));
        }
Exemple #7
0
        /// <summary>
        ///     Checking for update.
        /// </summary>
        /// <param name="e">The sender.</param>
        protected virtual void OnCheckingForUpdate(UpdaterStateEventArgs e)
        {
            if (_state == UpdaterState.Outdated)
            {
                CheckingForUpdate?.Invoke(new UpdaterStateEventArgs(GetEntryAssembly, _installOptions, _updateServerPackagePath, _state));
                return;
            }

            CheckingForUpdate?.Invoke(new UpdaterStateEventArgs(GetEntryAssembly, _installOptions, _updateServerPackagePath, _state));
            if (NetworkManager.InternetAvailable)
            {
                if (NetworkManager.SourceExists(e.PackagePath.OriginalString))
                {
                    if (ApplicationManager.CheckForUpdate(e.Assembly, e.PackagePath))
                    {
                        _updateAvailable = true;
                        NotificationUpdateAvailable();
                        _state = UpdaterState.Outdated;
                        CheckingForUpdate?.Invoke(new UpdaterStateEventArgs(GetEntryAssembly, _installOptions, _updateServerPackagePath, _state));
                    }
                    else
                    {
                        _updateAvailable = false;
                        _state           = UpdaterState.Updated;
                        CheckingForUpdate?.Invoke(new UpdaterStateEventArgs(GetEntryAssembly, _installOptions, _updateServerPackagePath, _state));
                    }
                }
                else
                {
                    _state           = UpdaterState.PackageNotFound;
                    _updateAvailable = false;
                    CheckingForUpdate?.Invoke(new UpdaterStateEventArgs(GetEntryAssembly, _installOptions, _updateServerPackagePath, _state));
                    VisualExceptionDialog.Show(new FileNotFoundException(StringManager.RemoteFileNotFound(e.PackagePath.OriginalString)));
                }
            }
            else
            {
                _state           = UpdaterState.NoConnection;
                _updateAvailable = false;
                CheckingForUpdate?.Invoke(new UpdaterStateEventArgs(GetEntryAssembly, _installOptions, _updateServerPackagePath, _state));
            }

            _backgroundUpdateChecker.CancelAsync();
        }
Exemple #8
0
        /// <summary>Draws the selector.</summary>
        /// <param name="graphics">The specified graphics to draw on.</param>
        /// <param name="selectorType">The selector Type.</param>
        private void DrawSelector(Graphics graphics, SelectorTypes selectorType)
        {
            if (_selectorVisible)
            {
                try
                {
                    for (var tabIndex = 0; tabIndex <= TabCount - 1; tabIndex++)
                    {
                        VisualTabPage _tabPage = (VisualTabPage)TabPages[tabIndex];
                        _tabPage.Rectangle = GetStyledTabRectangle(tabIndex);

                        if (tabIndex == SelectedIndex)
                        {
                            switch (selectorType)
                            {
                            case SelectorTypes.Arrow:
                            {
                                DrawSelectorArrow(graphics, _tabPage.Rectangle);
                                break;
                            }

                            case SelectorTypes.Line:
                            {
                                DrawSelectorLine(graphics, _tabPage.Rectangle);
                                break;
                            }

                            default:
                            {
                                throw new ArgumentOutOfRangeException(nameof(selectorType), selectorType, null);
                            }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    VisualExceptionDialog.Show(e);
                }
            }
        }
Exemple #9
0
        /// <summary>Load a package from a uri.</summary>
        /// <param name="uri">The uri.</param>
        public void Load(Uri uri)
        {
            try
            {
                if (string.IsNullOrEmpty(uri.OriginalString))
                {
                    throw new NoNullAllowedException(StringManager.IsNullOrEmpty(uri.OriginalString));
                }

                if (!NetworkManager.IsURLFormatted(uri.OriginalString))
                {
                    throw new UriFormatException(StringManager.UrlNotWellFormatted(uri.OriginalString));
                }

                if (NetworkManager.InternetAvailable)
                {
                    XDocument _xmlPackageDocument = XDocument.Load(uri.OriginalString);
                    Deserialize(_xmlPackageDocument);

                    // Bug: Gets thrown on slow connection.
                    // if (!NetworkManager.SourceExists(url))
                    // {
                    // throw new FileNotFoundException(StringManager.PackageNotFound(url));
                    // }
                    // else
                    // {
                    // // Load from url
                    // XDocument _xPackage = XDocument.Load(url);
                    // Deserialize(_xPackage);
                    // }
                }
            }
            catch (WebException)
            {
                VisualExceptionDialog.Show(new FileNotFoundException(StringManager.RemoteFileNotFound(uri.OriginalString)));
            }
            catch (Exception e)
            {
                VisualExceptionDialog.Show(e);
            }
        }
Exemple #10
0
        /// <summary>
        ///     Saves the settings to file.
        /// </summary>
        public void Save()
        {
            try
            {
                XDocument _settingsDocument = new XDocument();
                XElement  _headerElement    = new XElement("Settings");
                _settingsDocument.Add(_headerElement);

                _headerElement.Add(new XElement("AutoUpdate", _updaterSettings.AutoUpdate));
                _headerElement.Add(new XElement("NotifyUpdateAvailable", _updaterSettings.NotifyUpdateAvailable));
                _headerElement.Add(new XElement("NotifyBeforeInstallingUpdates", _updaterSettings.NotifyUpdateReadyToInstall));
                _headerElement.Add(new XElement("DisplayWelcomePage", _updaterSettings.DisplayWelcomePage));

                _headerElement.Add(new XElement("MaxRecentProjects", _applicationSettings.MaxRecentProjects));

                _settingsDocument.Save(FilePath, SaveOptions.None);
            }
            catch (Exception e)
            {
                VisualExceptionDialog.Show(e);
            }
        }
Exemple #11
0
        /// <summary>Load a package from filename.</summary>
        /// <param name="path">The file path</param>
        /// <param name="encoding">The encoding.</param>
        public void Load(string path, Encoding encoding)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new NoNullAllowedException(StringManager.IsNullOrEmpty(path));
            }

            if (!File.Exists(path))
            {
                throw new FileNotFoundException(StringManager.FileNotFound(path));
            }

            try
            {
                XDocument _packageFile = XDocument.Parse(File.ReadAllText(path, encoding));
                Deserialize(_packageFile);
            }
            catch (Exception e)
            {
                VisualExceptionDialog.Show(e);
            }
        }
Exemple #12
0
        public void UpdateTheme(Theme theme)
        {
            try
            {
                _border.Color      = theme.BorderSettings.Normal;
                _border.HoverColor = theme.BorderSettings.Hover;

                ForeColor          = theme.TextSetting.Enabled;
                TextStyle.Enabled  = theme.TextSetting.Enabled;
                TextStyle.Disabled = theme.TextSetting.Disabled;

                Font        = theme.TextSetting.Font;
                _headerFont = ThemeManager.Theme.TextSetting.Font;

                foreach (ListViewItem _item in Items)
                {
                    _item.BackColor = theme.ListItemSettings.Item;
                }

                _itemSelected = theme.ListItemSettings.ItemSelected;
                _itemHover    = theme.ListItemSettings.ItemHover;

                _columnHeaderColor = theme.OtherSettings.ColumnHeader;
                _headerText        = theme.OtherSettings.ColumnText;

                _colorState = new ColorState
                {
                    Enabled  = theme.BackgroundSettings.Type4,
                    Disabled = theme.BackgroundSettings.Type1
                };
            }
            catch (Exception e)
            {
                VisualExceptionDialog.Show(e);
            }

            Invalidate();
            OnThemeChanged(new ThemeEventArgs(theme));
        }
        public void UpdateTheme(Theme theme)
        {
            try
            {
                _border.Color      = theme.BorderSettings.Normal;
                _border.HoverColor = theme.BorderSettings.Hover;

                _buttonBorder.Color      = theme.BorderSettings.Normal;
                _buttonBorder.HoverColor = theme.BorderSettings.Hover;

                ForeColor          = theme.TextSetting.Enabled;
                TextStyle.Enabled  = theme.TextSetting.Enabled;
                TextStyle.Disabled = theme.TextSetting.Disabled;

                Font = theme.TextSetting.Font;

                _controlColorState = new ColorState
                {
                    Enabled  = theme.BackgroundSettings.Type2,
                    Disabled = theme.BackgroundSettings.Type1
                };

                _buttonColorState = new ControlColorState
                {
                    Enabled  = theme.ColorStateSettings.Enabled,
                    Disabled = theme.ColorStateSettings.Disabled,
                    Hover    = theme.ColorStateSettings.Hover,
                    Pressed  = theme.ColorStateSettings.Pressed
                };
            }
            catch (Exception e)
            {
                VisualExceptionDialog.Show(e);
            }

            Invalidate();
            OnThemeChanged(new ThemeEventArgs(theme));
        }
Exemple #14
0
        /// <summary>Prevents a default instance of the <see cref="StyleManager" /> class from being created.</summary>
        private StyleManager()
        {
            try
            {
                ConstructDefaultThemeFile();

                if (_customThemePath == null)
                {
                    string _themePath = Settings.TemplatesFolder + @"DefaultTheme.xml";
                    _theme           = new Theme(_themePath);
                    _customThemePath = _themePath;
                }

                _formCollection = new List <Form>();

                _themeType = Settings.DefaultValue.DefaultStyle;
                _theme     = new Theme(_themeType);
            }
            catch (Exception e)
            {
                VisualExceptionDialog.Show(e);
            }
        }
Exemple #15
0
        public void UpdateTheme(Theme theme)
        {
            try
            {
                _border.Color      = theme.BorderSettings.Normal;
                _border.HoverColor = theme.BorderSettings.Hover;

                ForeColor          = theme.TextSetting.Enabled;
                TextStyle.Enabled  = theme.TextSetting.Enabled;
                TextStyle.Disabled = theme.TextSetting.Disabled;

                Font = theme.TextSetting.Font;

                BackColorState.Enabled  = theme.ColorStateSettings.Enabled;
                BackColorState.Disabled = theme.ColorStateSettings.Disabled;
            }
            catch (Exception e)
            {
                VisualExceptionDialog.Show(e);
            }

            Invalidate();
            OnThemeChanged(new ThemeEventArgs(theme));
        }
Exemple #16
0
        /// <summary>
        ///     Import the package downloads to the list view.
        /// </summary>
        /// <param name="downloads">The downloads.</param>
        internal void ImportPackageDownloads(List <Uri> downloads)
        {
            try
            {
                foreach (Uri _download in downloads)
                {
                    ListViewItem _item = new ListViewItem(_download.OriginalString);
                    _item.SubItems.Add(NetworkManager.SourceExists(_download.OriginalString).ToString());

                    if (Helper.IsItemInCollection(_item, ListViewUrlList))
                    {
                        return;
                    }

                    ListViewUrlList.Items.Add(_item);
                }

                UpdateDownloadsList();
            }
            catch (Exception e)
            {
                VisualExceptionDialog.Show(e);
            }
        }
Exemple #17
0
        /// <summary>
        ///     Loads the history log file.
        /// </summary>
        public void Load()
        {
            if (string.IsNullOrEmpty(_logFile))
            {
                throw new NoNullAllowedException(StringManager.IsNullOrEmpty(_logFile));
            }

            try
            {
                if (File.Exists(_logFile))
                {
                    XDocument _historyLogFile = XDocument.Load(_logFile);
                    Deserialize(_historyLogFile);
                }
                else
                {
                    Save();
                }
            }
            catch (Exception e)
            {
                VisualExceptionDialog.Show(e);
            }
        }
Exemple #18
0
        /// <summary>Draws the tab pages.</summary>
        /// <param name="graphics">The specified graphics to draw on.</param>
        private void DrawTabPages(Graphics graphics)
        {
            try
            {
                for (var tabIndex = 0; tabIndex <= TabCount - 1; tabIndex++)
                {
                    VisualTabPage _tabPage = (VisualTabPage)TabPages[tabIndex];
                    _tabPage.Rectangle = GetStyledTabRectangle(tabIndex);

                    if (tabIndex == SelectedIndex)
                    {
                        // Selected tab header
                        DrawBackgroundHeader(graphics, _tabPage, true);
                        DrawBorderHeader(graphics, _tabPage);
                        DrawContentHeader(graphics, _tabPage, true);
                    }
                    else
                    {
                        // Unselected tab header
                        DrawBackgroundHeader(graphics, _tabPage, false);

                        if ((_mouseState == MouseStates.Hover) && _tabPage.Rectangle.Contains(_mouseLocation))
                        {
                            graphics.FillRectangle(new SolidBrush(_tabPage.TabHover), _tabPage.Rectangle);
                        }

                        DrawBorderHeader(graphics, _tabPage);
                        DrawContentHeader(graphics, _tabPage, false);
                    }
                }
            }
            catch (Exception e)
            {
                VisualExceptionDialog.Show(e);
            }
        }
Exemple #19
0
        /// <summary>Deserialize the theme file.</summary>
        /// <param name="themeContainer">The theme container.</param>
        private void Deserialize(XContainer themeContainer)
        {
            const string Header      = @"VisualPlus-Theme/";
            const string Information = Header + @"Information/";
            const string StyleTable  = Header + @"StyleTable/";
            const string Shared      = StyleTable + @"Shared/";
            const string Toolkit     = StyleTable + @"Toolkit/";

            try
            {
                _informationSettings.Name   = themeContainer.GetValue(Information + "Name");
                _informationSettings.Author = themeContainer.GetValue(Information + "Author");

                _borderSettings.Normal = themeContainer.GetValue(Shared + "Border/Normal").ToColor();
                _borderSettings.Hover  = themeContainer.GetValue(Shared + "Border/Hover").ToColor();

                _textSettings.Enabled          = themeContainer.GetValue(Shared + "Font/Enabled").ToColor();
                _textSettings.Disabled         = themeContainer.GetValue(Shared + "Font/Disabled").ToColor();
                _textSettings.Selected         = themeContainer.GetValue(Shared + "Font/Selected").ToColor();
                _textSettings.SubscriptColor   = themeContainer.GetValue(Shared + "Font/Subscript").ToColor();
                _textSettings.SuperscriptColor = themeContainer.GetValue(Shared + "Font/Superscript").ToColor();
                _textSettings.Font             = ResolveFontFamily(themeContainer.GetValue(Shared + "Font/FontFamily"));

                _controlColorStateSettings.Enabled  = themeContainer.GetValue(Toolkit + "VisualButton/Enabled").ToColor();
                _controlColorStateSettings.Disabled = themeContainer.GetValue(Toolkit + "VisualButton/Disabled").ToColor();
                _controlColorStateSettings.Hover    = themeContainer.GetValue(Toolkit + "VisualButton/Hover").ToColor();
                _controlColorStateSettings.Pressed  = themeContainer.GetValue(Toolkit + "VisualButton/Pressed").ToColor();

                _otherSettings.FormBackground = themeContainer.GetValue(Toolkit + "VisualForm/Background").ToColor();
                _otherSettings.FormWindowBar  = themeContainer.GetValue(Toolkit + "VisualForm/WindowBar").ToColor();

                _listItemSettings.Item          = themeContainer.GetValue(Shared + "ListItem/Normal").ToColor();
                _listItemSettings.ItemHover     = themeContainer.GetValue(Shared + "ListItem/Hover").ToColor();
                _listItemSettings.ItemSelected  = themeContainer.GetValue(Shared + "ListItem/Selected").ToColor();
                _listItemSettings.ItemAlternate = themeContainer.GetValue(Shared + "ListItem/Alternate").ToColor();

                _backgroundSettings.Type1 = themeContainer.GetValue(Shared + "Background/Type1").ToColor();
                _backgroundSettings.Type2 = themeContainer.GetValue(Shared + "Background/Type2").ToColor();
                _backgroundSettings.Type3 = themeContainer.GetValue(Shared + "Background/Type3").ToColor();
                _backgroundSettings.Type4 = themeContainer.GetValue(Shared + "Background/Type4").ToColor();

                _otherSettings.Line      = themeContainer.GetValue(Shared + "Line").ToColor();
                _otherSettings.Shadow    = themeContainer.GetValue(Shared + "Shadow").ToColor();
                _otherSettings.LightText = themeContainer.GetValue(Shared + "LightText").ToColor();

                _otherSettings.ColumnHeader = themeContainer.GetValue(Shared + "ColumnHeader/Header").ToColor();
                _otherSettings.ColumnText   = themeContainer.GetValue(Shared + "ColumnHeader/Text").ToColor();

                _otherSettings.ControlEnabled  = themeContainer.GetValue(Shared + "Control/Enabled").ToColor();
                _otherSettings.ControlDisabled = themeContainer.GetValue(Shared + "Control/Disabled").ToColor();

                _otherSettings.BackCircle = themeContainer.GetValue(Toolkit + "VisualRadialProgress/BackCircle").ToColor();
                _otherSettings.ForeCircle = themeContainer.GetValue(Toolkit + "VisualRadialProgress/ForeCircle").ToColor();

                _otherSettings.ProgressBackground = themeContainer.GetValue(Shared + "ProgressBar/Background").ToColor();
                _otherSettings.Progress           = themeContainer.GetValue(Shared + "ProgressBar/Working").ToColor();
                _otherSettings.ProgressDisabled   = themeContainer.GetValue(Shared + "ProgressBar/Disabled").ToColor();

                _otherSettings.HatchBackColor = themeContainer.GetValue(Shared + "Hatch/BackColor").ToColor();
                _otherSettings.HatchForeColor = themeContainer.GetValue(Shared + "Hatch/ForeColor").ToColor();

                _otherSettings.FlatControlDisabled = themeContainer.GetValue(Shared + "FlatControl/Enabled").ToColor();
                _otherSettings.FlatControlEnabled  = themeContainer.GetValue(Shared + "FlatControl/Enabled").ToColor();

                _otherSettings.BoxDisabled = themeContainer.GetValue(Shared + "Box/Disabled").ToColor();
                _otherSettings.BoxEnabled  = themeContainer.GetValue(Shared + "Box/Enabled").ToColor();

                _otherSettings.WatermarkActive   = themeContainer.GetValue(Shared + "Watermark/Active").ToColor();
                _otherSettings.WatermarkInactive = themeContainer.GetValue(Shared + "Watermark/Inactive").ToColor();

                _otherSettings.TabPageEnabled  = themeContainer.GetValue(Shared + "TabPage/Enabled").ToColor();
                _otherSettings.TabPageDisabled = themeContainer.GetValue(Shared + "TabPage/Disabled").ToColor();
                _otherSettings.TabPageHover    = themeContainer.GetValue(Shared + "TabPage/Hover").ToColor();
                _otherSettings.TabPageSelected = themeContainer.GetValue(Shared + "TabPage/Selected").ToColor();

                _otherSettings.HelpButtonBack.Disabled = themeContainer.GetValue(Toolkit + "VisualControlBox/HelpButton/BackColorState/Disabled").ToColor();
                _otherSettings.HelpButtonBack.Enabled  = themeContainer.GetValue(Toolkit + "VisualControlBox/HelpButton/BackColorState/Enabled").ToColor();
                _otherSettings.HelpButtonBack.Hover    = themeContainer.GetValue(Toolkit + "VisualControlBox/HelpButton/BackColorState/Hover").ToColor();
                _otherSettings.HelpButtonBack.Pressed  = themeContainer.GetValue(Toolkit + "VisualControlBox/HelpButton/BackColorState/Pressed").ToColor();

                _otherSettings.HelpButtonFore.Disabled = themeContainer.GetValue(Toolkit + "VisualControlBox/HelpButton/ForeColorState/Disabled").ToColor();
                _otherSettings.HelpButtonFore.Enabled  = themeContainer.GetValue(Toolkit + "VisualControlBox/HelpButton/ForeColorState/Enabled").ToColor();
                _otherSettings.HelpButtonFore.Hover    = themeContainer.GetValue(Toolkit + "VisualControlBox/HelpButton/ForeColorState/Hover").ToColor();
                _otherSettings.HelpButtonFore.Pressed  = themeContainer.GetValue(Toolkit + "VisualControlBox/HelpButton/ForeColorState/Pressed").ToColor();

                _otherSettings.MinimizeButtonBack.Disabled = themeContainer.GetValue(Toolkit + "VisualControlBox/MinimizeButton/BackColorState/Disabled").ToColor();
                _otherSettings.MinimizeButtonBack.Enabled  = themeContainer.GetValue(Toolkit + "VisualControlBox/MinimizeButton/BackColorState/Enabled").ToColor();
                _otherSettings.MinimizeButtonBack.Hover    = themeContainer.GetValue(Toolkit + "VisualControlBox/MinimizeButton/BackColorState/Hover").ToColor();
                _otherSettings.MinimizeButtonBack.Pressed  = themeContainer.GetValue(Toolkit + "VisualControlBox/MinimizeButton/BackColorState/Pressed").ToColor();

                _otherSettings.MinimizeButtonFore.Disabled = themeContainer.GetValue(Toolkit + "VisualControlBox/MinimizeButton/ForeColorState/Disabled").ToColor();
                _otherSettings.MinimizeButtonFore.Enabled  = themeContainer.GetValue(Toolkit + "VisualControlBox/MinimizeButton/ForeColorState/Enabled").ToColor();
                _otherSettings.MinimizeButtonFore.Hover    = themeContainer.GetValue(Toolkit + "VisualControlBox/MinimizeButton/ForeColorState/Hover").ToColor();
                _otherSettings.MinimizeButtonFore.Pressed  = themeContainer.GetValue(Toolkit + "VisualControlBox/MinimizeButton/ForeColorState/Pressed").ToColor();

                _otherSettings.MaximizeButtonBack.Disabled = themeContainer.GetValue(Toolkit + "VisualControlBox/MaximizeButton/BackColorState/Disabled").ToColor();
                _otherSettings.MaximizeButtonBack.Enabled  = themeContainer.GetValue(Toolkit + "VisualControlBox/MaximizeButton/BackColorState/Enabled").ToColor();
                _otherSettings.MaximizeButtonBack.Hover    = themeContainer.GetValue(Toolkit + "VisualControlBox/MaximizeButton/BackColorState/Hover").ToColor();
                _otherSettings.MaximizeButtonBack.Pressed  = themeContainer.GetValue(Toolkit + "VisualControlBox/MaximizeButton/BackColorState/Pressed").ToColor();

                _otherSettings.MaximizeButtonFore.Disabled = themeContainer.GetValue(Toolkit + "VisualControlBox/MaximizeButton/ForeColorState/Disabled").ToColor();
                _otherSettings.MaximizeButtonFore.Enabled  = themeContainer.GetValue(Toolkit + "VisualControlBox/MaximizeButton/ForeColorState/Enabled").ToColor();
                _otherSettings.MaximizeButtonFore.Hover    = themeContainer.GetValue(Toolkit + "VisualControlBox/MaximizeButton/ForeColorState/Hover").ToColor();
                _otherSettings.MaximizeButtonFore.Pressed  = themeContainer.GetValue(Toolkit + "VisualControlBox/MaximizeButton/ForeColorState/Pressed").ToColor();

                _otherSettings.CloseButtonBack.Disabled = themeContainer.GetValue(Toolkit + "VisualControlBox/CloseButton/BackColorState/Disabled").ToColor();
                _otherSettings.CloseButtonBack.Enabled  = themeContainer.GetValue(Toolkit + "VisualControlBox/CloseButton/BackColorState/Enabled").ToColor();
                _otherSettings.CloseButtonBack.Hover    = themeContainer.GetValue(Toolkit + "VisualControlBox/CloseButton/BackColorState/Hover").ToColor();
                _otherSettings.CloseButtonBack.Pressed  = themeContainer.GetValue(Toolkit + "VisualControlBox/CloseButton/BackColorState/Pressed").ToColor();

                _otherSettings.CloseButtonFore.Disabled = themeContainer.GetValue(Toolkit + "VisualControlBox/CloseButton/ForeColorState/Disabled").ToColor();
                _otherSettings.CloseButtonFore.Enabled  = themeContainer.GetValue(Toolkit + "VisualControlBox/CloseButton/ForeColorState/Enabled").ToColor();
                _otherSettings.CloseButtonFore.Hover    = themeContainer.GetValue(Toolkit + "VisualControlBox/CloseButton/ForeColorState/Hover").ToColor();
                _otherSettings.CloseButtonFore.Pressed  = themeContainer.GetValue(Toolkit + "VisualControlBox/CloseButton/ForeColorState/Pressed").ToColor();
            }
            catch (Exception e)
            {
                VisualExceptionDialog.Show(e);
            }
        }
Exemple #20
0
        private void BtnRunTest_Click(object sender, EventArgs e)
        {
            VisualForm _formToOpen;

            switch (_unitTest)
            {
            case UnitTests.VisualForm:
            {
                _formToOpen = new VisualForm($@"{nameof(VisualForm)} Test");
                _formToOpen.ShowDialog();
                break;
            }

            case UnitTests.VisualControlBox:
            {
                _formToOpen = new VisualControlBoxTest();
                _formToOpen.ShowDialog();
                break;
            }

            case UnitTests.VisualListView:
            {
                _formToOpen = new VisualListViewTest();
                _formToOpen.ShowDialog();
                break;
            }

            case UnitTests.VisualMessageBox:
            {
                _formToOpen = new VisualMessageBoxTest();
                _formToOpen.ShowDialog();
                break;
            }

            case UnitTests.VisualInputDialog:
            {
                VisualInputDialog inputDialog = new VisualInputDialog($@"{nameof(VisualInputDialog)} Test");

                if (inputDialog.ShowDialog() == DialogResult.OK)
                {
                    ConsoleEx.WriteDebug(inputDialog.InputResult);
                }

                break;
            }

            case UnitTests.VisualExceptionDialog:
            {
                VisualExceptionDialog.Show(new Exception("Your custom exception message."));
                break;
            }

            case UnitTests.VisualColorDialog:
            {
                VisualColorDialog colorDialog = new VisualColorDialog();

                if (colorDialog.ShowDialog() == DialogResult.OK)
                {
                    ConsoleEx.WriteDebug(colorDialog.Color);
                }

                break;
            }

            case UnitTests.ClipboardTest:
            {
                _formToOpen = new ClipboardTest();
                _formToOpen.ShowDialog();
                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException();
            }
            }
        }
Exemple #21
0
        /// <summary>
        ///     Begins downloading the files.
        /// </summary>
        private void BeginDownload()
        {
            DownloadData _downloadData = null;
            FileStream   _fileStream   = null;

            try
            {
                FileManager.CreateDirectory(_downloadDirectory);

                // Start the stop stop watch for speed calculation.
                _stopWatch.Start();

                // Receive download details
                _waitingForResponse = true;

                _downloadData = new DownloadData(_currentUrl, _downloadDirectory);
                _downloadData.Create();

                _waitingForResponse = false;

                // Reset the adler
                _downloaderAdler32.Reset();

                DownloadingTo = _downloadData.OutputFilePath;
                _downloadedFiles.Add(DownloadingTo);

                if (!File.Exists(DownloadingTo))
                {
                    // Create the file.
                    _fileStream = File.Open(DownloadingTo, FileMode.Create, FileAccess.Write);
                }
                else
                {
                    // Read in the existing data to calculate the Adler32
                    if (Adler32 != 0)
                    {
                        GetAdler32(DownloadingTo);
                    }

                    // Append to an existing file (resume the download)
                    _fileStream = File.Open(DownloadingTo, FileMode.Append, FileAccess.Write);
                }

                var _buffer = new byte[_bufferSize];
                int _readCount;

                // Update how many bytes have already been read.
                _sentSinceLastCalc = _downloadData.StartPoint; // For BPS (bytes/per second) calculation

                // Only increment once for each %.
                var _lastProgress = 0;
                while ((_readCount = _downloadData.DownloadStream.Read(_buffer, 0, _bufferSize)) > 0)
                {
                    // Break on cancel
                    if (_backgroundDownloader.CancellationPending)
                    {
                        _downloadData.Close();
                        _fileStream.Close();
                        break;
                    }

                    // Update total bytes read
                    _downloadData.StartPoint += _readCount;

                    // Update the Adler32 value
                    if (Adler32 != 0)
                    {
                        _downloaderAdler32.Update(_buffer, 0, _readCount);
                    }

                    // Save block to end of file
                    _fileStream.Write(_buffer, 0, _readCount);

                    CalculateBps(_downloadData.StartPoint, _downloadData.TotalDownloadSize);

                    // Send progress info.
                    if (!_backgroundDownloader.CancellationPending && (_downloadData.PercentDone > _lastProgress))
                    {
                        _backgroundDownloader.ReportProgress(0, new object[]
                        {
                            // use the relative or the raw progress.
                            UseRelativeProgress?GetRelativeProgress(0, _downloadData.PercentDone) : _downloadData.PercentDone,

                                // unweighted percent
                                _downloadData.PercentDone,
                                _downloadSpeed, ProgressStatus.None, null
                        });

                        _lastProgress = _downloadData.PercentDone;
                    }

                    // Break on cancel
                    if (_backgroundDownloader.CancellationPending)
                    {
                        _downloadData.Close();
                        _fileStream.Close();
                        break;
                    }
                }
            }
            catch (UriFormatException e)
            {
                VisualExceptionDialog.Show(new Exception($"Could not parse the URL \"{_currentUrl}\" - it's either malformed or is an unknown protocol.", e));
            }
            catch (Exception e)
            {
                if (string.IsNullOrEmpty(DownloadingTo))
                {
                    VisualExceptionDialog.Show(new Exception($"Error trying to save file: {e.Message}", e));
                }
                else
                {
                    VisualExceptionDialog.Show(new Exception($"Error trying to save file \"{DownloadingTo}\": {e.Message}", e));
                }
            }
            finally
            {
                _downloadData?.Close();
                _fileStream?.Close();
            }
        }
        public void UpdateTheme(Theme theme)
        {
            try
            {
                _closeButton.BackColorState = new ControlColorState
                {
                    Disabled = theme.OtherSettings.CloseButtonBack.Disabled,
                    Enabled  = theme.OtherSettings.CloseButtonBack.Enabled,
                    Hover    = theme.OtherSettings.CloseButtonBack.Hover,
                    Pressed  = theme.OtherSettings.CloseButtonBack.Pressed
                };

                _closeButton.ForeColorState = new ControlColorState
                {
                    Disabled = theme.OtherSettings.CloseButtonFore.Disabled,
                    Enabled  = theme.OtherSettings.CloseButtonFore.Enabled,
                    Hover    = theme.OtherSettings.CloseButtonFore.Hover,
                    Pressed  = theme.OtherSettings.CloseButtonFore.Pressed
                };

                _maximizeButton.BackColorState = new ControlColorState
                {
                    Disabled = theme.OtherSettings.MaximizeButtonBack.Disabled,
                    Enabled  = theme.OtherSettings.MaximizeButtonBack.Enabled,
                    Hover    = theme.OtherSettings.MaximizeButtonBack.Hover,
                    Pressed  = theme.OtherSettings.MaximizeButtonBack.Pressed
                };

                _maximizeButton.ForeColorState = new ControlColorState
                {
                    Disabled = theme.OtherSettings.MaximizeButtonFore.Disabled,
                    Enabled  = theme.OtherSettings.MaximizeButtonFore.Enabled,
                    Hover    = theme.OtherSettings.MaximizeButtonFore.Hover,
                    Pressed  = theme.OtherSettings.MaximizeButtonFore.Pressed
                };

                _minimizeButton.BackColorState = new ControlColorState
                {
                    Disabled = theme.OtherSettings.MinimizeButtonBack.Disabled,
                    Enabled  = theme.OtherSettings.MinimizeButtonBack.Enabled,
                    Hover    = theme.OtherSettings.MinimizeButtonBack.Hover,
                    Pressed  = theme.OtherSettings.MinimizeButtonBack.Pressed
                };

                _minimizeButton.ForeColorState = new ControlColorState
                {
                    Disabled = theme.OtherSettings.MinimizeButtonFore.Disabled,
                    Enabled  = theme.OtherSettings.MinimizeButtonFore.Enabled,
                    Hover    = theme.OtherSettings.MinimizeButtonFore.Hover,
                    Pressed  = theme.OtherSettings.MinimizeButtonFore.Pressed
                };

                _helpButton.BackColorState = new ControlColorState
                {
                    Disabled = theme.OtherSettings.HelpButtonBack.Disabled,
                    Enabled  = theme.OtherSettings.HelpButtonBack.Enabled,
                    Hover    = theme.OtherSettings.HelpButtonBack.Hover,
                    Pressed  = theme.OtherSettings.HelpButtonBack.Pressed
                };

                _helpButton.ForeColorState = new ControlColorState
                {
                    Disabled = theme.OtherSettings.HelpButtonFore.Disabled,
                    Enabled  = theme.OtherSettings.HelpButtonFore.Enabled,
                    Hover    = theme.OtherSettings.HelpButtonFore.Hover,
                    Pressed  = theme.OtherSettings.HelpButtonFore.Pressed
                };
            }
            catch (Exception e)
            {
                VisualExceptionDialog.Show(e);
            }

            Invalidate();
            OnThemeChanged(new ThemeEventArgs(theme));
        }
Exemple #23
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            try
            {
                Graphics graphics = e.Graphics;
                graphics.SmoothingMode      = SmoothingMode.HighQuality;
                graphics.CompositingQuality = CompositingQuality.GammaCorrected;

                Size      textArea = GraphicsManager.MeasureText(Text, Font, graphics);
                Rectangle group    = ConfigureStyleBox(textArea);
                Rectangle title    = ConfigureStyleTitleBox(textArea);

                _titleBoxRectangle = new Rectangle(title.X, title.Y, title.Width - 1, title.Height);

                Rectangle _clientRectangle = new Rectangle(group.X, group.Y, group.Width, group.Height);
                ControlGraphicsPath = VisualBorderRenderer.CreateBorderTypePath(_clientRectangle, _border);
                graphics.FillRectangle(new SolidBrush(BackColor), _clientRectangle);

                Color _backColor = Enabled ? BackColorState.Enabled : BackColorState.Disabled;
                VisualBackgroundRenderer.DrawBackground(e.Graphics, _backColor, BackgroundImage, MouseState, group, Border);

                if (_borderEdge.Visible)
                {
                    _borderEdge.Location = new Point(_titleBoxRectangle.X + _border.Thickness, _titleBoxRectangle.Bottom);
                    _borderEdge.Size     = new Size(Width - _border.Thickness - 1, 1);
                }

                VisualBorderRenderer.DrawBorderStyle(e.Graphics, _border, ControlGraphicsPath, MouseState);

                if (_boxStyle == GroupBoxStyle.Classic)
                {
                    Size _newSize;
                    if (_image != null)
                    {
                        _newSize = _image.Size;
                    }
                    else
                    {
                        _newSize = new Size(0, 0);
                    }

                    Point _titleBoxBackground = RelationManager.GetTextImageRelationLocation(graphics, _textImageRelation, new Rectangle(new Point(0, 0), _newSize), Text, Font, _titleBoxRectangle, false);
                    graphics.FillRectangle(new SolidBrush(BackColorState.Enabled), new Rectangle(new Point(_titleBoxBackground.X, _titleBoxBackground.Y), new Size(_titleBoxRectangle.Width, _titleBoxRectangle.Height)));
                }

                if (_image != null)
                {
                    VisualControlRenderer.DrawContent(e.Graphics, _titleBoxRectangle, Text, Font, ForeColor, _image, _image.Size, _textImageRelation);
                }
                else
                {
                    StringFormat _stringFormat = new StringFormat
                    {
                        Alignment     = _textAlignment,
                        LineAlignment = _textLineAlignment
                    };

                    VisualControlRenderer.DrawContentText(e.Graphics, _titleBoxRectangle, Text, Font, ForeColor, _stringFormat);
                }
            }
            catch (Exception exception)
            {
                VisualExceptionDialog.Show(exception);
                throw;
            }
        }