using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml; using TradeIdeas.TIProData; using System.Drawing; using System.IO; using System.Windows.Forms; using TradeIdeas.XML; namespace TradeIdeas.TIProGUI { /*This FontManager class does things related to changing the fonts on different forms. Since there's some code that could possibly be repeated for each form, I made this little class to to be a one-stop-shop. Due to the nature of some of these forms, just doing myForm.Font = whatever... doesn't necessarily affect all controls on the form. An example would be tab pages in the config window. Another example would be the oddsmaker config window. Although there are no tab pages there, there are group boxes, and for some weird reason, not everthing gets updated just by simply using myForm.Font = whateverFont. In many cases, one needs to loop thru every control on the form in question to sucessfully * change its font. Although stated within the code comments of the Options Tab, I'll mention it here again: We need some sort of default to go back to. I used the Options Window as a point of reference. Although my fontsize combo box has "8" as the first selection, the actual fontsize of the default Options window is 8.25 points(VS Designer). So, whenever someone sets the Font comboBox to MS Sans Serif with the size being 8, the fontsize of other forms will be set to their respective defaults. That is, their fontsizes that were set within Visual Studio Designmer. (Not all forms in this application have a default fontsize of 8.25 points) Note-MS San Serif is the Default Font for all of the forms (Visual Studio)*/ public class FontManager { private float _formDefaultFont; private Form _form; private float _fontSize = 0.0F; //initialize with something... private Size DEFAULT_MAIN_FORM_SIZE = new Size(336, 102); public FontManager(Form form, float formDefaultFont) { _form = form; _formDefaultFont = formDefaultFont; } public void selectTheFont() { if (GuiEnvironment.FontSettings.Name == GuiEnvironment.DEFAULT_FONT && GuiEnvironment.FontSettings.Size == GuiEnvironment.DEFAULT_FONTSIZE) { _form.Font = new Font(GuiEnvironment.FontSettings.Name, _formDefaultFont, GuiEnvironment.FontSettings.Style, GraphicsUnit.Point); _fontSize = _formDefaultFont; } else { _form.Font = new Font(GuiEnvironment.FontSettings.Name, GuiEnvironment.FontSettings.Size, GuiEnvironment.FontSettings.Style, GraphicsUnit.Point); _fontSize = GuiEnvironment.FontSettings.Size; } foreach (Control control in _form.Controls) { Type test = control.GetType(); if (test.Name == "TabControl") { TabControl tabControl = (TabControl)control; tabControl.Font = GuiEnvironment.FontSettings; } else if (test.Name == "MenuStrip") //Main Form has a MenuStrip { //We must gather every item and subItem from the //menuStrip MenuStrip menuStrip = (MenuStrip)control; getAllMenuStripItems(menuStrip.Items, _fontSize); } changeControlsFonts(control, _fontSize); } } private void getAllMenuStripItems(ToolStripItemCollection items, float fontSize) { foreach (ToolStripItem item in items) { changeMenuStripFonts(item, fontSize); //Gather sub-items (if any) ToolStripDropDownItem dropItem = item as ToolStripDropDownItem; if (dropItem != null) { getAllMenuStripItems(dropItem.DropDownItems,fontSize); } } } private void changeFontOfIndexPanel(ToolStripControlHost h, float size) { Font newFont = new Font(GuiEnvironment.INDEX_FONT_FAMILY, size, FontStyle.Bold, GraphicsUnit.Point); h.Height = newFont.Height; // Now change the fontHeight of the label inside(IndexPanel). // We want this height to be roughly a little more than half the height of font of the toolbar because we want // to utilize only the area that's available and not exceed it. float newLabelHeight = size * .63f; Font newIndexLabelFont = new Font(GuiEnvironment.INDEX_FONT_FAMILY, newLabelHeight, FontStyle.Bold, GraphicsUnit.Point); if (null != h.Control as IndexPanel) { IndexPanel p = (IndexPanel)h.Control; p.ChangeFont(newIndexLabelFont); } if (null != h.Control as BrokeragePlusStartPanel) { BrokeragePlusStartPanel p = (BrokeragePlusStartPanel)h.Control; p.changeFont(newIndexLabelFont); double widthD = (double)p.Width; p.Width = (int)(0.9 * widthD); } } private void changeControlsFonts(Control container, float size) { //We wish to keep any Bold and Italic Styles,and underlines even //when the font is changed... FontStyle boldItalicState; if (container.Font.Bold) { boldItalicState = FontStyle.Bold; } else if (container.Font.Italic) { boldItalicState = FontStyle.Italic; } else if (container.Font.Underline) { boldItalicState = FontStyle.Underline; } else { boldItalicState = FontStyle.Regular; } if (container as IndexPanel == null) //we don't want the labels in the IndexPanel control to have the same font height as those in the rest of the toolbar return; container.Font = new Font(GuiEnvironment.FontSettings.Name, size, boldItalicState, GraphicsUnit.Point); foreach (Control ctrl in container.Controls) { changeControlsFonts(ctrl, size); } } private void changeMenuStripFonts(ToolStripItem tStrip, float size) { if (tStrip as ToolStripControlHost != null) { ToolStripControlHost host = (ToolStripControlHost)tStrip; changeFontOfIndexPanel(host,size); } else tStrip.Font = new Font(GuiEnvironment.FontSettings.Name, size, GuiEnvironment.FontSettings.Style, GraphicsUnit.Point); } public void selectTheFont(TabPage page) { //This is an alternative method which deals with //controls for individual tab page...as with the Options Window float fontSize; if (GuiEnvironment.FontSettings.Name == GuiEnvironment.DEFAULT_FONT && GuiEnvironment.FontSettings.Size == GuiEnvironment.DEFAULT_FONTSIZE) { fontSize = _formDefaultFont; //Set to default size setting for the form in question (VS Designer) } else { fontSize = GuiEnvironment.FontSettings.Size; } changeControlsFonts(page, fontSize); } public void changeContextMenuStripFont(ContextMenuStrip ctxtStrip) { // Regular tool strips are controls on a form and can thus be enumerated //using the selectFont() method-the Main Form is an example. ContextMenuStrips,OTOH, //don't appear to be part of the controls on the form. So, they'll have to be treated //separately which,of course is the purpose of this method. ctxtStrip.Font = new Font(GuiEnvironment.FontSettings.Name, _fontSize, GuiEnvironment.FontSettings.Style, GraphicsUnit.Point); } //Although fonts can be weeded out by FontStyle.style(underline,bold..etc), //there are other fonts that can get the user into a bit of trouble should //he choose it in the Options window. Those fonts will be listed here in //this static array. They will not be added to the font combo-box within the //Options window. private static string[] ForbiddenFonts = { "Bookshelf Symbol 7", "Euclid Extra", "Euclid Math One", "Euclid Math Two", "Euclid Symbol","Fences", "Marlett", "MS Outlook","MS Reference Specialty", "MT Extra","MT Extra Tiger", "QuickType II Pi", "SWGamekeys MT", "Symbol", "Symbol Tiger", "Symbol Tiger Expert","Webdings", "Wingdings", "Wingdings 2", "Wingdings 3","ZWAdobeF" }; public static bool isFontForbidden(string fontName) { foreach (string s in ForbiddenFonts) { if (s == fontName) { return true; } } return false; } } /// /// This interface is used with forms that can stay on /// desktop..that is, they're not modal dialog boxes. This /// would include alert,toplist,Oddsmaker results forms. /// This interface facilitates changing the fonts for /// windows that are currently open while using the Options /// window. /// public interface IFont { void selectTheFont(); } public interface IGrid //setting gridlines of alert,toplist,multistrategy window { void setGridLines(); } public interface IRowSelect //selecting rows of alert,toplist,multistrategy { void chooseRowSelect(); } }