
前提・実現したいこと
visualstudio,c#でツールを作成しています。
現在フォーカスが当たっているテキストボックスが、特定の名前のテキストボックス(txt〇〇)のテキストが条件に当てはまったら、次のTabIndexのテキストを非活性にしたいです。
発生している問題・エラーメッセージ
次のテキストボックスのTabIndexの値はとれましたが、TabIndexをキーにしてNameへの変換の仕方がわかりません。
宜しくお願いします。
該当のソースコード
cs
1private void Form1_Shown(object sender, EventArgs e) 2 { 3 this.KeyPreview = true; 4 } 5 6 private void Form1_KeyDown(object sender, KeyEventArgs e) 7 { 8 if (e.KeyCode == Keys.Enter) 9 { 10 ProcessTabKey(true); 11 if (this.ActiveControl.Name.Contains(“foge”)) 12 { 13 int FrNext = this.ActiveControl.TabIndex + 1; 14 } 15 } 16 }
試したこと
以下のようにすると取得できましたが、リストを作成しなければいけなかった為、TabIndexからNameへの変換方法を押し経てただきたいです。
cs
1 2public partial class Form1 : Form 3 { 4 public struct TxtBoxBean 5 { 6 public string tabindex; 7 public TextBox txtbox; 8 } 9 // テキストボックス 10 List<TxtBoxBean> txtboxList = new List<TxtBoxBean>(); 11 public Form1() 12 { 13 InitializeComponent(); 14 } 15 private void Form1_KeyPress(object sender, KeyPressEventArgs e) 16 { 17 txtboxList.Add(new TxtBoxBean { tabindex = "1", txtbox = textBox11 }); 18 txtboxList.Add(new TxtBoxBean { tabindex = "3", txtbox = textBox12 }); 19 txtboxList.Add(new TxtBoxBean { tabindex = "5", txtbox = textBox13 }); 20 txtboxList.Add(new TxtBoxBean { tabindex = "7", txtbox = textBox14 }); 21 txtboxList.Add(new TxtBoxBean { tabindex = "9", txtbox = textBox15 }); 22 txtboxList.Add(new TxtBoxBean { tabindex = "2", txtbox = focas1 }); 23 txtboxList.Add(new TxtBoxBean { tabindex = "4", txtbox = focas2 }); 24 txtboxList.Add(new TxtBoxBean { tabindex = "6", txtbox = focas3 }); 25 txtboxList.Add(new TxtBoxBean { tabindex = "8", txtbox = focas4 }); 26 txtboxList.Add(new TxtBoxBean { tabindex = "10", txtbox = focas5 }); 27 foreach (var boxlist in txtboxList) 28 { 29 TextBox txtName = boxlist.txtbox; 30 if (txtName.Name.Contains("textBox1")) // 特定の文字が含まれているか検索 31 { 32 int txtnum = int.Parse(boxlist.tabindex) + 1; //次のタブインデクス値を取得 33 foreach (var txtlist in txtboxList) 34 { 35 if(txtnum == int.Parse(txtlist.tabindex)) //タブインデクスを検索 36 { 37 if (txtName.Text == "1") 38 { 39 txtlist.txtbox.Enabled = false; //非活性 40 } 41 } 42 } 43 } 44 } 45
補足情報(FW/ツールのバージョンなど)
Visual Stdio 2022
Windows フォーム アプリケーション(.NET Framework)


回答1件
あなたの回答
tips
プレビュー