示例#1
0
        public override Size GetPreferredSize(Size proposedSize)
        {
            Size preferredSize;

            base.GetPreferredSize(proposedSize);

            using (var g = CreateGraphics())
            {
                proposedSize  = new Size(int.MaxValue, int.MaxValue);
                preferredSize = TextRenderer.MeasureText(g, Text, WellsMetroFonts.Label(metroLabelSize, metroLabelWeight), proposedSize, WellsMetroPaint.GetTextFormatFlags(TextAlign));
            }

            return(preferredSize);
        }
示例#2
0
        private void CreateBaseTextBox()
        {
            if (baseTextBox.Visible && !firstInitialization)
            {
                return;
            }
            if (!firstInitialization)
            {
                return;
            }

            firstInitialization = false;

            if (!DesignMode)
            {
                Form parentForm = FindForm();
                if (parentForm != null)
                {
                    parentForm.ResizeBegin += new EventHandler(parentForm_ResizeBegin);
                    parentForm.ResizeEnd   += new EventHandler(parentForm_ResizeEnd);
                }
            }

            baseTextBox.BackColor   = Color.Transparent;
            baseTextBox.Visible     = true;
            baseTextBox.BorderStyle = BorderStyle.None;
            baseTextBox.Font        = WellsMetroFonts.Label(metroLabelSize, metroLabelWeight);
            baseTextBox.Location    = new Point(1, 0);
            baseTextBox.Text        = Text;
            baseTextBox.ReadOnly    = true;

            baseTextBox.Size      = GetPreferredSize(Size.Empty);
            baseTextBox.Multiline = true;

            baseTextBox.DoubleClick += BaseTextBoxOnDoubleClick;
            baseTextBox.Click       += BaseTextBoxOnClick;

            Controls.Add(baseTextBox);
        }
示例#3
0
        private void UpdateBaseTextBox()
        {
            if (!baseTextBox.Visible)
            {
                return;
            }

            SuspendLayout();
            baseTextBox.SuspendLayout();

            if (useCustomBackColor)
            {
                baseTextBox.BackColor = BackColor;
            }
            else
            {
                baseTextBox.BackColor = WellsMetroPaint.BackColor.Form(Theme);
            }

            if (!Enabled)
            {
                if (Parent != null)
                {
                    if (Parent is WellsMetroTile)
                    {
                        baseTextBox.ForeColor = WellsMetroPaint.ForeColor.Tile.Disabled(Theme);
                    }
                    else
                    {
                        if (useStyleColors)
                        {
                            baseTextBox.ForeColor = WellsMetroPaint.GetStyleColor(Style);
                        }
                        else
                        {
                            baseTextBox.ForeColor = WellsMetroPaint.ForeColor.Label.Disabled(Theme);
                        }
                    }
                }
                else
                {
                    if (useStyleColors)
                    {
                        baseTextBox.ForeColor = WellsMetroPaint.GetStyleColor(Style);
                    }
                    else
                    {
                        baseTextBox.ForeColor = WellsMetroPaint.ForeColor.Label.Disabled(Theme);
                    }
                }
            }
            else
            {
                if (Parent != null)
                {
                    if (Parent is WellsMetroTile)
                    {
                        baseTextBox.ForeColor = WellsMetroPaint.ForeColor.Tile.Normal(Theme);
                    }
                    else
                    {
                        if (useStyleColors)
                        {
                            baseTextBox.ForeColor = WellsMetroPaint.GetStyleColor(Style);
                        }
                        else
                        {
                            baseTextBox.ForeColor = WellsMetroPaint.ForeColor.Label.Normal(Theme);
                        }
                    }
                }
                else
                {
                    if (useStyleColors)
                    {
                        baseTextBox.ForeColor = WellsMetroPaint.GetStyleColor(Style);
                    }
                    else
                    {
                        baseTextBox.ForeColor = WellsMetroPaint.ForeColor.Label.Normal(Theme);
                    }
                }
            }

            baseTextBox.Font        = WellsMetroFonts.Label(metroLabelSize, metroLabelWeight);
            baseTextBox.Text        = Text;
            baseTextBox.BorderStyle = BorderStyle.None;

            Size = GetPreferredSize(Size.Empty);

            baseTextBox.ResumeLayout();
            ResumeLayout();
        }
示例#4
0
        protected virtual void OnPaintForeground(PaintEventArgs e)
        {
            Color foreColor;

            if (useCustomForeColor)
            {
                foreColor = ForeColor;
            }
            else
            {
                if (!Enabled)
                {
                    if (Parent != null)
                    {
                        if (Parent is WellsMetroTile)
                        {
                            foreColor = WellsMetroPaint.ForeColor.Tile.Disabled(Theme);
                        }
                        else
                        {
                            foreColor = WellsMetroPaint.ForeColor.Label.Normal(Theme);
                        }
                    }
                    else
                    {
                        foreColor = WellsMetroPaint.ForeColor.Label.Disabled(Theme);
                    }
                }
                else
                {
                    if (Parent != null)
                    {
                        if (Parent is WellsMetroTile)
                        {
                            foreColor = WellsMetroPaint.ForeColor.Tile.Normal(Theme);
                        }
                        else
                        {
                            if (useStyleColors)
                            {
                                foreColor = WellsMetroPaint.GetStyleColor(Style);
                            }
                            else
                            {
                                foreColor = WellsMetroPaint.ForeColor.Label.Normal(Theme);
                            }
                        }
                    }
                    else
                    {
                        if (useStyleColors)
                        {
                            foreColor = WellsMetroPaint.GetStyleColor(Style);
                        }
                        else
                        {
                            foreColor = WellsMetroPaint.ForeColor.Label.Normal(Theme);
                        }
                    }
                }
            }

            if (LabelMode == WellsMetroLabelMode.Selectable)
            {
                CreateBaseTextBox();
                UpdateBaseTextBox();

                if (!baseTextBox.Visible)
                {
                    TextRenderer.DrawText(e.Graphics, Text, WellsMetroFonts.Label(metroLabelSize, metroLabelWeight), ClientRectangle, foreColor, WellsMetroPaint.GetTextFormatFlags(TextAlign));
                }
            }
            else
            {
                DestroyBaseTextbox();
                TextRenderer.DrawText(e.Graphics, Text, WellsMetroFonts.Label(metroLabelSize, metroLabelWeight), ClientRectangle, foreColor, WellsMetroPaint.GetTextFormatFlags(TextAlign, wrapToLine));
                OnCustomPaintForeground(new WellsMetroPaintEventArgs(Color.Empty, foreColor, e.Graphics));
            }
        }