Hello all iam new to windows service want to understand how to implement this logic radio butto either we are selecting decimal we will restrict textbox with decimal validation if we select hexa then hexadecimal validation and when switching between radio button the input in textbox should covert decimal to hexadecimal and vice versa.decimal will be in octet format
Implementation/logic of textbox input based on selection radio button
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Ijas AhamedRank #708 · 3.3K reputationPosted Feb 4, 2023, 3:32 PM EST
Here is a simple code in C# that implements the logic you described:
using System; using System.Windows.Forms; namespace WindowsServiceExample { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void radioButtonDecimal_CheckedChanged(object sender, EventArgs e) { if (radioButtonDecimal.Checked) { textBox1.Text = Convert.ToInt32(textBox1.Text, 16).ToString(); textBox1.KeyPress += TextBox1_KeyPressDecimal; } else { textBox1.Text = Convert.ToString(Convert.ToInt32(textBox1.Text), 16); textBox1.KeyPress -= TextBox1_KeyPressDecimal; textBox1.KeyPress += TextBox1_KeyPressHexadecimal; } } private void TextBox1_KeyPressDecimal(object sender, KeyPressEventArgs e) { if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && (e.KeyChar != '.')) { e.Handled = true; } } private void TextBox1_KeyPressHexadecimal(object sender, KeyPressEventArgs e) { if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && !(char.IsLetter(e.KeyChar) && char.ToUpperInvariant(e.KeyChar) >= 'A' && char.ToUpperInvariant(