![](/img/trans.png)
[英]How to input comma separated Hex values into a textbox and output as hex values, c#
[英]How to use a textbox to input multiple HEX values into an array in c#
我正在尝试使用文本框控件,以便用户可以在其中输入十六进制值,然后按Enter键并将其存储在数组中。 然后输入另一个十六进制值,按Enter键,它将存储在数组中。
我是编程新手,所以也许有比文本框更合适的控件可以执行此操作?
这是我到目前为止提出的代码,但是我不确定在用户按下Enter键时如何清除文本框,也许还有一些更适合输入值的东西?
任何帮助,将不胜感激!
private void Test_TextChanged(object sender, EventArgs e)
{
string hexString = Test.Text;
int num = Int32.Parse(hexString, System.Globalization.NumberStyles.HexNumber);
int[] arr = new int[20];
for (uint i = 0; i < 5; i++)
{
arr[i] = num;
ReadValue.Text = num.ToString();
}
}
您可以使用NumericUpDown
控件并将其Hexadecimal
属性设置为true
。 比您可以使用他的KeyDown事件
private List<int> hexValues = new List<int>();
private void numericUpDown1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
hexValues.Add(Convert.ToInt32(numericUpDown1.Value));
// Reset the value.
numericUpDown1.Value = Decimal.Zero;
}
}
然后,如果需要数组:
int[] hexValuesArray = hexValues.ToArray();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.