Witam.
Uczę się programować w C# w Visual Studio 2010.
Potrzebuję usunąć wszystkie kontrolki typu TextBox z formy. Używam do tego pętli foreach do wyszukania kontrolek i metody Dispose() do usunięcia. Problem jest tego typu, że usuwa mi co 2 kontrolkę? Gdzie mam błąd?
Oto kod:
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 WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Control.ControlCollection coll = this.Controls;
foreach (Control c in coll)
{
if (c.GetType().ToString() == "System.Windows.Forms.TextBox")
{
MessageBox.Show("OK:" + c.GetType(), "Index: " + c.Name, MessageBoxButtons.OK, MessageBoxIcon.Information);
c.Dispose();
}
}
}
}
}