예제 #1
0
        /// <summary>
        /// Creates the base text box.
        /// </summary>
        private void CreateBaseTextBox()
        {
            if (this._baseTextBox.Visible && !this._firstInitialization)
            {
                return;
            }

            if (!this._firstInitialization)
            {
                return;
            }

            this._firstInitialization = false;

            if (!this.DesignMode)
            {
                Form parentForm = this.FindForm();

                if (parentForm != null)
                {
                    parentForm.ResizeBegin += this.OnParentFormResizeBegin;
                    parentForm.ResizeEnd   += this.OnParentFormResizeEnd;
                }
            }

            this._baseTextBox.BackColor   = Color.Transparent;
            this._baseTextBox.Visible     = true;
            this._baseTextBox.BorderStyle = BorderStyle.None;
            this._baseTextBox.Font        = ModernFonts.Label(this.FontSize, this.FontWeight);
            this._baseTextBox.Location    = new Point(1, 0);
            this._baseTextBox.Text        = this.Text;
            this._baseTextBox.ReadOnly    = true;

            this._baseTextBox.Size      = this.GetPreferredSize(Size.Empty);
            this._baseTextBox.Multiline = true;

            this._baseTextBox.DoubleClick += this.BaseTextBoxOnDoubleClick;
            this._baseTextBox.Click       += this.BaseTextBoxOnClick;

            this.Controls.Add(this._baseTextBox);
        }
예제 #2
0
        /// <summary>
        /// Updates the base text box.
        /// </summary>
        private void UpdateBaseTextBox()
        {
            if (!this._baseTextBox.Visible)
            {
                return;
            }

            this.SuspendLayout();
            this._baseTextBox.SuspendLayout();

            if (this.UseCustomBackColor)
            {
                this._baseTextBox.BackColor = this.BackColor;
            }
            else
            {
                this._baseTextBox.BackColor = ModernPaint.BackColor.Form(this.ThemeStyle);
            }

            if (!this.Enabled)
            {
                if (this.Parent != null)
                {
                    if (this.Parent is ModernTile)
                    {
                        this._baseTextBox.ForeColor = ModernPaint.ForeColor.Tile.Disabled(this.ThemeStyle);
                    }
                    else
                    {
                        if (this.UseStyleColors)
                        {
                            this._baseTextBox.ForeColor = ModernPaint.GetStyleColor(this.ColorStyle);
                        }
                        else
                        {
                            this._baseTextBox.ForeColor = ModernPaint.ForeColor.Label.Disabled(this.ThemeStyle);
                        }
                    }
                }
                else
                {
                    if (this.UseStyleColors)
                    {
                        this._baseTextBox.ForeColor = ModernPaint.GetStyleColor(this.ColorStyle);
                    }
                    else
                    {
                        this._baseTextBox.ForeColor = ModernPaint.ForeColor.Label.Disabled(this.ThemeStyle);
                    }
                }
            }
            else
            {
                if (this.Parent != null)
                {
                    if (this.Parent is ModernTile)
                    {
                        this._baseTextBox.ForeColor = ModernPaint.ForeColor.Tile.Normal(this.ThemeStyle);
                    }
                    else
                    {
                        if (this.UseStyleColors)
                        {
                            this._baseTextBox.ForeColor = ModernPaint.GetStyleColor(this.ColorStyle);
                        }
                        else
                        {
                            this._baseTextBox.ForeColor = ModernPaint.ForeColor.Label.Normal(this.ThemeStyle);
                        }
                    }
                }
                else
                {
                    if (this.UseStyleColors)
                    {
                        this._baseTextBox.ForeColor = ModernPaint.GetStyleColor(this.ColorStyle);
                    }
                    else
                    {
                        this._baseTextBox.ForeColor = ModernPaint.ForeColor.Label.Normal(this.ThemeStyle);
                    }
                }
            }

            this._baseTextBox.Font        = ModernFonts.Label(this.FontSize, this.FontWeight);
            this._baseTextBox.Text        = this.Text;
            this._baseTextBox.BorderStyle = BorderStyle.None;

            this.Size = this.GetPreferredSize(Size.Empty);

            this._baseTextBox.ResumeLayout();
            this.ResumeLayout();
        }
예제 #3
0
        /// <summary>
        /// Raises the <see cref="E:PaintForeground" /> event.
        /// </summary>
        /// <param name="e">The <see cref="PaintEventArgs"/> instance containing the event data.</param>
        protected virtual void OnPaintForeground(PaintEventArgs e)
        {
            Color foreColor;

            if (this.UseCustomForeColor)
            {
                foreColor = this.ForeColor;
            }
            else
            {
                if (!this.Enabled)
                {
                    if (this.Parent != null)
                    {
                        if (this.Parent is ModernTile)
                        {
                            foreColor = ModernPaint.ForeColor.Tile.Disabled(this.ThemeStyle);
                        }
                        else
                        {
                            foreColor = ModernPaint.ForeColor.Label.Normal(this.ThemeStyle);
                        }
                    }
                    else
                    {
                        foreColor = ModernPaint.ForeColor.Label.Disabled(this.ThemeStyle);
                    }
                }
                else
                {
                    if (this.Parent != null)
                    {
                        if (this.Parent is ModernTile)
                        {
                            foreColor = ModernPaint.ForeColor.Tile.Normal(this.ThemeStyle);
                        }
                        else
                        {
                            if (this.UseStyleColors)
                            {
                                foreColor = ModernPaint.GetStyleColor(this.ColorStyle);
                            }
                            else
                            {
                                foreColor = ModernPaint.ForeColor.Label.Normal(this.ThemeStyle);
                            }
                        }
                    }
                    else
                    {
                        if (this.UseStyleColors)
                        {
                            foreColor = ModernPaint.GetStyleColor(this.ColorStyle);
                        }
                        else
                        {
                            foreColor = ModernPaint.ForeColor.Label.Normal(this.ThemeStyle);
                        }
                    }
                }
            }

            if (this.CanSelectText)
            {
                this.CreateBaseTextBox();
                this.UpdateBaseTextBox();

                if (!this._baseTextBox.Visible)
                {
                    TextRenderer.DrawText(e.Graphics, this.Text, ModernFonts.Label(this.FontSize, this.FontWeight), this.ClientRectangle, foreColor, ModernPaint.GetTextFormatFlags(this.TextAlign));
                }
            }
            else
            {
                this.DestroyBaseTextbox();
                TextRenderer.DrawText(e.Graphics, this.Text, ModernFonts.Label(this.FontSize, this.FontWeight), this.ClientRectangle, foreColor, ModernPaint.GetTextFormatFlags(this.TextAlign, this.WordWrap));
                this.OnCustomPaintForeground(new ModernPaintEventArgs(Color.Empty, foreColor, e.Graphics));
            }
        }
예제 #4
0
        /// <summary>
        /// Retrieves the size of a rectangular area into which a control can be fitted.
        /// </summary>
        /// <param name="proposedSize">The custom-sized area for a control.</param>
        /// <returns>An ordered pair of type <see cref="T:System.Drawing.Size" /> representing the width and height of a rectangle.</returns>
        public override Size GetPreferredSize(Size proposedSize)
        {
            Size preferredSize;

            base.GetPreferredSize(proposedSize);

            using (Graphics g = this.CreateGraphics())
            {
                proposedSize  = new Size(int.MaxValue, int.MaxValue);
                preferredSize = TextRenderer.MeasureText(g, this.Text ?? string.Empty, ModernFonts.Label(this.FontSize, this.FontWeight), proposedSize, ModernPaint.GetTextFormatFlags(this.TextAlign));
            }

            return(preferredSize);
        }