Public Class Form1 Inherits System.Windows.Forms.Form ' フルスクリーン・モードかどうかのフラグ Private _bScreenMode As Boolean ' フルスクリーン表示前のウィンドウの状態を保存する Private prevFormState As FormWindowState ' 通常表示時のフォームの境界線スタイルを保存する Private prevFormStyle As FormBorderStyle ' 通常表示時のウィンドウのサイズを保存する Private prevFormSize As Size #Region " Windows フォーム デザイナで生成されたコード " Public Sub New() MyBase.New() ' この呼び出しは Windows フォーム デザイナで必要です。 InitializeComponent() ' InitializeComponent() 呼び出しの後に初期化を追加します。 End Sub ' Form は、コンポーネント一覧に後処理を実行するために dispose をオーバーライドします。 Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub ' Windows フォーム デザイナで必要です。 Private components As System.ComponentModel.IContainer ' メモ : 以下のプロシージャは、Windows フォーム デザイナで必要です。 'Windows フォーム デザイナを使って変更してください。 ' コード エディタを使って変更しないでください。 Friend WithEvents mainMenu1 As System.Windows.Forms.MainMenu Friend WithEvents statusBar1 As System.Windows.Forms.StatusBar Friend WithEvents menuItem1 As System.Windows.Forms.MenuItem Friend WithEvents menuItem2 As System.Windows.Forms.MenuItem Friend WithEvents button1 As System.Windows.Forms.Button Private Sub InitializeComponent() Me.mainMenu1 = New System.Windows.Forms.MainMenu Me.menuItem1 = New System.Windows.Forms.MenuItem Me.menuItem2 = New System.Windows.Forms.MenuItem Me.statusBar1 = New System.Windows.Forms.StatusBar Me.button1 = New System.Windows.Forms.Button Me.SuspendLayout() ' 'mainMenu1 ' Me.mainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.menuItem1}) ' 'menuItem1 ' Me.menuItem1.Index = 0 Me.menuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.menuItem2}) Me.menuItem1.Text = "ファイル" ' 'menuItem2 ' Me.menuItem2.Index = 0 Me.menuItem2.Text = "終了" ' 'statusBar1 ' Me.statusBar1.Location = New System.Drawing.Point(0, 197) Me.statusBar1.Name = "statusBar1" Me.statusBar1.Size = New System.Drawing.Size(496, 22) Me.statusBar1.TabIndex = 0 Me.statusBar1.Text = "ready" ' 'button1 ' Me.button1.Font = New System.Drawing.Font("MS UI Gothic", 36.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(128, Byte)) Me.button1.Location = New System.Drawing.Point(16, 56) Me.button1.Name = "button1" Me.button1.Size = New System.Drawing.Size(464, 80) Me.button1.TabIndex = 1 Me.button1.Text = "通常表示する" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12) Me.ClientSize = New System.Drawing.Size(496, 219) Me.Controls.Add(Me.button1) Me.Controls.Add(Me.statusBar1) Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None Me.Menu = Me.mainMenu1 Me.Name = "Form1" Me.Text = "Form1" Me.WindowState = System.Windows.Forms.FormWindowState.Maximized Me.ResumeLayout(False) End Sub #End Region Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' フルスクリーン・モードで起動 _bScreenMode = True ' フルスクリーン表示前のウィンドウの状態を保存する prevFormState = FormWindowState.Normal ' 通常表示時のフォームの境界線スタイルを保存する prevFormStyle = FormBorderStyle.Sizable ' 通常表示時のウィンドウのサイズを保存する prevFormSize = New Size(496, 219) End Sub Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click If (_bScreenMode = False) Then ' <フルスクリーン表示への切り替え処理> ' ウィンドウの状態を保存する prevFormState = Me.WindowState ' 境界線スタイルを保存する prevFormStyle = Me.FormBorderStyle ' 0. 「最大化表示」→「フルスクリーン表示」では ' タスク・バーが消えないので、いったん「通常表示」を行う If Me.WindowState = FormWindowState.Maximized Then Me.WindowState = FormWindowState.Normal End If ' フォームのサイズを保存する prevFormSize = Me.ClientSize ' 1. フォームの境界線スタイルを「None」にする Me.FormBorderStyle = FormBorderStyle.None ' 2. フォームのウィンドウ状態を「最大化」する Me.WindowState = FormWindowState.Maximized ' ボタンの表示を変更する Me.button1.Text = "通常表示する" ' フルスクリーン・モードをONにする _bScreenMode = True Else ' <通常表示/最大化表示への切り替え処理> ' フォームのウィンドウのサイズを元に戻す Me.ClientSize = prevFormSize ' 0. 最大化に戻す場合にはいったん通常表示を行う ' (フルスクリーン表示の処理とのバランスと取るため) If prevFormState = FormWindowState.Maximized Then Me.WindowState = FormWindowState.Normal End If ' 1. フォームの境界線スタイルを元に戻す Me.FormBorderStyle = prevFormStyle ' 2. フォームのウィンドウ状態を元に戻す Me.WindowState = prevFormState ' ボタンの表示を変更する Me.button1.Text = "フルスクリーン表示する" ' フルスクリーン・モードをOFFにする _bScreenMode = False End If End Sub Private Sub menuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles menuItem2.Click Me.Close() End Sub End Class