/// <summary> /// Sets <c>Fonts</c> for a <c><see cref="YataDialog"/></c>. /// </summary> /// <param name="f">a <c><see cref="YataDialog"/></c></param> /// <param name="bypassColor"><c>true</c> to set the <c>TextBoxBase's</c> /// <c>BackColor</c> to the Yata-default.</param> /// <param name="bypassFont"><c>true</c> to bypass setting the dialog's /// <c>Font</c></param> /// <remarks>IMPORTANT: Make sure that the <c>Font</c> for any /// <c>TextBoxBases</c> ARE INSTANTIATED in the Designer - this funct /// will <c>Dispose()</c> those <c>Fonts</c>. If a <c>TextBoxBase</c> /// happens to use the .net default <c>Font</c> it will get disposed and /// then the app is borked since the .net default <c>Font</c> will no /// longer be available at all.</remarks> internal static void SetFonts(YataDialog f, bool bypassColor, bool bypassFont) { if (!bypassFont) { if (_font2dialog != null) { f.Font = _font2dialog; } else { f.Font = _fontdialog; } } foreach (var tbb in f._tbbs) { if (_fontf != null) { tbb.Font.Dispose(); if (tbb is RichTextBox) { tbb.Font = _fontf; } else { tbb.Font = _fontf_tb; // is TextBox } } if (!bypassColor) { tbb.BackColor = Colors.TextboxBackground; } } }
/// <summary> /// cTor. /// </summary> /// <param name="title">a caption on the titlebar</param> /// <param name="head">info to be displayed with a proportional font - /// keep this fairly brief</param> /// <param name="copyable">info to be displayed in a fixed-width font as /// readily copyable text - can be <c>null</c></param> /// <param name="ibt">an <c><see cref="InfoboxType"/></c> to deter the /// backcolor of <c><see cref="la_head"/></c></param> /// <param name="buttons"><c><see cref="InfoboxButtons"/></c> to show to /// the user</param> internal Infobox( string title, string head, string copyable = null, InfoboxType ibt = InfoboxType.Info, InfoboxButtons buttons = InfoboxButtons.Okay) { // TODO: Store static location and size of the Infobox (if shown non-modally). InitializeComponent(); if (copyable != null) { InitializePanel(); pa_Copyable.BringToFront(); YataDialog.SetTabs(rt_Copyable); if (Settings._fontf != null) { rt_Copyable.Font.Dispose(); rt_Copyable.Font = Settings._fontf; } } else { la_head.Dock = DockStyle.Fill; } if (Settings._fonti != null) { Font.Dispose(); Font = Settings._fonti; } Text = title; switch (ibt) { case InfoboxType.Info: la_head.BackColor = Color.Lavender; break; case InfoboxType.Warn: la_head.BackColor = Color.Moccasin; break; case InfoboxType.Error: la_head.BackColor = Color.SandyBrown; break; } switch (buttons) { case InfoboxButtons.Okay: bu_Cancel.Text = "ok"; break; case InfoboxButtons.CancelYes: bu_Okay.Text = "yes"; bu_Okay.Visible = true; break; case InfoboxButtons.AbortLoadNext: bu_Cancel.Text = "abort"; bu_Okay.Text = "load"; bu_Retry.Text = "next"; bu_Okay.Visible = bu_Retry.Visible = true; break; case InfoboxButtons.Abort: bu_Cancel.Text = "abort"; break; } SuspendLayout(); int client_w = 0; int client_h = 0; int widthScroller = SystemInformation.VerticalScrollBarWidth; string[] lines; if (copyable != null) { lines = copyable.Split(gs.CRandorLF, StringSplitOptions.None); int test; foreach (var line in lines) { test = TextRenderer.MeasureText(line, rt_Copyable.Font).Width; if (test > client_w) { client_w = test; } } client_w += pa_Copyable.Padding.Horizontal + widthScroller; client_h = rt_Copyable.Font.Height + 1; pa_Copyable.Height = client_h * (lines.Length + 1) + pa_Copyable.Padding.Vertical; rt_Copyable.Text = copyable + Environment.NewLine; } if (client_w < w_Min) { client_w = w_Min; } else if (client_w > w_Max) { client_w = w_Max; } int lineshead; if (TextRenderer.MeasureText(head, la_head.Font).Width + la_head.Padding.Horizontal > client_w) { lines = SplitString(head, client_w - la_head.Padding.Horizontal, la_head.Font); lineshead = lines.Length; head = String.Empty; for (int i = 0; i != lineshead; ++i) { if (i != 0) { head += Environment.NewLine; } head += lines[i]; } } else { lineshead = 1; } la_head.Text = head; client_h = la_head.Font.Height + 1; la_head.Height = client_h * lineshead + la_head.Padding.Vertical + 1; client_h = la_head.Height + (pa_Copyable != null ? pa_Copyable.Height : 0) + pa_buttons.Height; if (client_h > h_Max) { client_h = h_Max; } ClientSize = new Size(client_w + 2, client_h + 1); // pad. MinimumSize = new Size(Width, Height); ResumeLayout(); bu_Cancel.Select(); }