前提・実現したいこと
Visual C#で動的にテキストボックスを追加や削除などの管理がしたい
発生している問題
- 追加したテキストボックス等(コントロール)を削除したり管理する方法が分からない
該当のソースコード
C#
1using System; 2using System.Collections.Generic; 3using System.ComponentModel; 4using System.Data; 5using System.Drawing; 6using System.Linq; 7using System.Text; 8using System.Threading.Tasks; 9using System.Windows.Forms; 10using static System.Net.Mime.MediaTypeNames; 11 12namespace 動的なコントロールの実験 13{ 14 public partial class Form1 : Form 15 { 16 //何件追加したか 17 public int Addcounter = 0; 18 public Form1() 19 { 20 InitializeComponent(); 21 TextBox txt0 = new TextBox(); 22 txt0.Location = new Point(12, 12); 23 txt0.Size = new Size(100, 19); 24 txt0.TabIndex = 2; 25 Controls.Add(txt0); 26 Addcounter++; 27 } 28 private void Addbutton_Click(object sender, EventArgs e) 29 { 30 TextBox txt = new TextBox(); 31 txt.Location = new Point(12, 12 + Addcounter * 25); 32 txt.Size = new Size(100, 19); 33 txt.TabIndex = 2; 34 Controls.Add(txt); 35 Addcounter++; 36 } 37 38 private void Delbutton_Click(object sender, EventArgs e) 39 { 40 //削除したい 41 } 42 } 43}
試したこと
追加ボタンを押すとテキストボックスを等間隔に追加することはできました
補足情報(FW/ツールのバージョンなど)
もっと効率的な管理方法がありましたらぜひご教授願いたいです
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/03/05 14:54