J'ai trouvé ma solution.
Il faut créer 2 feuilles : Main et Form1
- Main est la feuille principal celle que l'on lance en premier. On ajoute dessus le titre(Text) et l'icône qui apparaîtront dans la barre des taches.
- Dans Form1 on supprime le titre(Text) et on met ControlBox à False. On ajoute un label(lTitreForm) pour afficher le titre en remplacement. On ajoute également trois picturebox qui remplaceront "minimiser", "maximiser" et "fermer"(pbMinForm, pbMaxForm et pbCloseForm).
Dans Main on ajoute le code ci-dessous.
Public Class Main
Public Shared ComResize As Boolean = False
Public Shared ComLoad As Boolean = False
Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Form1.LoadSetting_Form() ' Chargement des paramètres pour toutes les interfaces
Form1.Visible = True
ComLoad = True
End Sub
Private Sub Main_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
If ComResize Then Exit Sub
If Form1 Is Nothing Then
Me.Left = -Me.Width 'rend la form presente mais hors écran
Dim gp As New System.Drawing.Drawing2D.GraphicsPath
Dim rgn As Region
gp.AddEllipse(0, 0, 1, 1)
rgn = New Region(gp) ' réduit à un seul pixel la taille de la fenêtre
Me.Region = rgn
gp.Dispose()
Form1.Visible = False
Form1.Focus()
Form1.ShowInTaskbar = False
End If
Select Case WindowState
Case FormWindowState.Maximized
If Form1.Maximized = False Then
Form1.Maximized = True
If Form1.Minimized Then
Form1.Minimized = False
End If
Else
Form1.Minimized = False
End If
Case FormWindowState.Minimized
Form1.Minimized = True
Case Else
If Form1.Minimized Then
Form1.Minimized = False
ElseIf Form1.Maximized Then
Form1.Maximized = False
End If
End Select
End Sub
Private Sub Main_Activated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Activated
Form1.Focus()
End Sub
End Class
Dans Form1 on ajoute le code ci-dessous.
Public Class Form1
Private CursLocationOnlTitre As Point
Private CursLocationOnForm As Point
Private NrmTop As Integer
Private NrmLeft As Integer
Private NrmHeight As Integer
Private NrmWidth As Integer
Private IsMaximized As Boolean = False
Private IsMinimized As Boolean = False
Public Sub LoadSetting_Form()
Dim Vers As String
Vers = My.Application.Info.Version.ToString ' Version
Vers = Mid(Vers, 1, InStrRev(Vers, ".") - 1) ' Version sans le nombre de compilation
lTitreForm.Text = My.Application.Info.ProductName & " " & Vers ' titre
Main.Text = lTitreForm.Text
End Sub
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
Main.Close()
End Sub
Private Sub pbCloseForm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pbCloseForm.Click
Close()
End Sub
Private Sub pbMaxForm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pbMaxForm.Click
Maximized = Not Maximized
pbMaxForm_MouseLeave(Nothing, Nothing)
End Sub
Private Sub pbMinForm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pbMinForm.Click
Minimized = Not Minimized
End Sub
Private Sub SaveNormalSize()
NrmTop = Top
NrmLeft = Left
NrmHeight = Height
NrmWidth = Width
End Sub
Private Sub SetNormalSize()
FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
Top = NrmTop
Left = NrmLeft
Height = NrmHeight
Width = NrmWidth
pbMaxForm_MouseLeave(Nothing, Nothing)
End Sub
Private Sub SetMaximalSize()
SaveNormalSize()
FormBorderStyle = Windows.Forms.FormBorderStyle.FixedDialog
Top = My.Computer.Screen.WorkingArea.Top
Left = My.Computer.Screen.WorkingArea.Left
Height = My.Computer.Screen.WorkingArea.Height
Width = My.Computer.Screen.WorkingArea.Width
pbMaxForm_MouseLeave(Nothing, Nothing)
End Sub
Public Property Maximized() As Boolean
Get
Return IsMaximized
End Get
Set(ByVal value As Boolean)
IsMaximized = value
Main.ComResize = True
If value Then
Main.WindowState = FormWindowState.Maximized
SetMaximalSize()
Else
SetNormalSize()
If Minimized Then
Main.WindowState = FormWindowState.Minimized
Else
Main.WindowState = FormWindowState.Normal
End If
End If
Main.ComResize = False
End Set
End Property
Public Property Minimized() As Boolean
Get
Return IsMinimized
End Get
Set(ByVal value As Boolean)
IsMinimized = value
Main.ComResize = True
If value = True Then
Main.WindowState = FormWindowState.Minimized
ElseIf Maximized Then
Main.WindowState = FormWindowState.Maximized
Else
Main.WindowState = FormWindowState.Normal
End If
Main.ComResize = False
Visible = Not value
End Set
End Property
Private Sub lTitreForm_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lTitreForm.DoubleClick
pbMaxForm_Click(Nothing, Nothing)
End Sub
Private Sub lTitreForm_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lTitreForm.MouseDown
CursLocationOnlTitre = e.Location ' évite un décalage brutale du curseur durant le déplacement
End Sub
Private Sub lTitreForm_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lTitreForm.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then
Left += e.X - CursLocationOnlTitre.X ' déplace la fenêtre
Top += e.Y - CursLocationOnlTitre.Y
End If
End Sub
#End Region
End Class
S Nikator