Don't draw text if rectangle is too small

This commit is contained in:
Jaex 2016-05-20 21:34:20 +03:00
parent fec6e8429a
commit 67f69559fc
6 changed files with 11 additions and 7 deletions

View file

@ -240,6 +240,7 @@ private void InitializeComponent()
this.Name = "TextDrawingInputBox"; this.Name = "TextDrawingInputBox";
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.TopMost = true; this.TopMost = true;
this.Shown += new System.EventHandler(this.TextDrawingInputBox_Shown);
this.flpProperties.ResumeLayout(false); this.flpProperties.ResumeLayout(false);
this.flpProperties.PerformLayout(); this.flpProperties.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudTextSize)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.nudTextSize)).EndInit();

View file

@ -77,6 +77,11 @@ public TextDrawingInputBox(string text, TextDrawingOptions options)
UpdateVerticalAlignmentImage(); UpdateVerticalAlignmentImage();
} }
private void TextDrawingInputBox_Shown(object sender, EventArgs e)
{
this.ForceActivate();
}
private void cbFonts_SelectedIndexChanged(object sender, EventArgs e) private void cbFonts_SelectedIndexChanged(object sender, EventArgs e)
{ {
Options.Font = cbFonts.SelectedItem as string; Options.Font = cbFonts.SelectedItem as string;

View file

@ -56,7 +56,7 @@ public override void Draw(Graphics g)
public override void DrawFinal(Graphics g, Bitmap bmp) public override void DrawFinal(Graphics g, Bitmap bmp)
{ {
if (!string.IsNullOrEmpty(Text)) if (!string.IsNullOrEmpty(Text) && Rectangle.Width > 10 && Rectangle.Height > 10)
{ {
DrawText(g); DrawText(g);
} }
@ -65,14 +65,12 @@ public override void DrawFinal(Graphics g, Bitmap bmp)
private void DrawText(Graphics g) private void DrawText(Graphics g)
{ {
using (Font font = new Font(Options.Font, Options.Size, Options.Style)) using (Font font = new Font(Options.Font, Options.Size, Options.Style))
using (Brush textBrush = new SolidBrush(Options.Color))
using (StringFormat sf = new StringFormat { Alignment = Options.AlignmentHorizontal, LineAlignment = Options.AlignmentVertical }) using (StringFormat sf = new StringFormat { Alignment = Options.AlignmentHorizontal, LineAlignment = Options.AlignmentVertical })
{
using (Brush textBrush = new SolidBrush(Options.Color))
{ {
g.DrawString(Text, font, textBrush, Rectangle, sf); g.DrawString(Text, font, textBrush, Rectangle, sf);
} }
} }
}
private void UpdateText() private void UpdateText()
{ {

View file

@ -59,7 +59,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="AnnotationOptions.cs" /> <Compile Include="Shapes\AnnotationOptions.cs" />
<Compile Include="Enums.cs" /> <Compile Include="Enums.cs" />
<Compile Include="Forms\RectangleRegionAnnotateForm.cs"> <Compile Include="Forms\RectangleRegionAnnotateForm.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
@ -92,7 +92,7 @@
<Compile Include="Shapes\BaseShape.cs" /> <Compile Include="Shapes\BaseShape.cs" />
<Compile Include="Shapes\Drawing\ArrowDrawingShape.cs" /> <Compile Include="Shapes\Drawing\ArrowDrawingShape.cs" />
<Compile Include="Shapes\Drawing\BaseDrawingShape.cs" /> <Compile Include="Shapes\Drawing\BaseDrawingShape.cs" />
<Compile Include="Shapes\Drawing\TextDrawingOptions.cs" /> <Compile Include="Shapes\TextDrawingOptions.cs" />
<Compile Include="Shapes\Drawing\TextDrawingShape.cs" /> <Compile Include="Shapes\Drawing\TextDrawingShape.cs" />
<Compile Include="Shapes\Effect\BlurEffectShape.cs" /> <Compile Include="Shapes\Effect\BlurEffectShape.cs" />
<Compile Include="Shapes\Drawing\EllipseDrawingShape.cs" /> <Compile Include="Shapes\Drawing\EllipseDrawingShape.cs" />