ComponentFactory.Krypton.Toolkit.KryptonWrapLabel.UpdateFont C# (CSharp) Method

UpdateFont() private method

private UpdateFont ( ) : void
return void
        public void UpdateFont()
        {
            Font font = null;
            Color textColor = Color.Empty;
            PaletteTextHint hint = PaletteTextHint.Inherit;
            PaletteState ps = PaletteState.Normal;

            // Get values from correct enabled/disabled state
            if (Enabled)
            {
                font = _stateNormal.Font;
                textColor = _stateNormal.TextColor;
                hint = _stateNormal.Hint;
            }
            else
            {
                font = _stateDisabled.Font;
                textColor = _stateDisabled.TextColor;
                hint = _stateDisabled.Hint;
                ps = PaletteState.Disabled;
            }

            // Recover font from state common or as last resort the inherited palette
            if (font == null)
            {
                font = _stateCommon.Font;
                if (font == null)
                    font = _redirector.GetContentShortTextFont(_labelContentStyle, ps);
            }

            // Recover text color from state common or as last resort the inherited palette
            if (textColor == Color.Empty)
            {
                textColor = _stateCommon.TextColor;
                if (textColor == Color.Empty)
                    textColor = _redirector.GetContentShortTextColor1(_labelContentStyle, ps);
            }

            // Recover text hint from state common or as last resort the inherited palette
            if (hint == PaletteTextHint.Inherit)
            {
                hint = _stateCommon.Hint;
                if (hint == PaletteTextHint.Inherit)
                    hint = _redirector.GetContentShortTextHint(_labelContentStyle, ps);
            }

            // Only update the font when the control is created
            if (Handle != IntPtr.Zero)
                Font = font;
        }

Usage Example

Esempio n. 1
0
        private Size UpdatePromptSizing()
        {
            // Update size of the message label but with a maximum width
            using (Graphics g = CreateGraphics())
            {
                // Find size of the label when it has a maximum length of 250, this tells us the height
                // required to fully show the label with the prompt.
                _labelPrompt.UpdateFont();
                Size messageSize = g.MeasureString(_prompt, _labelPrompt.Font, 250).ToSize();

                // Work out DPI adjustment factor
                messageSize.Width  = (int)(messageSize.Width * DpiHelper.Default.DpiScaleFactor);
                messageSize.Height = (int)(messageSize.Height * DpiHelper.Default.DpiScaleFactor);

                _labelPrompt.Location = new Point(GAP, GAP);
                _labelPrompt.Size     = new Size(255, Math.Max(messageSize.Height, _buttonCancel.Bottom - _buttonOK.Top));

                return(new Size(_labelPrompt.Right, _labelPrompt.Bottom));
            }
        }