/// <summary> /// Returns max size to fit button text, plus some /// </summary> /// <param name="ctrl">CButton control to measure text from</param> /// <returns>Int of the max size</returns> public static int GetMaxPanelWidth(CButton ctrl) { var myFont = new Font(ctrl.Font.FontFamily, ctrl.Font.Size); var mySize = ctrl.CreateGraphics().MeasureString(ctrl.Text, myFont); return(((int)(Math.Round(mySize.Width, 0))) + 26); }
// Add top search item to panel public static CButton AddTopSearchTag(string text, int count) { var a = new CButton { Text = text, TextAlign = ContentAlignment.MiddleCenter, Font = new Font("Segoe UI Semibold", 9.25F, FontStyle.Regular), Size = new Size(70, 24), BackColor = Color.Transparent, ForeColor = Colors.ColorOrange, TextMargin = new Padding(0, 2, 0, 2), BorderColor = Colors.ColorOrange, ColorFillSolid = Color.Transparent, FillType = CButton.eFillType.Solid, TextShadowShow = false, ShowFocus = CButton.eFocus.None, Margin = new Padding(0, 3, 6, 3), BorderShow = true, DimFactorClick = 0, DimFactorHover = 0, Cursor = Cursors.Hand, Name = "tagItem" + count, Corners = new CornersProperty(2), }; var myFont = new Font(a.Font.FontFamily, a.Font.Size); var mySize = a.CreateGraphics().MeasureString(a.Text, myFont); a.Width = (((int)(Math.Round(mySize.Width, 0))) + 10); a.ClickButtonArea += BtnTopSearchesTag_ClickButtonArea; a.MouseEnter += BtnCButton_MouseEnter; a.MouseLeave += BtnCButton_MouseLeave; return(a); }
/// <summary> /// Change button text and auto size /// </summary> /// <param name="ctrl">CButton control to set text</param> /// <param name="text">Text to set to control</param> public static void SetControlText(CButton ctrl, string text) { ctrl.Text = text; var myFont = new Font(ctrl.Font.FontFamily, ctrl.Font.Size); var mySize = ctrl.CreateGraphics().MeasureString(ctrl.Text, myFont); ctrl.Width = (((int)(Math.Round(mySize.Width, 0))) + 46); }