回答編集履歴
1
見直しキャンペーン中
test
CHANGED
@@ -1,103 +1,52 @@
|
|
1
1
|
[TabControl.Deselecting イベント (System.Windows.Forms) | Microsoft Docs](https://docs.microsoft.com/ja-jp/dotnet/api/system.windows.forms.tabcontrol.deselecting)
|
2
|
-
|
3
2
|
がいいんじゃないでしょうか。
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
```
|
4
|
+
```cs
|
8
|
-
|
9
5
|
using System;
|
10
|
-
|
11
6
|
using System.Drawing;
|
12
|
-
|
13
7
|
using System.Windows.Forms;
|
14
8
|
|
15
|
-
|
16
|
-
|
17
9
|
namespace Questions289215
|
18
|
-
|
19
10
|
{
|
20
|
-
|
21
11
|
public partial class Form1 : Form
|
22
|
-
|
23
12
|
{
|
24
|
-
|
25
13
|
public Form1()
|
26
|
-
|
27
14
|
{
|
28
|
-
|
29
15
|
InitializeComponent();
|
30
16
|
|
31
|
-
|
32
|
-
|
33
17
|
var tabControl = new TabControl { Dock = DockStyle.Fill, };
|
34
|
-
|
35
18
|
tabControl.Deselecting += TabControl_Deselecting;
|
36
|
-
|
37
19
|
Controls.Add(tabControl);
|
38
20
|
|
39
|
-
|
40
|
-
|
41
21
|
for(var i = 1; i < 11; i++)
|
42
|
-
|
43
22
|
{
|
44
|
-
|
45
23
|
var tabPage = new TabPage($"Page{i}");
|
46
|
-
|
47
24
|
tabControl.TabPages.Add(tabPage);
|
48
25
|
|
49
|
-
|
50
|
-
|
51
26
|
tabPage.Controls.Add(new TextBox { Name = "textBox", });
|
52
|
-
|
53
27
|
var button = new Button() { Text = "OK", Location = new Point(0, 30), };
|
54
|
-
|
55
28
|
button.Click += Button_Click;
|
56
|
-
|
57
29
|
tabPage.Controls.Add(button);
|
58
|
-
|
59
30
|
}
|
60
|
-
|
61
31
|
}
|
62
32
|
|
63
|
-
|
64
|
-
|
65
33
|
private void TabControl_Deselecting(object sender, TabControlCancelEventArgs e)
|
66
|
-
|
67
34
|
{
|
68
|
-
|
69
35
|
if(e.TabPage.Tag == null) // OK押してなければ。。。
|
70
|
-
|
71
36
|
{
|
72
|
-
|
73
37
|
MessageBox.Show("OKボタンを押下していません");
|
74
|
-
|
75
38
|
//e.Cancel = true; // ページ移動をキャンセルするなら
|
76
|
-
|
77
39
|
}
|
78
|
-
|
79
40
|
}
|
80
41
|
|
81
|
-
|
82
|
-
|
83
42
|
private void Button_Click(object sender, EventArgs e)
|
84
|
-
|
85
43
|
{
|
86
|
-
|
87
44
|
if(sender is Button button)
|
88
|
-
|
89
45
|
{
|
90
|
-
|
91
46
|
var textBox = button.Parent.Controls["textBox"] as TextBox;
|
92
|
-
|
93
47
|
button.Parent.Tag = "OK"; // OK押したフラグ(Tagを使ったのには深い意味はない
|
94
|
-
|
95
48
|
}
|
96
|
-
|
97
49
|
}
|
98
|
-
|
99
50
|
}
|
100
|
-
|
101
51
|
}
|
102
|
-
|
103
52
|
```
|