تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
الحل الأمثل لتعديل حجم الفورم و الأدوات طبقا لحجم الشاشة
#1
السلا عليكم ورحمة الله و بركاته

مرحبا بكم اقدم لكم اليوم الحل الأمثل لتعديل حجم الفورم والأدوات عند تغيير حجم الشاشة

قم بأضافة Class جديد باسم FormResizer

وأنسخ هذا الكود


كود :
[align=left]Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Windows.Forms
Imports System.Drawing
Imports System.ComponentModel

Public Class FormResizer

    'Considerations:
    'Change the Form AutoSize Mode to None.
    Private f_HeightRatio As New Single()
    Private f_WidthRatio As New Single()

    Public Sub ResizeForm(ObjForm As Form, DesignerHeight As Integer, DesignerWidth As Integer)
        '#Region "Code for Resizing and Font Change According to Resolution"
        'Specify Here the Resolution Y component in which this form is designed
        'For Example if the Form is Designed at 800 * 600 Resolution then DesignerHeight=600
        Dim i_StandardHeight As Integer = DesignerHeight

        'Specify Here the Resolution X component in which this form is designed
        'For Example if the Form is Designed at 800 * 600 Resolution then DesignerWidth=800
        Dim i_StandardWidth As Integer = DesignerWidth
        Dim i_PresentHeight As Integer = Screen.PrimaryScreen.Bounds.Height

        'Present Resolution Height
        Dim i_PresentWidth As Integer = Screen.PrimaryScreen.Bounds.Width

        'Presnet Resolution Width
        f_HeightRatio = CSng(CSng(i_PresentHeight) / CSng(i_StandardHeight))
        f_WidthRatio = CSng(CSng(i_PresentWidth) / CSng(i_StandardWidth))
        ObjForm.AutoScaleMode = AutoScaleMode.None

        'Make the Autoscale Mode=None
        ObjForm.Scale(New SizeF(f_WidthRatio, f_HeightRatio))
        For Each c As Control In ObjForm.Controls
            If c.HasChildren Then
                ResizeControlStore(c)
            Else
                c.Font = New Font(c.Font.FontFamily, c.Font.Size * f_HeightRatio, c.Font.Style, c.Font.Unit, CByte(0))
            End If
        Next
        ObjForm.Font = New Font(ObjForm.Font.FontFamily, ObjForm.Font.Size * f_HeightRatio, ObjForm.Font.Style, ObjForm.Font.Unit, CByte(0))
    End Sub

    ''' <summary>
    ''' This Function is Used to Change the Font of Controls that are Nested in Other Controls.
    ''' </summary>
    ''' <param name="objCtl"></param>
    Private Sub ResizeControlStore(objCtl As Control)
        If objCtl.HasChildren Then
            For Each cChildren As Control In objCtl.Controls
                If cChildren.HasChildren Then
                    ResizeControlStore(cChildren)
                Else
                    cChildren.Font = New Font(cChildren.Font.FontFamily, cChildren.Font.Size * f_HeightRatio, cChildren.Font.Style, cChildren.Font.Unit, CByte(0))
                End If
            Next
            objCtl.Font = New Font(objCtl.Font.FontFamily, objCtl.Font.Size * f_HeightRatio, objCtl.Font.Style, objCtl.Font.Unit, CByte(0))
        Else
            objCtl.Font = New Font(objCtl.Font.FontFamily, objCtl.Font.Size * f_HeightRatio, objCtl.Font.Style, objCtl.Font.Unit, CByte(0))
        End If
    End Sub
End Class[/align]

فى حدث Form_Load

كود :
[align=left]        Dim Resizer As New FormResizer
        Resizer.ResizeForm(Me, 864, 1152)[/align]
الرد }}}}
تم الشكر بواسطة: Mostafa Saad
#2
Class رائع من شخص راثع
شكرًا جزيلاً على مشاركاتك الطيبة
الرد }}}}
تم الشكر بواسطة:


التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم