From 5d50cd8b96c04a43fd37e532fd5243c1adf2d5a5 Mon Sep 17 00:00:00 2001 From: Robin Date: Fri, 13 Jan 2017 20:17:15 +0100 Subject: [PATCH] BUG-2109: Fix for NPE --- Greenshot/Drawing/TextContainer.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Greenshot/Drawing/TextContainer.cs b/Greenshot/Drawing/TextContainer.cs index 2761bfe9c..0c72b464b 100644 --- a/Greenshot/Drawing/TextContainer.cs +++ b/Greenshot/Drawing/TextContainer.cs @@ -272,8 +272,11 @@ namespace Greenshot.Drawing _parent.Controls.Add(_textBox); } EnsureTextBoxContrast(); - _textBox.Show(); - _textBox.Focus(); + if (_textBox != null) + { + _textBox.Show(); + _textBox.Focus(); + } } /// @@ -281,6 +284,10 @@ namespace Greenshot.Drawing /// private void EnsureTextBoxContrast() { + if (_textBox == null) + { + return; + } Color lc = GetFieldValueAsColor(FieldType.LINE_COLOR); if (lc.R > 203 && lc.G > 203 && lc.B > 203) { @@ -295,7 +302,7 @@ namespace Greenshot.Drawing private void HideTextBox() { _parent.Focus(); - _textBox.Hide(); + _textBox?.Hide(); _parent.KeysLocked = false; _parent.Controls.Remove(_textBox); } @@ -424,6 +431,10 @@ namespace Greenshot.Drawing /// private void UpdateTextBoxPosition() { + if (_textBox == null) + { + return; + } int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS); int lineWidth = (int)Math.Floor(lineThickness / 2d);