ウィンドウが画面外に表示された場合に戻す
終了時の画面のサイズ、位置を保存している場合、保存後にデスクトップのサイズが
変化したりすると、ウィンドウが画面外に表示されてしまったりする場合がある。
それを検知して、画面内に引き戻すコード。
// ---- FormのLoadイベントなどに記述する ----
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
| | #spanend
#spanadd
#spanend
#spanadd
#spanend
#spanadd
Point backLocation=this.Location; #spanend
#spanadd
this.Location=option.MainWindowPosition;#spanend
#spanadd
this.ClientSize=option.MainWindowSize;#spanend
#spanadd
#spanend
Point backLocation=this.Location;
this.Location=option.MainWindowPosition;
this.ClientSize=option.MainWindowSize;
this.WindowState=FormWindowState.Normal;
if(System.Windows.Forms.Screen.GetWorkingArea(this).IntersectsWith(this.Bounds)==false){
this.Location=backLocation;
}
#spanadd
this.WindowState=FormWindowState.Normal;#spanend
#spanadd
#spanend
#spanadd
if(System.Windows.Forms.Screen.GetWorkingArea(this).IntersectsWith(this.Bounds)==false){
#spanend
this.Location=backLocation;
#spanadd
}
#spanend
this.Visible=true;
this.WindowState=FormWindowState.Normal;
option.MainWindowPosition=this.Location;
option.MainWindowSize=this.ClientSize;
#spanadd
#spanend
#spanadd
this.Visible=true;
#spanend
#spanadd
this.WindowState=FormWindowState.Normal;#spanend
#spanadd
option.MainWindowPosition=this.Location;
#spanend
#spanadd
option.MainWindowSize=this.ClientSize;
#spanend
#spanadd
|