Ajuster le form en fonction de la resolution de l'écran

Résolu
dindinfb Messages postés 48 Date d'inscription mardi 24 mars 2009 Statut Membre Dernière intervention 3 janvier 2015 - 29 sept. 2014 à 08:14
dindinfb Messages postés 48 Date d'inscription mardi 24 mars 2009 Statut Membre Dernière intervention 3 janvier 2015 - 12 oct. 2014 à 09:39
Bonjour,

j'ai voulu afficher mon form1 en plein écran en fonction de la résolution de l'écran ainsi que ses controles (label ; bouton ....), j'ai testé plusieurs codes , la plupart ne fonctionnent pas sauf celui là qui affiche le form en plein écran mais ne tient pas compte des controles . j'aurais besoin de votre aide svp :


Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
' Adapte le formulaire à l'espace de travail de l'écran. L'espace de travail est
' la zone d'affichage du bureau, à l'exception des barres des tâches,
' des fenêtres et barres d'outils ancrées.
Me.Size = New System.Drawing.Size(Screen.PrimaryScreen.WorkingArea.Width, _
Screen.PrimaryScreen.WorkingArea.Height)
'*** Location du formulaire.
Me.Location = New System.Drawing.Point(0, 0)


End Sub
merci d'avance
--

3 réponses

cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 137
29 sept. 2014 à 08:58
0
dindinfb Messages postés 48 Date d'inscription mardi 24 mars 2009 Statut Membre Dernière intervention 3 janvier 2015
3 oct. 2014 à 21:46
Merci pour ta proposition, par contre j ai trouvé un autre code ue je posterai prochainement. Ce code s applique au form ainsi que ses controle. Il fonctionne avec merveille.
--
0
dindinfb Messages postés 48 Date d'inscription mardi 24 mars 2009 Statut Membre Dernière intervention 3 janvier 2015
12 oct. 2014 à 09:39
Bonjour
comme promis voici les démarches à faire pour que ce code fonctionne.
Tout d'abord il faut rajouter un class qu'on le nomme : ResizeControls
Namespace FormTools

Public Class ResizeControls

Dim RatioTable As New Hashtable

Private WindowHeight As Single
Private WindowWidth As Single
Private HeightRatio As Single
Private WidthRatio As Single

Private _Container As New Control

Public Property Container() As Control
Get
Return _Container
End Get
Set(ByVal Ctrl As Control)
_Container = Ctrl
FullRatioTable()
End Set

End Property

Private Structure SizeRatio
Dim TopRatio As Single
Dim LeftRatio As Single
Dim HeightRatio As Single
Dim WidthRatio As Single
End Structure

Private Sub FullRatioTable()
WindowHeight = _Container.Height
WindowWidth = _Container.Width
RatioTable = New Hashtable
AddChildrenToTable(_Container)
End Sub

Private Sub AddChildrenToTable(ByRef ChildContainer As Control)
Dim R As New SizeRatio
For Each C As Control In ChildContainer.Controls
With C
R.TopRatio = CSng(.Top / WindowHeight)
R.LeftRatio = CSng(.Left / WindowWidth)
R.HeightRatio = CSng(.Height / WindowHeight)
R.WidthRatio = CSng(.Width / WindowWidth)
RatioTable(.Name) = R
If .HasChildren Then
AddChildrenToTable(C)
End If
End With
Next
End Sub

Public Sub ResizeControls()

HeightRatio = CSng(_Container.Height / WindowHeight)
WidthRatio = CSng(_Container.Width / WindowWidth)

WindowHeight = _Container.Height
WindowWidth = _Container.Width

ResizeChildren(_Container)

End Sub

Private Sub ResizeChildren(ByRef ChildContainer As Control)
Dim R As New SizeRatio
For Each C As Control In ChildContainer.Controls
With C
R = CType(RatioTable(.Name), FormTools.ResizeControls.SizeRatio)
.Top = CInt(WindowHeight * R.TopRatio)
.Left = CInt(WindowWidth * R.LeftRatio)
.Height = CInt(WindowHeight * R.HeightRatio)
.Width = CInt(WindowWidth * R.WidthRatio)
If .HasChildren Then
ResizeChildren(C)
End If

Select Case True
Case TypeOf C Is ListBox
Dim L As New ListBox
L = CType(C, ListBox)
L.IntegralHeight = False

Case TypeOf C Is ListView
ResizeColumnsL(C, WidthRatio)

Case TypeOf C Is DataGridView
ResizeColumnsD(C, WidthRatio)

Case TypeOf C Is DataGrid
ResizeColumnsDg(C, WidthRatio)
End Select


ResizeControlFont(C, WidthRatio, HeightRatio)
End With
Next
End Sub

Private Sub ResizeControlFont(ByRef Ctrl As Control, ByVal RatioW As Single, ByVal RatioH As Single)

Dim FSize As Single = Ctrl.Font.Size
Dim FStyle As FontStyle = Ctrl.Font.Style
Dim FNome As String = Ctrl.Font.Name
Dim NewSize As Single = FSize

If TypeOf Ctrl Is DataGridView Then
Dim D As DataGridView

D = CType(Ctrl, DataGridView)
D.DefaultCellStyle.Font = New Font(D.Font.FontFamily, CSng(FSize * Math.Sqrt(RatioW * RatioH)), FontStyle.Regular)

End If

NewSize = CSng(FSize * Math.Sqrt(RatioW * RatioH))
Dim NFont As New Font(FNome, CSng(NewSize), FStyle)
Ctrl.Font = NFont

End Sub

Private Sub ResizeColumnsL(ByRef Ctrl As Control, ByVal RatioW As Single)

Dim C As ColumnHeader
For Each C In CType(Ctrl, ListView).Columns
C.Width = CInt(C.Width * RatioW)
Next

End Sub

Private Sub ResizeColumnsD(ByRef Ctrl As Control, ByVal RatioW As Single)

Dim C As DataGridViewColumn
For Each C In CType(Ctrl, DataGridView).Columns
C.Width = CInt(C.Width * RatioW)
Next

End Sub

Private Sub ResizeColumnsDg(ByRef Ctrl As Control, ByVal RatioW As Single)

Dim C As DataGridColumnStyle
For Each C In CType(Ctrl, DataGrid).TableStyles(0).GridColumnStyles
C.Width = CInt(C.Width * RatioW)
Next

End Sub

End Class

End Namespace



ensuite rajouter le code suivant (on nommera le form : FormMain.




Public Class FormMain

Dim R As New FormTools.ResizeControls()

Private Sub FormMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
R.Container = Me
End Sub

Private Sub FormMain_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
R.ResizeControls()
End Sub

End Class




Ce n'est pas moi qu'a fait le code , je suis un simple débutant en vb net . je l'ai juste récuperé de ce site : www.vb4arab.com (site didié à visual basic . ceux qui maitrise la langue arabe , peuvent trouver des perles dedans, désolé pour les autres ).
je le rajoute afin que celui qu'on besoin l'utilise , comme je l'ai utilisé .
0
Rejoignez-nous