public static void UpdateFont(Control ctl, Font oldFont, Font newFont) { if (!oldFont.Equals(newFont)) { foreach (Control c in ctl.Controls) { UpdateFont(c, oldFont, newFont); } if (ctl.Font != newFont) { if (ctl.Font.FontFamily.Name == oldFont.FontFamily.Name) { ctl.Font = new Font(newFont.FontFamily, ctl.Font.SizeInPoints * (newFont.SizeInPoints / oldFont.SizeInPoints), ctl.Font.Style); } } } }
public static void UpdateFormFont(Form form, Font oldFont, Font newFont) { if (!oldFont.Equals(newFont)) { UpdateFont(form, oldFont, newFont); // Minimise and restore the window to correct any layout errors. // Temporarily disable minimise/restore animation because it should not be visible anyway. bool animationEnabled = WinApi.IsMinimizeRestoreAnimationEnabled(); if (animationEnabled) WinApi.SetMinimizeRestoreAnimation(false); FormWindowState prevState = form.WindowState; form.WindowState = FormWindowState.Minimized; form.WindowState = prevState; if (animationEnabled) WinApi.SetMinimizeRestoreAnimation(true); } }
/// <summary> /// This procedure sets the default font for this control. /// /// </summary> /// <returns>void</returns> protected void SetDefaultFont() { if (FSettingDefaultFont) { return; } FSettingDefaultFont = true; System.Drawing.Font mControlFont = this.Font; System.Drawing.Font mTextBoxFont = this.txtTextBox.Font; System.Single mFontSize = 9.25F; System.Drawing.Font mFont = new System.Drawing.Font("Courier New", mFontSize, System.Drawing.FontStyle.Bold); if ((!(mControlFont.Equals(mFont))) || (!(mTextBoxFont.Equals(mFont)))) { // MessageBox.Show(mFont.FontFamily.GetName(-1) + " " + mControlFont.FontFamily.GetName(-1) + " " + mTextBoxFont.FontFamily.GetName(-1)); // on Mono the message box displays: Courier New Lucida Console Microsoft Sans Serif this.Font = mFont; this.txtTextBox.Font = mFont; } FSettingDefaultFont = false; }
public static void WriteRegistry(Font tabFont, string[] strsTextExts, string[] strsImgExts) { InitializeStaticFields(); using(RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\Quizo\QTTabBar")) { if(key != null) { key.SetValue("Config", QTUtility.ConfigValues); key.SetValue("TabWidth", QTUtility.TabWidth); key.SetValue("TabHeight", QTUtility.TabHeight); key.SetValue("TabWidthMax", QTUtility.MaxTabWidth); key.SetValue("TabWidthMin", QTUtility.MinTabWidth); key.SetValue("TitleColorActive", QTUtility.TabTextColor_Active.ToArgb()); key.SetValue("TitleColorInactive", QTUtility.TabTextColor_Inactv.ToArgb()); key.SetValue("HighlightColorClassic", QTUtility.TabHiliteColor.ToArgb()); key.SetValue("TitleColorShadowActive", QTUtility.TabTextColor_ActivShdw.ToArgb()); key.SetValue("TitleColorShadowInActv", QTUtility.TabTextColor_InAtvShdw.ToArgb()); key.SetValue("ToolbarBGColor", QTUtility.RebarBGColor.ToArgb()); key.SetValue("AlternateColor_Bk", QTUtility.ShellViewRowCOLORREF_Background); key.SetValue("AlternateColor_Text", QTUtility.ShellViewRowCOLORREF_Text); key.SetValue("Max_Undo", QTUtility.MaxCount_History); key.SetValue("Max_RecentFile", QTUtility.MaxCount_Executed); key.SetValue("PreviewMaxWidth", QTUtility.PreviewMaxWidth); key.SetValue("PreviewMaxHeight", QTUtility.PreviewMaxHeight); key.SetValue("Action_BarDblClick", QTUtility.Action_BarDblClick); if((tabFont != null) && !tabFont.Equals(DefaultFont)) { key.SetValue("TabFont", tabFont.Name); key.SetValue("TabFontSize", tabFont.SizeInPoints.ToString()); QTUtility.TabFont = tabFont; } else { key.DeleteValue("TabFont", false); key.DeleteValue("TabFontSize", false); QTUtility.TabFont = null; } key.SetValue("TabImage", QTUtility.Path_TabImage); byte[] buffer = new byte[] { (byte)QTUtility.TabImageSizingMargin.Left, (byte)QTUtility.TabImageSizingMargin.Top, (byte)QTUtility.TabImageSizingMargin.Right, (byte)QTUtility.TabImageSizingMargin.Bottom }; key.SetValue("TabImageSizingMargin", buffer); QTUtility.PreviewExtsList_Txt.Clear(); QTUtility.PreviewExtsList_Img.Clear(); string str = string.Empty; string str2 = string.Empty; if(strsTextExts != null) { foreach(string ext in strsTextExts) { QTUtility.PreviewExtsList_Txt.Add(ext); str = str + ext + ";"; } if(str.Length > 0) { str = str.TrimEnd(QTUtility.SEPARATOR_CHAR); } } if(strsImgExts != null) { foreach(string ext in strsImgExts) { QTUtility.PreviewExtsList_Img.Add(ext); str2 = str2 + ext + ";"; } if(str2.Length > 0) { str2 = str2.TrimEnd(QTUtility.SEPARATOR_CHAR); } } key.SetValue("TextExtensions", str); key.SetValue("ImageExtensions", str2); if(QTUtility.PreviewFontName != null) { key.SetValue("PreviewFont", QTUtility.PreviewFontName); key.SetValue("PreviewFontSize", QTUtility.PreviewFontSize.ToString()); } else { key.DeleteValue("PreviewFont", false); key.DeleteValue("PreviewFontSize", false); } key.SetValue("NetworkTimeout", IDLWrapper.iPingTimeOutMS); key.SetValue("LanguageFile", QTUtility.Path_LanguageFile); using(RegistryKey key2 = key.CreateSubKey("Plugins")) { if(key2 != null) { key2.SetValue("LanguageFile", QTUtility.Path_PluginLangFile); } } key.SetValue("ToolbarBGImage", QTUtility.Path_RebarImage); QTUtility2.WriteRegBinary(QTUtility.ShortcutKeys, "ShortcutKeys", key); } } }
private static TextServiceDirectWriteInterop EnsureInterop(Font font) { if (interops == null) { interops = new List<KeyValuePair<Font, TextServiceDirectWriteInterop>>(MaxCachedInterops); } if (lastWidth != Screen.PrimaryScreen.Bounds.Width) { ClearCache(); } lastWidth = Screen.PrimaryScreen.Bounds.Width; int index = -1; for (int i = 0; i < interops.Count; i++) { if (font.Equals(interops[i].Key)) { index = i; } } if (index < 0) { if (interops.Count >= MaxCachedInterops) { ClearCache(); } index = interops.Count; TextServiceDirectWriteInterop interop = new TextServiceDirectWriteInterop(); interop.Reset(TextServiceDirectWrite.InteropGlobals, font, lastWidth); interops.Add(new KeyValuePair<Font, TextServiceDirectWriteInterop>(font, interop)); #if DEBUG Debugger.Log( 1, "TextServiceDirectWrite", String.Concat( DateTime.Now.ToString(), ": Added DirectWrite interop for ", font.ToString(), " ", font.Style.ToString(), Environment.NewLine)); #endif } return interops[index].Value; }
/// <summary> /// 计算合适的字体大小与偏移,并创建“g”和“bitmap”。 /// </summary> /// <remarks>关联属性更改后调用</remarks> private void Ini() { if (bitmap != null) { if (latticeSize != bitmap.Size) { bitmap.Dispose(); bitmap = null; if (g != null) { g.Dispose(); } } } if (bitmap == null) { bitmap = new Bitmap(width, height); g = Graphics.FromImage(bitmap); g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; } if (autoFontSize) { float h = height; Font fontn = new Font(Font.FontFamily, h, Font.Style, GraphicsUnit.Pixel); if (!fontn.Equals(font)) { font = fontn; base.OnFontChanged(EventArgs.Empty); } } RectangleF re = new Rectangle(0, 0, 10000, 10000); StringFormat sf = new StringFormat(); string testString = "w"; CharacterRange[] cr = { new CharacterRange(0, 1) };//,new CharacterRange(1,1)}; sf.SetMeasurableCharacterRanges(cr); Region[] charRegions; charRegions = g.MeasureCharacterRanges(testString, font, re, sf); if (charRegions.Length > 0) { PointF t2 = charRegions[0].GetBounds(g).Location; charOffset = new PointF(charLocation.X - t2.X, charLocation.Y - t2.Y); } sf.Dispose(); DrawChar(); }
internal int GetValueTextWidth(string valueString, Graphics g, Font f) { if (cacheItems == null) { cacheItems = new CacheItems(); } else if (cacheItems.lastValueTextWidth != -1 && cacheItems.lastValueString == valueString && f.Equals(cacheItems.lastValueFont)) { return cacheItems.lastValueTextWidth; } // Value text is rendered using GDI directly (No TextRenderer) but measured/adjusted using GDI+ (since previous releases), so don't use MeasureTextHelper. cacheItems.lastValueTextWidth = (int) g.MeasureString(valueString, f).Width; cacheItems.lastValueString = valueString; cacheItems.lastValueFont = f; return cacheItems.lastValueTextWidth; }
protected int GetLabelTextWidth(string labelText, Graphics g, Font f) { if (cacheItems == null) { cacheItems = new CacheItems(); } else if (cacheItems.useCompatTextRendering == ownerGrid.UseCompatibleTextRendering && cacheItems.lastLabel == labelText && f.Equals(cacheItems.lastLabelFont)) { return cacheItems.lastLabelWidth; } SizeF textSize = PropertyGrid.MeasureTextHelper.MeasureText( this.ownerGrid, g, labelText, f); cacheItems.lastLabelWidth = (int) textSize.Width; cacheItems.lastLabel = labelText; cacheItems.lastLabelFont = f; cacheItems.useCompatTextRendering = ownerGrid.UseCompatibleTextRendering; return cacheItems.lastLabelWidth; }
internal int GetValueTextWidth(string valueString, Graphics g, Font f) { if (this.cacheItems == null) { this.cacheItems = new CacheItems(); } else if (((this.cacheItems.lastValueTextWidth != -1) && (this.cacheItems.lastValueString == valueString)) && f.Equals(this.cacheItems.lastValueFont)) { return this.cacheItems.lastValueTextWidth; } this.cacheItems.lastValueTextWidth = (int) g.MeasureString(valueString, f).Width; this.cacheItems.lastValueString = valueString; this.cacheItems.lastValueFont = f; return this.cacheItems.lastValueTextWidth; }
protected int GetLabelTextWidth(string labelText, Graphics g, Font f) { if (this.cacheItems == null) { this.cacheItems = new CacheItems(); } else if (((this.cacheItems.useCompatTextRendering == this.ownerGrid.UseCompatibleTextRendering) && (this.cacheItems.lastLabel == labelText)) && f.Equals(this.cacheItems.lastLabelFont)) { return this.cacheItems.lastLabelWidth; } SizeF ef = PropertyGrid.MeasureTextHelper.MeasureText(this.ownerGrid, g, labelText, f); this.cacheItems.lastLabelWidth = (int) ef.Width; this.cacheItems.lastLabel = labelText; this.cacheItems.lastLabelFont = f; this.cacheItems.useCompatTextRendering = this.ownerGrid.UseCompatibleTextRendering; return this.cacheItems.lastLabelWidth; }
public static bool Test() { bool ok = true; string s = string.Empty; // DecodePoint Point p1 = new Point(5, 104); s = DecodePointInverse(p1); Point p2 = DecodePoint(s); if (!p1.Equals(p2)) ok = false; // DecodeSize Size s1 = new Size(1254, 67); s = DecodeSizeInverse(s1); Size s2 = DecodeSize(s); if (!s1.Equals(s2)) ok = false; // DecodeFont Font f1 = new Font("Microsoft Sans Serif", 8.25F, FontStyle.Bold | FontStyle.Italic, GraphicsUnit.Point); s = DecodeFontInverse(f1); Font f2 = DecodeFont(s); if (!f1.Equals(f2)) ok = false; // DecodeDateTime DateTime t1 = DateTime.Today; s = DecodeDateTimeInverse(t1); DateTime t2 = DecodeDateTime(s); if (!t1.Equals(t2)) ok = false; // DecodeAppearance Appearance a1 = Appearance.Button; s = DecodeAppearanceInverse(a1); Appearance a2 = DecodeAppearance(s); if (!t1.Equals(t2)) ok = false; // DecodeScrollBars ScrollBars sb1 = ScrollBars.Both; s = DecodeScrollBarsInverse(sb1); ScrollBars sb2 = DecodeScrollBars(s); if (!sb1.Equals(sb2)) ok = false; // DecodeSelectionMode SelectionMode sm1 = SelectionMode.MultiSimple; s = DecodeSelectionModeInverse(sm1); SelectionMode sm2 = DecodeSelectionMode(s); if (!sm1.Equals(sm2)) ok = false; // DecodeView View v1 = View.LargeIcon; s = DecodeViewInverse(v1); View v2 = DecodeView(s); if (!v1.Equals(v2)) ok = false; // DecodeOrientation Orientation o1 = Orientation.Vertical; s = DecodeOrientationInverse(o1); Orientation o2 = DecodeOrientation(s); if (!o1.Equals(o2)) ok = false; // DecodeTickStyle TickStyle ts1 = TickStyle.BottomRight; s = DecodeTickStyleInverse(ts1); TickStyle ts2 = DecodeTickStyle(s); if (!ts1.Equals(ts2)) ok = false; // DecodeTabAlignment TabAlignment ta1 = TabAlignment.Right; s = DecodeTabAlignmentInverse(ta1); TabAlignment ta2 = DecodeTabAlignment(s); if (!ta1.Equals(ta2)) ok = false; // DecodeListViewItem (single) ListViewItem lv1 = new ListViewItem("John Doe"); s = DecodeListViewItemInverse(lv1); ListViewItem lv2 = DecodeListViewItem(s); /* not comparable (only by reference) if (!lv1.Equals(lv2)) ok = false; */ // DecodeListViewItem (subitems) lv1 = new ListViewItem(); lv1.SubItems.Add("John Doe"); lv1.SubItems.Add("Mountain View"); lv1.SubItems.Add("43"); s = DecodeListViewItemInverse(lv1); lv2 = DecodeListViewItem(s); /* not comparable (only by reference) if (!lv1.Equals(lv2)) ok = false; */ // DecodeColor s = DecodeColorInverse(Color.BlanchedAlmond); Color c = DecodeColor(s); if (!c.Equals(Color.BlanchedAlmond)) ok = false; return ok; }
private void btnOk_Click(object sender, EventArgs e) { try { this.SaveProxySetting(); FontStyle style = FontStyle.Regular; if (this.cbDefaultFontStyle.Text == "Bold") { style = FontStyle.Bold; } Font font = new Font(this.cbDefaultFontName.Text, (float)Convert.ToInt32(this.cbDefaultFontSize.Text), style); if (!font.Equals(Settings.Default.Default_Font)) { Settings.Default.Default_Font = font; TemplateManager.Instance.CurrentActiveTemplateView.SetFont(); } int num; int.TryParse(this.cbMaxViewOrderRows.Text, out num); if (num >= 20 && num <= 9999) { Settings.Default.ViewOrderRows = num; } Settings.Default.IsWriteErrorLog = this.chkIsWriteLog.Checked; this.SetBlinkTP2AllForm(); if (this.rdbFontColorSoftStyle.Checked) { ApplicationInfo.IsFrontSoftStyle = true; } else if (this.rdbFontColorOriginalStyle.Checked) { ApplicationInfo.IsFrontSoftStyle = false; } Settings.Default.Save(); } catch (Exception ex) { this.ShowError("SaveProfileConfig", ex); } base.Close(); }