diff --git a/Greenshot/Drawing/TextContainer.cs b/Greenshot/Drawing/TextContainer.cs
index c73424908..939dd3de6 100644
--- a/Greenshot/Drawing/TextContainer.cs
+++ b/Greenshot/Drawing/TextContainer.cs
@@ -22,6 +22,7 @@
using Greenshot.Drawing.Fields;
using Greenshot.Helpers;
using Greenshot.Memento;
+using GreenshotPlugin.Core;
using GreenshotPlugin.Interfaces.Drawing;
using System;
using System.ComponentModel;
@@ -155,6 +156,24 @@ namespace Greenshot.Drawing
FieldChanged += TextContainer_FieldChanged;
}
+ protected override void SwitchParent(Surface newParent)
+ {
+ _parent.SizeChanged -= Parent_SizeChanged;
+ base.SwitchParent(newParent);
+ _parent.SizeChanged += Parent_SizeChanged;
+ }
+
+ private void Parent_SizeChanged(object sender, EventArgs e)
+ {
+ UpdateTextBoxPosition();
+ UpdateTextBoxFont();
+ }
+
+ public override void ApplyBounds(RectangleF newBounds)
+ {
+ base.ApplyBounds(newBounds);
+ UpdateTextBoxPosition();
+ }
public override void Invalidate()
{
@@ -255,7 +274,8 @@ namespace Greenshot.Drawing
AcceptsTab = true,
AcceptsReturn = true,
BorderStyle = BorderStyle.None,
- Visible = false
+ Visible = false,
+ Font = new Font(FontFamily.GenericSansSerif, 1) // just need something non-default here
};
_textBox.DataBindings.Add("Text", this, "Text", false, DataSourceUpdateMode.OnPropertyChanged);
@@ -388,7 +408,6 @@ namespace Greenshot.Drawing
var newFont = CreateFont(fontFamily, fontBold, fontItalic, fontSize);
_font?.Dispose();
_font = newFont;
- _textBox.Font = _font;
}
catch (Exception ex)
{
@@ -400,7 +419,6 @@ namespace Greenshot.Drawing
var newFont = CreateFont(fontFamily, fontBold, fontItalic, fontSize);
_font?.Dispose();
_font = newFont;
- _textBox.Font = _font;
}
catch (Exception)
{
@@ -413,6 +431,8 @@ namespace Greenshot.Drawing
}
}
+ UpdateTextBoxFont();
+
UpdateAlignment();
}
@@ -423,7 +443,29 @@ namespace Greenshot.Drawing
}
///
- /// This will create the textbox exactly to the inner size of the element
+ /// Set TextBox font according to the TextContainer font and the parent zoom factor.
+ ///
+ private void UpdateTextBoxFont()
+ {
+ if (_textBox == null || _font == null)
+ {
+ return;
+ }
+
+ var textBoxFontScale = _parent?.ZoomFactor ?? Fraction.Identity;
+
+ var newFont = new Font(
+ _font.FontFamily,
+ _font.Size * textBoxFontScale,
+ _font.Style,
+ GraphicsUnit.Pixel
+ );
+ _textBox.Font.Dispose();
+ _textBox.Font = newFont;
+ }
+
+ ///
+ /// This will align the textbox exactly to the inner size of the element
/// is a bit of a hack, but for now it seems to work...
///
private void UpdateTextBoxPosition()
@@ -453,12 +495,9 @@ namespace Greenshot.Drawing
_textBox.Height = displayRectangle.Height - 2 * lineWidth + correction;
}
- public override void ApplyBounds(RectangleF newBounds)
- {
- base.ApplyBounds(newBounds);
- UpdateTextBoxPosition();
- }
-
+ ///
+ /// Set TextBox text align and fore color according to field values.
+ ///
private void UpdateTextBoxFormat()
{
if (_textBox == null)