Skip to content

Commit

Permalink
use attribute when create textbox
Browse files Browse the repository at this point in the history
  • Loading branch information
rcktrncn committed Aug 2, 2021
1 parent feb1a47 commit 285b206
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions taskt/UI/CustomControls/CommandControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,18 @@ public static Control CreateDefaultInputFor(string parameterName, Core.Automatio
{
variableProperties = pInfo;
}
return CreateDefaultInputFor(parameterName, parent, 30, 300);

var setting = (Core.Automation.Attributes.PropertyAttributes.PropertyTextBoxSetting)variableProperties.GetCustomAttribute(typeof(Core.Automation.Attributes.PropertyAttributes.PropertyTextBoxSetting));
if (setting == null)
{
return CreateDefaultInputFor(parameterName, parent, 30, 300, true);
}
else
{
return CreateDefaultInputFor(parameterName, parent, setting.height * 30, 300, setting.allowNewLine);
}
}
public static Control CreateDefaultInputFor(string parameterName, Core.Automation.Commands.ScriptCommand parent, int height = 30, int width = 300)
public static Control CreateDefaultInputFor(string parameterName, Core.Automation.Commands.ScriptCommand parent, int height = 30, int width = 300, bool allowNewLine = true)
{
var inputBox = new TextBox();
//inputBox.Font = new Font("Segoe UI", 12, FontStyle.Regular);
Expand All @@ -332,13 +341,19 @@ public static Control CreateDefaultInputFor(string parameterName, Core.Automatio
inputBox.ForeColor = theme.FontColor;
inputBox.BackColor = theme.BackColor;
inputBox.DataBindings.Add("Text", parent, parameterName, false, DataSourceUpdateMode.OnPropertyChanged);
inputBox.Height = height;
inputBox.Width = width;

if (inputBox.Height != 30)

if (!allowNewLine)
{
inputBox.KeyDown += (sender, e) => TextBoxKeyDown(sender, e);
inputBox.ScrollBars = ScrollBars.None;
}
else
{
inputBox.Multiline = true;
inputBox.ScrollBars = ScrollBars.Vertical;
}
inputBox.Height = height;
inputBox.Width = width;

inputBox.Name = parameterName;
return inputBox;
Expand Down Expand Up @@ -994,6 +1009,15 @@ private static void ShowDLLExplorer(object sender, EventArgs e)
}
}

private static void TextBoxKeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
e.SuppressKeyPress = true;
e.Handled = true;
}
}

private static void ComboBoxKeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
ComboBox trg = (ComboBox)sender;
Expand Down

0 comments on commit 285b206

Please sign in to comment.