diff --git a/Greenshot/Drawing/CropContainer.cs b/Greenshot/Drawing/CropContainer.cs
index 5bf51021d..93464f18f 100644
--- a/Greenshot/Drawing/CropContainer.cs
+++ b/Greenshot/Drawing/CropContainer.cs
@@ -50,24 +50,20 @@ namespace Greenshot.Drawing {
}
public override void Invalidate() {
- if (_parent == null)
- {
- return;
- }
- _parent.Invalidate();
+ _parent?.Invalidate();
}
///
/// We need to override the DrawingBound, return a rectangle in the size of the image, to make sure this element is always draw
/// (we create a transparent brown over the complete picture)
///
- public override Rectangle DrawingBounds {
- get {
- return new Rectangle(0,0,_parent.Width, _parent.Height);
- }
- }
+ public override Rectangle DrawingBounds => new Rectangle(0,0,_parent?.Width??0, _parent?.Height ?? 0);
public override void Draw(Graphics g, RenderMode rm) {
+ if (_parent == null)
+ {
+ return;
+ }
using (Brush cropBrush = new SolidBrush(Color.FromArgb(100, 150, 150, 100))) {
Rectangle cropRectangle = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
Rectangle selectionRect = new Rectangle(cropRectangle.Left - 1, cropRectangle.Top - 1, cropRectangle.Width + 1, cropRectangle.Height + 1);
diff --git a/Greenshot/Drawing/DrawableContainer.cs b/Greenshot/Drawing/DrawableContainer.cs
index 650e20992..989cc9d07 100644
--- a/Greenshot/Drawing/DrawableContainer.cs
+++ b/Greenshot/Drawing/DrawableContainer.cs
@@ -89,14 +89,7 @@ namespace Greenshot.Drawing
if (!disposing) {
return;
}
- if (_parent != null)
- {
- FieldAggregator fieldAggregator = _parent.FieldAggregator;
- if (fieldAggregator != null)
- {
- fieldAggregator.UnbindElement(this);
- }
- }
+ _parent?.FieldAggregator?.UnbindElement(this);
}
~DrawableContainer() {
@@ -306,7 +299,7 @@ namespace Greenshot.Drawing
public virtual void Invalidate() {
if (Status != EditStatus.UNDRAWN) {
- _parent.Invalidate(DrawingBounds);
+ _parent?.Invalidate(DrawingBounds);
}
}
@@ -491,15 +484,7 @@ namespace Greenshot.Drawing
{
return;
}
- if (_parent != null)
- {
- // Remove FieldAggregator
- FieldAggregator fieldAggregator = _parent.FieldAggregator;
- if (fieldAggregator != null)
- {
- fieldAggregator.UnbindElement(this);
- }
- }
+ _parent.FieldAggregator?.UnbindElement(this);
_parent = newParent;
foreach(IFilter filter in Filters) {
@@ -521,7 +506,7 @@ namespace Greenshot.Drawing
/// The field to be changed
/// The new value
public virtual void BeforeFieldChange(IField fieldToBeChanged, object newValue) {
- _parent.MakeUndoable(new ChangeFieldHolderMemento(this, fieldToBeChanged), true);
+ _parent?.MakeUndoable(new ChangeFieldHolderMemento(this, fieldToBeChanged), true);
Invalidate();
}
diff --git a/Greenshot/Drawing/FreehandContainer.cs b/Greenshot/Drawing/FreehandContainer.cs
index 23de535f6..eb97544e7 100644
--- a/Greenshot/Drawing/FreehandContainer.cs
+++ b/Greenshot/Drawing/FreehandContainer.cs
@@ -217,7 +217,7 @@ namespace Greenshot.Drawing {
int safetymargin = 10;
return new Rectangle(myBounds.Left + Left - (safetymargin+lineThickness), myBounds.Top + Top - (safetymargin+lineThickness), myBounds.Width + 2*(lineThickness+safetymargin), myBounds.Height + 2*(lineThickness+safetymargin));
}
- return new Rectangle(0, 0, _parent.Width, _parent.Height);
+ return new Rectangle(0, 0, _parent?.Width??0, _parent?.Height?? 0);
}
}
diff --git a/Greenshot/Drawing/TextContainer.cs b/Greenshot/Drawing/TextContainer.cs
index 397a4501e..a6673d091 100644
--- a/Greenshot/Drawing/TextContainer.cs
+++ b/Greenshot/Drawing/TextContainer.cs
@@ -40,14 +40,12 @@ namespace Greenshot.Drawing {
public class TextContainer : RectangleContainer, ITextContainer {
// If makeUndoable is true the next text-change will make the change undoable.
// This is set to true AFTER the first change is made, as there is already a "add element" on the undo stack
+ // Although the name is wrong, we can't change it due to file serialization
+ // ReSharper disable once InconsistentNaming
private bool makeUndoable;
[NonSerialized]
private Font _font;
- public Font Font {
- get {
- return _font;
- }
- }
+ public Font Font => _font;
[NonSerialized]
private TextBox _textBox;
@@ -57,11 +55,10 @@ namespace Greenshot.Drawing {
///
[NonSerialized]
StringFormat _stringFormat = new StringFormat();
- public StringFormat StringFormat {
- get {
- return _stringFormat;
- }
- }
+ public StringFormat StringFormat => _stringFormat;
+
+ // Although the name is wrong, we can't change it due to file serialization
+ // ReSharper disable once InconsistentNaming
private string text;
// there is a binding on the following property!
public string Text {
@@ -168,7 +165,7 @@ namespace Greenshot.Drawing {
HideTextBox();
} else if (Selected && Status == EditStatus.DRAWING) {
ShowTextBox();
- } else if (Selected && Status == EditStatus.IDLE && _textBox.Visible) {
+ } else if (_parent != null && Selected && Status == EditStatus.IDLE && _textBox.Visible) {
// Fix (workaround) for BUG-1698
_parent.KeysLocked = true;
}
@@ -221,8 +218,11 @@ namespace Greenshot.Drawing {
}
private void ShowTextBox() {
- _parent.KeysLocked = true;
- _parent.Controls.Add(_textBox);
+ if (_parent != null)
+ {
+ _parent.KeysLocked = true;
+ _parent.Controls.Add(_textBox);
+ }
EnsureTextBoxContrast();
_textBox.Show();
_textBox.Focus();