Added font selection to input box

This commit is contained in:
Jaex 2016-05-20 03:47:04 +03:00
parent 54d4633f0f
commit 60016ecd9f
3 changed files with 72 additions and 22 deletions

View file

@ -38,12 +38,17 @@ private void InitializeComponent()
this.cbUnderline = new System.Windows.Forms.CheckBox();
this.btnOK = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.lblFont = new System.Windows.Forms.Label();
this.cbFonts = new System.Windows.Forms.ComboBox();
this.flpProperties.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudTextSize)).BeginInit();
this.SuspendLayout();
//
// txtInput
//
this.txtInput.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtInput.Location = new System.Drawing.Point(8, 40);
this.txtInput.Multiline = true;
this.txtInput.Name = "txtInput";
@ -55,23 +60,24 @@ private void InitializeComponent()
//
this.btnTextColor.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.btnTextColor.Color = System.Drawing.Color.Empty;
this.btnTextColor.Location = new System.Drawing.Point(204, 3);
this.btnTextColor.Location = new System.Drawing.Point(319, 3);
this.btnTextColor.Name = "btnTextColor";
this.btnTextColor.Size = new System.Drawing.Size(120, 24);
this.btnTextColor.Size = new System.Drawing.Size(24, 24);
this.btnTextColor.TabIndex = 1;
this.btnTextColor.Text = "Text color";
this.btnTextColor.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.btnTextColor.UseVisualStyleBackColor = true;
this.btnTextColor.ColorChanged += new ShareX.HelpersLib.ColorButton.ColorChangedEventHandler(this.btnTextColor_ColorChanged);
//
// flpProperties
//
this.flpProperties.Controls.Add(this.lblFont);
this.flpProperties.Controls.Add(this.cbFonts);
this.flpProperties.Controls.Add(this.lblTextSize);
this.flpProperties.Controls.Add(this.nudTextSize);
this.flpProperties.Controls.Add(this.btnTextColor);
this.flpProperties.Controls.Add(this.cbBold);
this.flpProperties.Controls.Add(this.cbItalic);
this.flpProperties.Controls.Add(this.cbUnderline);
this.flpProperties.Controls.Add(this.btnTextColor);
this.flpProperties.Location = new System.Drawing.Point(8, 5);
this.flpProperties.Name = "flpProperties";
this.flpProperties.Size = new System.Drawing.Size(472, 32);
@ -81,17 +87,17 @@ private void InitializeComponent()
//
this.lblTextSize.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.lblTextSize.AutoSize = true;
this.lblTextSize.Location = new System.Drawing.Point(0, 8);
this.lblTextSize.Margin = new System.Windows.Forms.Padding(0);
this.lblTextSize.Location = new System.Drawing.Point(227, 8);
this.lblTextSize.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0);
this.lblTextSize.Name = "lblTextSize";
this.lblTextSize.Size = new System.Drawing.Size(52, 13);
this.lblTextSize.Size = new System.Drawing.Size(30, 13);
this.lblTextSize.TabIndex = 2;
this.lblTextSize.Text = "Text size:";
this.lblTextSize.Text = "Size:";
//
// nudTextSize
//
this.nudTextSize.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.nudTextSize.Location = new System.Drawing.Point(55, 5);
this.nudTextSize.Location = new System.Drawing.Point(260, 5);
this.nudTextSize.Minimum = new decimal(new int[] {
5,
0,
@ -112,7 +118,7 @@ private void InitializeComponent()
//
this.cbBold.Appearance = System.Windows.Forms.Appearance.Button;
this.cbBold.Image = global::ShareX.ScreenCaptureLib.Properties.Resources.edit_bold;
this.cbBold.Location = new System.Drawing.Point(114, 3);
this.cbBold.Location = new System.Drawing.Point(349, 3);
this.cbBold.Name = "cbBold";
this.cbBold.Size = new System.Drawing.Size(24, 24);
this.cbBold.TabIndex = 4;
@ -123,7 +129,7 @@ private void InitializeComponent()
//
this.cbItalic.Appearance = System.Windows.Forms.Appearance.Button;
this.cbItalic.Image = global::ShareX.ScreenCaptureLib.Properties.Resources.edit_italic;
this.cbItalic.Location = new System.Drawing.Point(144, 3);
this.cbItalic.Location = new System.Drawing.Point(379, 3);
this.cbItalic.Name = "cbItalic";
this.cbItalic.Size = new System.Drawing.Size(24, 24);
this.cbItalic.TabIndex = 5;
@ -134,7 +140,7 @@ private void InitializeComponent()
//
this.cbUnderline.Appearance = System.Windows.Forms.Appearance.Button;
this.cbUnderline.Image = global::ShareX.ScreenCaptureLib.Properties.Resources.edit_underline;
this.cbUnderline.Location = new System.Drawing.Point(174, 3);
this.cbUnderline.Location = new System.Drawing.Point(409, 3);
this.cbUnderline.Name = "cbUnderline";
this.cbUnderline.Size = new System.Drawing.Size(24, 24);
this.cbUnderline.TabIndex = 6;
@ -143,6 +149,7 @@ private void InitializeComponent()
//
// btnOK
//
this.btnOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnOK.Location = new System.Drawing.Point(264, 328);
this.btnOK.Name = "btnOK";
this.btnOK.Size = new System.Drawing.Size(104, 24);
@ -153,6 +160,7 @@ private void InitializeComponent()
//
// btnCancel
//
this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnCancel.Location = new System.Drawing.Point(376, 328);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(104, 24);
@ -161,6 +169,28 @@ private void InitializeComponent()
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// lblFont
//
this.lblFont.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.lblFont.AutoSize = true;
this.lblFont.Location = new System.Drawing.Point(3, 8);
this.lblFont.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0);
this.lblFont.Name = "lblFont";
this.lblFont.Size = new System.Drawing.Size(31, 13);
this.lblFont.TabIndex = 7;
this.lblFont.Text = "Font:";
//
// cbFonts
//
this.cbFonts.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.cbFonts.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbFonts.FormattingEnabled = true;
this.cbFonts.Location = new System.Drawing.Point(37, 4);
this.cbFonts.Name = "cbFonts";
this.cbFonts.Size = new System.Drawing.Size(184, 21);
this.cbFonts.TabIndex = 8;
this.cbFonts.SelectedIndexChanged += new System.EventHandler(this.cbFonts_SelectedIndexChanged);
//
// TextDrawingInputBox
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -197,5 +227,7 @@ private void InitializeComponent()
private System.Windows.Forms.CheckBox cbBold;
private System.Windows.Forms.CheckBox cbItalic;
private System.Windows.Forms.CheckBox cbUnderline;
private System.Windows.Forms.Label lblFont;
private System.Windows.Forms.ComboBox cbFonts;
}
}

View file

@ -62,8 +62,24 @@ public TextDrawingInputBox(string inputText, string textFont, Color textColor, i
UpdateInputBox();
btnTextColor.Color = TextColor;
cbFonts.Items.AddRange(FontFamily.Families.Select(x => x.Name).ToArray());
if (cbFonts.Items.Contains(textFont))
{
cbFonts.SelectedItem = textFont;
}
else
{
cbFonts.SelectedItem = "Arial";
}
nudTextSize.Value = TextSize;
btnTextColor.Color = TextColor;
}
private void cbFonts_SelectedIndexChanged(object sender, EventArgs e)
{
UpdateInputBox();
}
private void nudTextSize_ValueChanged(object sender, EventArgs e)
@ -71,6 +87,11 @@ private void nudTextSize_ValueChanged(object sender, EventArgs e)
UpdateInputBox();
}
private void btnTextColor_ColorChanged(Color color)
{
UpdateInputBox();
}
private void cbBold_CheckedChanged(object sender, EventArgs e)
{
UpdateInputBox();
@ -86,11 +107,6 @@ private void cbUnderline_CheckedChanged(object sender, EventArgs e)
UpdateInputBox();
}
private void btnTextColor_ColorChanged(Color color)
{
UpdateInputBox();
}
private void UpdateInputBox()
{
FontStyle fontStyle = FontStyle.Regular;
@ -110,7 +126,7 @@ private void UpdateInputBox()
fontStyle |= FontStyle.Underline;
}
txtInput.Font = new Font(TextFont, (float)nudTextSize.Value, fontStyle);
txtInput.Font = new Font(cbFonts.SelectedItem as string, (float)nudTextSize.Value, fontStyle);
txtInput.ForeColor = btnTextColor.Color;
}
@ -118,8 +134,9 @@ private void UpdateInputBox()
private void btnOK_Click(object sender, EventArgs e)
{
InputText = txtInput.Text;
TextColor = btnTextColor.Color;
TextFont = cbFonts.SelectedItem as string;
TextSize = (int)nudTextSize.Value;
TextColor = btnTextColor.Color;
TextBold = cbBold.Checked;
TextItalic = cbItalic.Checked;
TextUnderline = cbUnderline.Checked;

View file

@ -40,7 +40,7 @@ public class TextDrawingShape : BaseDrawingShape
public override ShapeType ShapeType { get; } = ShapeType.DrawingText;
public string Text { get; set; }
public string TextFont { get; set; } = "Verdana";
public string TextFont { get; set; } = "Arial";
public int TextSize { get; set; } = 18;
public bool TextBold { get; set; }
public bool TextItalic { get; set; }
@ -102,8 +102,9 @@ private void UpdateText()
if (inputBox.ShowDialog() == DialogResult.OK)
{
Text = inputBox.InputText;
BorderColor = inputBox.TextColor;
TextFont = inputBox.TextFont;
TextSize = inputBox.TextSize;
BorderColor = inputBox.TextColor;
TextBold = inputBox.TextBold;
TextItalic = inputBox.TextItalic;
TextUnderline = inputBox.TextUnderline;