Jul 092011

One of the things that I admittedly am not always the best at is including accessibility options in the MarcEdit program.  Where this raises the most questions tends to be in regard to the Font, or more precisely, the font size of the program.  It’s something that I occasionally think about dealing with, but at this point, the program currently has 20-30 windows that would need to be dealt with representing way more code than I’d like to worry about. 

Anyway, this last week, I got another message asking about the ability to modify the font size of the application.  I like the fonts small – so I use 9pt Arial as my default.  However, I do realize that this isn’t going to work for everyone so this last weekend, I spent a lot of time working on prepping the program and putting together a simplified function that can be used to dynamically reset font sizes within the program. 

Starting with the next update (Scheduled for July 11, 2011) – a new option will be able to be found in the Preferences => Language section.  You will now find an option to update the Font size used by the application (and note, changing this option does require restarting the program)…




The hardest part of the program was getting the autoscaling to work correctly without breaking the various anchoring, resizing and dynamic placement happening within the program.  I’ve gone through and hand tested nearly every screen in the MarcEdit program and the Z39.50, and the Delimited Text translator at 12 pt font and everything appears to be good.  However, if you end up using this new function and notice something wonky – let me know.



The meat of the code changes wound up being pretty simple.  Two functions were created that were placed after the initialization routine of each window.  Basically, it was an enumerating function that changed the font of the controls contained on a window.

  1: public void SizeLabels(System.Windows.Forms.Control ctr)
  2: {
  3:   string tmp_string = "";
  4:   cglobal.cxmlini.GetAppSettings(cglobal.mglobal.XMLPath(), "settings", "font_size", "9", ref tmp_string);
  5:   float font_size = (float)System.Convert.ToDouble(tmp_string);
  6:   ctr.Font = new System.Drawing.Font(ctr.Font.FontFamily, font_size);
  7:   //ctr.SuspendLayout();
  8:   foreach (Control ctrl in ctr.Controls)
  9:     {
 10:       ctrl.Font = ctr.Font;
 11:       if (ctrl.Controls.Count > 0)
 12:       {
 13:         SizeLabels(ctrl);
 14:       }
 15:     }
 16:  }
 19: public void SizeLabels(System.Windows.Forms.Form fm)
 20: {
 21:   string tmp_string = ""; 
 22:   cglobal.cxmlini.GetAppSettings(cglobal.mglobal.XMLPath(), "settings", "font_size", "9", ref tmp_string);
 23:   float font_size = (float)System.Convert.ToDouble(tmp_string);
 24:   fm.Font = new System.Drawing.Font(fm.Font.FontFamily, font_size);
 25:   fm.SuspendLayout();
 26:   foreach (Control ctrl in fm.Controls)
 27:   {
 28:     if (ctrl.GetType() == typeof(System.Windows.Forms.MenuStrip))
 29:     {
 30:        System.Drawing.Graphics graphics = fm.CreateGraphics();
 31:        System.Drawing.SizeF textSize = graphics.MeasureString("File", fm.Font); //lb.Font);
 32:        float hText = textSize.Height + (float)(textSize.Height * 0.25);
 33:        ctrl.Height = (int)hText + 3;
 34:      }
 35:      ctrl.Font = fm.Font;
 36:      if (ctrl.Controls.Count > 0)
 37:      {
 38:         SizeLabels(ctrl);
 39:      }
 40:    }
 41:    //Make sure you resume layout
 42:    fm.ResumeLayout(true);
 43: }
 Posted by at 10:25 pm