Exemplo n.º 1
0
        private void textBoxValue_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (_preventTextBoxEvents)
            {
                return;
            }
            _preventTextBoxEvents = true;
            try
            {
                try
                {
                    switch (comboBoxType.SelectedItem.ToString())
                    {
                    case "byte": textBoxHex.Text = byte.Parse(textBoxValue.Text).ToString("X2"); break;

                    case "sbyte": textBoxHex.Text = sbyte.Parse(textBoxValue.Text).ToString("X2"); break;

                    case "ushort": textBoxHex.Text = TeraPacketWithData.toHex(BitConverter.GetBytes(ushort.Parse(textBoxValue.Text))); break;

                    case "short": textBoxHex.Text = TeraPacketWithData.toHex(BitConverter.GetBytes(short.Parse(textBoxValue.Text))); break;

                    case "uint": textBoxHex.Text = TeraPacketWithData.toHex(BitConverter.GetBytes(uint.Parse(textBoxValue.Text))); break;

                    case "int": textBoxHex.Text = TeraPacketWithData.toHex(BitConverter.GetBytes(int.Parse(textBoxValue.Text))); break;

                    case "ulong": textBoxHex.Text = TeraPacketWithData.toHex(BitConverter.GetBytes(ulong.Parse(textBoxValue.Text))); break;

                    case "long": textBoxHex.Text = TeraPacketWithData.toHex(BitConverter.GetBytes(long.Parse(textBoxValue.Text))); break;

                    case "float": textBoxHex.Text = TeraPacketWithData.toHex(BitConverter.GetBytes(float.Parse(textBoxValue.Text))); break;

                    case "double": textBoxHex.Text = TeraPacketWithData.toHex(BitConverter.GetBytes(double.Parse(textBoxValue.Text))); break;

                    case "singleChar": textBoxHex.Text = TeraPacketWithData.toHex(BitConverter.GetBytes(char.Parse(textBoxValue.Text))); break;

                    case "doubleChar": textBoxHex.Text = TeraPacketWithData.toHex(BitConverter.GetBytes(char.Parse(textBoxValue.Text))); break;

                    case "singleString": textBoxHex.Text = TeraPacketWithData.toHex(TeraPacketWithData.fromSingleString(textBoxValue.Text)); break;

                    case "doubleString": textBoxHex.Text = TeraPacketWithData.toHex(TeraPacketWithData.fromDoubleString(textBoxValue.Text)); break;

                    case "bool": textBoxHex.Text = TeraPacketWithData.toHex(BitConverter.GetBytes(bool.Parse(textBoxValue.Text))); break;

                    case "hex": textBoxHex.Text = TeraPacketWithData.toHex(TeraPacketWithData.fromHex(textBoxValue.Text)); break;
                    }
                }
                catch { textBoxHex.Text = "ERROR"; }
            }
            catch { }
            _preventTextBoxEvents = false;
        }