السلام عليكم و رحمة الله و بركاته
مشكلة تواجه اغلب المبرمجين و خاصة المبتدئين منهم حيث ان حجم الشاشة او دقة الشاشة كما يسميها البعض تختلف من حاسوب الى اخر و هذا الاختلاف سيكون مشكلة حيث ستتداخل الازرار و الادوات مع بعضها البعض اذا صغر حجم الشاشة او ستظهر هوامش لا معنى لها اذا كبر الحجم
و الحل بسيط و هو عبارة عن مجموعة اكواد طويلة قليلا انسخها و اكتبها كما هي عندك و ستحل المشكلة باذن الله
اليكم الاكواد
PHP كود :
Private DefaultControlSizes As New Dictionary(Of Control, CtrlInfo)
Private FormDefaultClientSize As Size
Public Sub New()
InitializeComponent()
Me.WindowState = FormWindowState.Normal
Me.MinimumSize = Me.Size
FormDefaultClientSize = Me.ClientSize
Dim ctrl As Control = Me.GetNextControl(Me, True)
While ctrl IsNot Nothing
If TypeOf ctrl Is ListBox Then DirectCast(ctrl, ListBox).IntegralHeight = False
DefaultControlSizes.Add(ctrl, New CtrlInfo(ctrl.Bounds, ctrl.Font.Size))
ctrl = Me.GetNextControl(ctrl, True)
End While
End Sub
Private Sub ScaleControls()
If Me.WindowState <> FormWindowState.Minimized Then
For Each kvp As KeyValuePair(Of Control, CtrlInfo) In DefaultControlSizes
Dim ctrl As Control = kvp.Key
Dim Xscl As Double = Me.ClientSize.Width / FormDefaultClientSize.Width
Dim Yscl As Double = Me.ClientSize.Height / FormDefaultClientSize.Height
'comment out these 2 lines if you dont want the fonts to be scaled'
Dim fntscl As Single = CSng(kvp.Value.cFontSize * Yscl)
ctrl.Font = New Font(ctrl.Font.FontFamily, fntscl, ctrl.Font.Style, ctrl.Font.Unit)
ctrl.Width = CInt(kvp.Value.cBounds.Width * Xscl)
ctrl.Height = CInt(kvp.Value.cBounds.Height * Yscl)
ctrl.Left = CInt(kvp.Value.cBounds.X * Xscl)
ctrl.Top = CInt(kvp.Value.cBounds.Y * Yscl)
Next
End If
End Sub
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
ScaleControls()
End Sub
End Class
Public Class CtrlInfo
Public cBounds As Rectangle
Public cFontSize As Single
Public Sub New(ByVal Bnds As Rectangle, ByVal FntSize As Single)
cBounds = Bnds
cFontSize = FntSize
End Sub
