Added custom input box for text drawing

This commit is contained in:
Jaex 2016-05-20 01:57:49 +03:00
parent f2c7257a36
commit 29189deb38
6 changed files with 380 additions and 14 deletions

View file

@ -96,28 +96,28 @@ private void InitializeComponent()
this.btnCancel = new System.Windows.Forms.Button();
this.txtInputText = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
//
// btnOK
//
//
resources.ApplyResources(this.btnOK, "btnOK");
this.btnOK.Name = "btnOK";
this.btnOK.UseVisualStyleBackColor = true;
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
//
//
// btnCancel
//
//
resources.ApplyResources(this.btnCancel, "btnCancel");
this.btnCancel.Name = "btnCancel";
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
//
// txtInputText
//
//
resources.ApplyResources(this.txtInputText, "txtInputText");
this.txtInputText.Name = "txtInputText";
//
//
// InputBox
//
//
this.AcceptButton = this.btnOK;
resources.ApplyResources(this, "$this");
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
@ -133,7 +133,6 @@ private void InitializeComponent()
this.Shown += new System.EventHandler(this.InputBox_Shown);
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.Button btnOK;

View file

@ -0,0 +1,156 @@
namespace ShareX.ScreenCaptureLib
{
partial class TextDrawingInputBox
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.txtInput = new System.Windows.Forms.TextBox();
this.btnTextColor = new ShareX.HelpersLib.ColorButton();
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
this.lblTextSize = new System.Windows.Forms.Label();
this.nudTextSize = new System.Windows.Forms.NumericUpDown();
this.btnOK = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.flowLayoutPanel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudTextSize)).BeginInit();
this.SuspendLayout();
//
// txtInput
//
this.txtInput.Location = new System.Drawing.Point(8, 40);
this.txtInput.Multiline = true;
this.txtInput.Name = "txtInput";
this.txtInput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtInput.Size = new System.Drawing.Size(472, 280);
this.txtInput.TabIndex = 0;
//
// btnTextColor
//
this.btnTextColor.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.btnTextColor.Color = System.Drawing.Color.Empty;
this.btnTextColor.Location = new System.Drawing.Point(0, 3);
this.btnTextColor.Margin = new System.Windows.Forms.Padding(0, 3, 3, 3);
this.btnTextColor.Name = "btnTextColor";
this.btnTextColor.Size = new System.Drawing.Size(120, 23);
this.btnTextColor.TabIndex = 1;
this.btnTextColor.Text = "Text color";
this.btnTextColor.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnTextColor.UseVisualStyleBackColor = true;
//
// flowLayoutPanel1
//
this.flowLayoutPanel1.Controls.Add(this.btnTextColor);
this.flowLayoutPanel1.Controls.Add(this.lblTextSize);
this.flowLayoutPanel1.Controls.Add(this.nudTextSize);
this.flowLayoutPanel1.Location = new System.Drawing.Point(8, 8);
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
this.flowLayoutPanel1.Size = new System.Drawing.Size(472, 32);
this.flowLayoutPanel1.TabIndex = 2;
//
// lblTextSize
//
this.lblTextSize.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.lblTextSize.AutoSize = true;
this.lblTextSize.Location = new System.Drawing.Point(126, 8);
this.lblTextSize.Name = "lblTextSize";
this.lblTextSize.Size = new System.Drawing.Size(52, 13);
this.lblTextSize.TabIndex = 2;
this.lblTextSize.Text = "Text size:";
//
// nudTextSize
//
this.nudTextSize.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.nudTextSize.Location = new System.Drawing.Point(184, 4);
this.nudTextSize.Minimum = new decimal(new int[] {
5,
0,
0,
0});
this.nudTextSize.Name = "nudTextSize";
this.nudTextSize.Size = new System.Drawing.Size(53, 20);
this.nudTextSize.TabIndex = 3;
this.nudTextSize.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.nudTextSize.Value = new decimal(new int[] {
10,
0,
0,
0});
this.nudTextSize.ValueChanged += new System.EventHandler(this.nudTextSize_ValueChanged);
//
// btnOK
//
this.btnOK.Location = new System.Drawing.Point(264, 328);
this.btnOK.Name = "btnOK";
this.btnOK.Size = new System.Drawing.Size(104, 24);
this.btnOK.TabIndex = 3;
this.btnOK.Text = "OK";
this.btnOK.UseVisualStyleBackColor = true;
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
//
// btnCancel
//
this.btnCancel.Location = new System.Drawing.Point(376, 328);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(104, 24);
this.btnCancel.TabIndex = 4;
this.btnCancel.Text = "Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// TextDrawingInputBox
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(488, 360);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOK);
this.Controls.Add(this.flowLayoutPanel1);
this.Controls.Add(this.txtInput);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
this.Name = "TextDrawingInputBox";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "ShareX - Text input";
this.TopMost = true;
this.flowLayoutPanel1.ResumeLayout(false);
this.flowLayoutPanel1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudTextSize)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox txtInput;
private HelpersLib.ColorButton btnTextColor;
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
private System.Windows.Forms.Label lblTextSize;
private System.Windows.Forms.NumericUpDown nudTextSize;
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.Button btnCancel;
}
}

View file

@ -0,0 +1,78 @@
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright (c) 2007-2016 ShareX Team
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
*/
#endregion License Information (GPL v3)
using ShareX.HelpersLib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ShareX.ScreenCaptureLib
{
internal partial class TextDrawingInputBox : Form
{
public string InputText { get; private set; }
public Color TextColor { get; private set; }
public int TextSize { get; private set; }
public TextDrawingInputBox(string inputText, Color textColor, int textSize)
{
InitializeComponent();
Icon = ShareXResources.Icon;
if (inputText != null)
{
txtInput.Text = inputText;
}
txtInput.Font = new Font(txtInput.Font.FontFamily, textSize);
btnTextColor.Color = textColor;
nudTextSize.Value = textSize;
}
private void nudTextSize_ValueChanged(object sender, EventArgs e)
{
txtInput.Font = new Font(txtInput.Font.FontFamily, (float)nudTextSize.Value);
}
private void btnOK_Click(object sender, EventArgs e)
{
InputText = txtInput.Text;
TextColor = btnTextColor.Color;
TextSize = (int)nudTextSize.Value;
DialogResult = DialogResult.OK;
}
private void btnCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
}
}
}

View file

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View file

@ -39,6 +39,7 @@ public class TextDrawingShape : BaseDrawingShape
public override ShapeType ShapeType { get; } = ShapeType.DrawingText;
public string Text { get; set; }
public int TextSize { get; set; } = 18;
public override void Draw(Graphics g)
{
@ -60,7 +61,7 @@ public override void DrawFinal(Graphics g, Bitmap bmp)
private void DrawText(Graphics g)
{
using (Font font = new Font("Verdana", 18))
using (Font font = new Font("Verdana", TextSize))
using (StringFormat sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center })
{
using (Brush textBrush = new SolidBrush(BorderColor))
@ -72,11 +73,14 @@ private void DrawText(Graphics g)
private void UpdateText()
{
string text = InputBox.GetInputText(null, Text);
if (text != null)
using (TextDrawingInputBox inputBox = new TextDrawingInputBox(Text, BorderColor, TextSize))
{
Text = text;
if (inputBox.ShowDialog() == DialogResult.OK)
{
Text = inputBox.InputText;
BorderColor = inputBox.TextColor;
TextSize = inputBox.TextSize;
}
}
}

View file

@ -72,6 +72,12 @@
<Compile Include="Forms\ScrollingCaptureForm.Designer.cs">
<DependentUpon>ScrollingCaptureForm.cs</DependentUpon>
</Compile>
<Compile Include="Forms\TextDrawingInputBox.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\TextDrawingInputBox.Designer.cs">
<DependentUpon>TextDrawingInputBox.cs</DependentUpon>
</Compile>
<Compile Include="Forms\WebpageCaptureForm.cs">
<SubType>Form</SubType>
</Compile>
@ -210,6 +216,9 @@
<EmbeddedResource Include="Forms\ScrollingCaptureForm.zh-CN.resx">
<DependentUpon>ScrollingCaptureForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\TextDrawingInputBox.resx">
<DependentUpon>TextDrawingInputBox.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\WebpageCaptureForm.de.resx">
<DependentUpon>WebpageCaptureForm.cs</DependentUpon>
</EmbeddedResource>