C# - WPF Font von WinForms Font


SUBMITTED BY: TheSwarm

DATE: Oct. 20, 2015, 9:02 p.m.

FORMAT: Text only

SIZE: 1.2 kB

HITS: 2160

  1. C# - WPF Font von WinForms Fontprivate void setFont(UIElement element, System.Drawing.Font systemFont)
  2. {
  3. TextBlock tbElement = (element as TextBlock);
  4. Label lbElement = (element as Label);
  5. if (tbElement != null)
  6. {
  7. tbElement.FontFamily = new System.Windows.Media.FontFamily(systemFont.Name);
  8. tbElement.FontSize = systemFont.Size;
  9. tbElement.FontStretch = FontStretches.Normal;
  10. tbElement.FontStyle = (systemFont.Style == System.Drawing.FontStyle.Italic ? FontStyles.Italic : FontStyles.Normal);
  11. tbElement.FontWeight = (systemFont.Style == System.Drawing.FontStyle.Bold ? FontWeights.Bold : FontWeights.Normal);
  12. }
  13. else if (lbElement != null)
  14. {
  15. lbElement.FontFamily = new System.Windows.Media.FontFamily(systemFont.Name);
  16. lbElement.FontSize = systemFont.Size;
  17. lbElement.FontStretch = FontStretches.Normal;
  18. lbElement.FontStyle = (systemFont.Style == System.Drawing.FontStyle.Italic ? FontStyles.Italic : FontStyles.Normal);
  19. lbElement.FontWeight = (systemFont.Style == System.Drawing.FontStyle.Bold ? FontWeights.Bold : FontWeights.Normal);
  20. }
  21. }

comments powered by Disqus