PilarMI BertinGA

PilarMI BertinGA

  • NA
  • 39
  • 1.6k

problem with font size in WPF

Feb 11 2021 1:46 PM
Hi, im programming with c#, and im doing one form using WPF, and i need show texts on it. Im using code below to draw text, but font size appears smaller than size indicated (i defined as arial 160, and appears about 118). I dont know what im doing bad, somebody can help me please. Also, over text appears a space, i want that text starts at heigh indicated in texbox position not below; you can see small line as texbox container.
 
thanks a lot.
  1. TextBox textBox = new TextBox();  
  2. textBox.BorderThickness = new Thickness(1);  
  3. textBox.IsHitTestVisible = false;  
  4. textBox.Focusable = false;  
  5. textBox.TextWrapping = TextWrapping.WrapWithOverflow;  
  6. textBox.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;  
  7. textBox.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;  
  8. textBox.Tag = (object)mText.Id;  
  9. textBox.Text = mText.Text;  
  10. textBox.FontSize = mText.Size;  
  11. textBox.Foreground = XDisplay.ConvertStringColorToBrush(mText.Color);  
  12. textBox.Background = XDisplay.ConvertStringColorToBrush(mText.BackgroundColor);  
  13. textBox.FontFamily = new FontFamily(mText.FontName);  
  14. textBox.FontWeight = mText.Bold ? FontWeights.Bold : FontWeights.Normal;  
  15. textBox.FontStyle = mText.Italic ? FontStyles.Italic : FontStyles.Normal;  
  16. textBox.Opacity = mText.Opacity;  
  17. textBox.Width = mText.Width;  
  18. textBox.Height = mText.Height;  
  19. textBox.TextAlignment = (TextAlignment)mText.Alignment;  
  20. Canvas.SetTop(textBox, mText.Y);  
  21. Canvas.SetLeft(textBox, mText.X);  
  22. Panel.SetZIndex(textBox, mText.Layer);  
  23. return textBox;  
 
 
 

Answers (7)