kontrolacisla
Dovolí do comboBox1 psát jen číslo typu float.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Kontrola_vstupu
{
public partial class Form1 : Form
{
Kontrola kontroluj;
public Form1()
{
kontroluj = new Kontrola();
InitializeComponent();
}
private void comboBox1_TextUpdate(object sender, EventArgs e)
{
comboBox1.Text = kontroluj.KonrolaCisla(comboBox1.Text);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Kontrola_vstupu
{
class Kontrola
{
public string KonrolaCisla(string cislo)
{
float a;
if (!float.TryParse(cislo, out a))
{
for (int i = 0; i < cislo.Length; i++)
{
if (!float.TryParse(cislo.Substring(0, i + 1), out a))
{
cislo = cislo.Remove(i, 1);
i--;
}
}
}
return cislo;
}
}
}