質問編集履歴

4

コード修正

2023/04/04 09:43

投稿

kitkatl0
kitkatl0

スコア1

test CHANGED
File without changes
test CHANGED
@@ -32,120 +32,3 @@
32
32
  ・conを複数重ねて配置するとAnchorがうまく動作しない事例はご存知でしょうか
33
33
  ・改善方法はありますでしょうか。![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-04-04/fc8d0c3f-7dec-408e-908a-4102c256dc42.png)
34
34
 
35
- ○コード
36
- ```C#
37
- public void TabAdd(TabControl base_tabcon1, string base_tabpage_text, string base_tabpage_name,
38
- TabControl source_tabcon2, TabControl source_tabcon3, int tab_index)
39
- {
40
- // 引数内容:
41
- // base_tabcon1 : tabControl1
42
- // base_tabpage_text : tabControl1に追加するタブ名  例)"tabPage2"
43
- // base_tabpage_name : tabControl1に追加するタブのTabPeges/メンバー名  例)"tabPage2"
44
- // source_tabcon2 : tabControl2
45
- // source_tabcon3 : tabControl3
46
- // tab_index : tabControl1に追加するタブのインデックス番号  例)1
47
-
48
- // tabControl2、3 のタブ名を格納する配列
49
- string[] tabcon2_tabname_arr = new string[source_tabcon2.TabPages.Count];
50
- string[] tabcon3_tabname_arr = new string[source_tabcon3.TabPages.Count];
51
-
52
- // tabControl2、3 のタブのTabPeges/メンバー名を格納するための配列
53
- string[] tabcon2_tabmembername_arr = new string[source_tabcon2.TabPages.Count];
54
- string[] tabcon3_tabmembername_arr = new string[source_tabcon3.TabPages.Count];
55
-
56
- // foreach でループ時に使うインデックス番号 - ネストしてるので2つ定義
57
- int index_cnt = 0;
58
- int index_cnt2 = 0;
59
-
60
- // TabControl1 に新規タブページ追加
61
- TabPage newTabPage = new TabPage();
62
- newTabPage.Text = base_tabpage_text;
63
- base_tabcon1.TabPages.Add(newTabPage);
64
- base_tabcon1.TabPages[tab_index - 1].Name = base_tabpage_name;
65
-
66
- // TabControl4 作成
67
- TabControl new_tabcon4 = new TabControl();
68
-
69
- // TabControl2 のプロパティを TabControl4 にコピー
70
- new_tabcon4.Size = source_tabcon2.Size;
71
- new_tabcon4.Location = source_tabcon2.Location;
72
- new_tabcon4.Anchor = source_tabcon2.Anchor;
73
- new_tabcon4.Name = source_tabcon2.Name + tab_index;
74
-
75
- // TabControl2 のタブ名を取得して配列に格納
76
- foreach (TabPage tabPage in source_tabcon2.TabPages)
77
- {
78
- tabcon2_tabname_arr[index_cnt] = tabPage.AccessibilityObject.Name;
79
- foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(tabPage))
80
- {
81
- if (prop.Name == "Name")
82
- {
83
- string get_prop_name = prop.GetValue(tabPage).ToString();
84
- tabcon2_tabmembername_arr[index_cnt] = get_prop_name + tab_index;
85
- index_cnt++;
86
- }
87
- }
88
- }
89
-
90
- index_cnt = 0;
91
-
92
- // TabControl3 のタブ名を取得して配列に格納
93
- foreach (TabPage tabPage in source_tabcon3.TabPages)
94
- {
95
- tabcon3_tabname_arr[index_cnt] = tabPage.AccessibilityObject.Name;
96
- foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(tabPage))
97
- {
98
- if (prop.Name == "Name")
99
- {
100
- string get_prop_name = prop.GetValue(tabPage).ToString();
101
- tabcon3_tabmembername_arr[index_cnt] = get_prop_name + tab_index;
102
- index_cnt++;
103
- }
104
- }
105
- }
106
-
107
- index_cnt = 0;
108
-
109
- // TabControl2 のタブと同名のタブを TabControl4 に追加
110
- foreach (string name in tabcon2_tabname_arr)
111
- {
112
- TabPage tabcon4_newtabpage = new TabPage();
113
- tabcon4_newtabpage.Text = name;
114
- tabcon4_newtabpage.Name = tabcon2_tabname_arr[index_cnt];
115
-
116
- // TabControl5 作成
117
- TabControl new_tabcon5 = new TabControl();
118
-
119
- // TabControl3 プロパティを TabControl5 にコピー
120
- new_tabcon5.Width = source_tabcon3.Width - 10;
121
- new_tabcon5.Height = source_tabcon3.Height;
122
- new_tabcon5.Location = source_tabcon3.Location;
123
- new_tabcon5.Dock = DockStyle.Fill; // KOZ6.0様からアドバイス頂いたコードを追加
124
- new_tabcon5.Anchor = source_tabcon2.Anchor;
125
- new_tabcon5.Name = source_tabcon3.Name + tab_index;
126
-
127
- // TabControl3 のタブと同名のタブを TabControl5 に追加
128
- foreach (string name2 in tabcon3_tabname_arr)
129
- {
130
- TabPage tabcon5_newtabpage = new TabPage();
131
- tabcon5_newtabpage.Text = name2;
132
- tabcon5_newtabpage.Name = tabcon3_tabname_arr[index_cnt2];
133
- index_cnt2++;
134
- new_tabcon5.TabPages.Add(tabcon5_newtabpage);
135
- }
136
- index_cnt2 = 0;
137
-
138
- // TabControl4 のタブに TabControl5 を追加
139
- tabcon4_newtabpage.Controls.Add(new_tabcon5);
140
-
141
- // TabControl4 に TabControl5 が含まれたタブを追加
142
- new_tabcon4.TabPages.Add(tabcon4_newtabpage);
143
-
144
- index_cnt++;
145
- }
146
-
147
- // TabControl1 にタブに TabControl4 を追加
148
- newTabPage.Controls.Add(new_tabcon4);
149
- }
150
- ```
151
-

3

コード追加

2023/04/04 09:29

投稿

kitkatl0
kitkatl0

スコア1

test CHANGED
File without changes
test CHANGED
@@ -33,6 +33,7 @@
33
33
  ・改善方法はありますでしょうか。![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-04-04/fc8d0c3f-7dec-408e-908a-4102c256dc42.png)
34
34
 
35
35
  ○コード
36
+ ```C#
36
37
  public void TabAdd(TabControl base_tabcon1, string base_tabpage_text, string base_tabpage_name,
37
38
  TabControl source_tabcon2, TabControl source_tabcon3, int tab_index)
38
39
  {
@@ -146,4 +147,5 @@
146
147
  // TabControl1 にタブに TabControl4 を追加
147
148
  newTabPage.Controls.Add(new_tabcon4);
148
149
  }
150
+ ```
149
151
 

2

コードを追加しました

2023/04/04 09:28

投稿

kitkatl0
kitkatl0

スコア1

test CHANGED
File without changes
test CHANGED
@@ -32,3 +32,118 @@
32
32
  ・conを複数重ねて配置するとAnchorがうまく動作しない事例はご存知でしょうか
33
33
  ・改善方法はありますでしょうか。![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2023-04-04/fc8d0c3f-7dec-408e-908a-4102c256dc42.png)
34
34
 
35
+ ○コード
36
+ public void TabAdd(TabControl base_tabcon1, string base_tabpage_text, string base_tabpage_name,
37
+ TabControl source_tabcon2, TabControl source_tabcon3, int tab_index)
38
+ {
39
+ // 引数内容:
40
+ // base_tabcon1 : tabControl1
41
+ // base_tabpage_text : tabControl1に追加するタブ名  例)"tabPage2"
42
+ // base_tabpage_name : tabControl1に追加するタブのTabPeges/メンバー名  例)"tabPage2"
43
+ // source_tabcon2 : tabControl2
44
+ // source_tabcon3 : tabControl3
45
+ // tab_index : tabControl1に追加するタブのインデックス番号  例)1
46
+
47
+ // tabControl2、3 のタブ名を格納する配列
48
+ string[] tabcon2_tabname_arr = new string[source_tabcon2.TabPages.Count];
49
+ string[] tabcon3_tabname_arr = new string[source_tabcon3.TabPages.Count];
50
+
51
+ // tabControl2、3 のタブのTabPeges/メンバー名を格納するための配列
52
+ string[] tabcon2_tabmembername_arr = new string[source_tabcon2.TabPages.Count];
53
+ string[] tabcon3_tabmembername_arr = new string[source_tabcon3.TabPages.Count];
54
+
55
+ // foreach でループ時に使うインデックス番号 - ネストしてるので2つ定義
56
+ int index_cnt = 0;
57
+ int index_cnt2 = 0;
58
+
59
+ // TabControl1 に新規タブページ追加
60
+ TabPage newTabPage = new TabPage();
61
+ newTabPage.Text = base_tabpage_text;
62
+ base_tabcon1.TabPages.Add(newTabPage);
63
+ base_tabcon1.TabPages[tab_index - 1].Name = base_tabpage_name;
64
+
65
+ // TabControl4 作成
66
+ TabControl new_tabcon4 = new TabControl();
67
+
68
+ // TabControl2 のプロパティを TabControl4 にコピー
69
+ new_tabcon4.Size = source_tabcon2.Size;
70
+ new_tabcon4.Location = source_tabcon2.Location;
71
+ new_tabcon4.Anchor = source_tabcon2.Anchor;
72
+ new_tabcon4.Name = source_tabcon2.Name + tab_index;
73
+
74
+ // TabControl2 のタブ名を取得して配列に格納
75
+ foreach (TabPage tabPage in source_tabcon2.TabPages)
76
+ {
77
+ tabcon2_tabname_arr[index_cnt] = tabPage.AccessibilityObject.Name;
78
+ foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(tabPage))
79
+ {
80
+ if (prop.Name == "Name")
81
+ {
82
+ string get_prop_name = prop.GetValue(tabPage).ToString();
83
+ tabcon2_tabmembername_arr[index_cnt] = get_prop_name + tab_index;
84
+ index_cnt++;
85
+ }
86
+ }
87
+ }
88
+
89
+ index_cnt = 0;
90
+
91
+ // TabControl3 のタブ名を取得して配列に格納
92
+ foreach (TabPage tabPage in source_tabcon3.TabPages)
93
+ {
94
+ tabcon3_tabname_arr[index_cnt] = tabPage.AccessibilityObject.Name;
95
+ foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(tabPage))
96
+ {
97
+ if (prop.Name == "Name")
98
+ {
99
+ string get_prop_name = prop.GetValue(tabPage).ToString();
100
+ tabcon3_tabmembername_arr[index_cnt] = get_prop_name + tab_index;
101
+ index_cnt++;
102
+ }
103
+ }
104
+ }
105
+
106
+ index_cnt = 0;
107
+
108
+ // TabControl2 のタブと同名のタブを TabControl4 に追加
109
+ foreach (string name in tabcon2_tabname_arr)
110
+ {
111
+ TabPage tabcon4_newtabpage = new TabPage();
112
+ tabcon4_newtabpage.Text = name;
113
+ tabcon4_newtabpage.Name = tabcon2_tabname_arr[index_cnt];
114
+
115
+ // TabControl5 作成
116
+ TabControl new_tabcon5 = new TabControl();
117
+
118
+ // TabControl3 プロパティを TabControl5 にコピー
119
+ new_tabcon5.Width = source_tabcon3.Width - 10;
120
+ new_tabcon5.Height = source_tabcon3.Height;
121
+ new_tabcon5.Location = source_tabcon3.Location;
122
+ new_tabcon5.Dock = DockStyle.Fill; // KOZ6.0様からアドバイス頂いたコードを追加
123
+ new_tabcon5.Anchor = source_tabcon2.Anchor;
124
+ new_tabcon5.Name = source_tabcon3.Name + tab_index;
125
+
126
+ // TabControl3 のタブと同名のタブを TabControl5 に追加
127
+ foreach (string name2 in tabcon3_tabname_arr)
128
+ {
129
+ TabPage tabcon5_newtabpage = new TabPage();
130
+ tabcon5_newtabpage.Text = name2;
131
+ tabcon5_newtabpage.Name = tabcon3_tabname_arr[index_cnt2];
132
+ index_cnt2++;
133
+ new_tabcon5.TabPages.Add(tabcon5_newtabpage);
134
+ }
135
+ index_cnt2 = 0;
136
+
137
+ // TabControl4 のタブに TabControl5 を追加
138
+ tabcon4_newtabpage.Controls.Add(new_tabcon5);
139
+
140
+ // TabControl4 に TabControl5 が含まれたタブを追加
141
+ new_tabcon4.TabPages.Add(tabcon4_newtabpage);
142
+
143
+ index_cnt++;
144
+ }
145
+
146
+ // TabControl1 にタブに TabControl4 を追加
147
+ newTabPage.Controls.Add(new_tabcon4);
148
+ }
149
+

1

開発環境を追加しました。

2023/04/04 04:04

投稿

kitkatl0
kitkatl0

スコア1

test CHANGED
File without changes
test CHANGED
@@ -1,3 +1,9 @@
1
+
2
+ ○開発環境
3
+ OS:Windows 10
4
+ Visual Studio:2022
5
+ 種類:Windows Forms アプリ
6
+ フレームワーク: .NET Framework 4.7.2
1
7
 
2
8
  ○手順
3
9
  以下の手順を実施しました。