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

خذ هذا الكود وضعه في كود النافذة المراد تغيير حجمها :
كود :
Public Class Form1

   Dim R As New ResizeControls()

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

       ResizeControls.SubResize(Me, 100, 100)

       Me.StartPosition = FormStartPosition.CenterScreen

       Me.CenterToScreen()

       Me.WindowState = FormWindowState.Maximized

       'DataGridView1.Rows.Add(6)

   End Sub

   Private Sub Form1_HandleCreated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.HandleCreated
       R.Container = Me
   End Sub

   Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize

       Me.StartPosition = FormStartPosition.CenterScreen

       R.ResizeControls()

   End Sub
End Class




و هذا الكود يكتب في كلاس جديد تحت كلاس النافذة أو في مودل جديد :


كود :
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

   Private Shared m_FormWidth As Long                          'Original form width.
   Private Shared m_FormHeight As Long

   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), 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

           End With


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

           ResizeControlFont(C, WidthRatio, HeightRatio)

       Next





   End Sub

   Public Shared Sub SubResize(ByVal F As Form, ByVal percentW As Single, ByVal percentH As Single)

       Dim FormHeight As Long
       Dim FormWidth As Long
       Dim HeightChange As Single, WidthChange As Single


       FormHeight = Int((Screen.PrimaryScreen.WorkingArea.Height) * (percentH / 100))
       FormWidth = Int((Screen.PrimaryScreen.WorkingArea.Width) * (percentW / 100))

       With F
           .Height = FormHeight
           .Width = FormWidth

           HeightChange = .ClientSize.Height / m_FormHeight
           WidthChange = .ClientSize.Width / m_FormWidth


       End With


   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

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

   End Sub

End Class
قال صلى الله عليه وسلم: 
«كلمتان خفيفتان على اللسان 
ثقيلتان في الميزان،حبيبتان إلى الرحمن: 
سبحان الله وبحمده، سبحان الله العظيم».
الرد }}}


الردود في هذا الموضوع
RE: مطلوب كود تكبير الفورم مع الحفاظ علي حجم ومكان الادوات عند التكبير والتصغير - بواسطة Taha Okla - 12-12-22, 07:02 PM

المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
Information [VB.NET] مطلوب سورس برنامج من سيربح المليون بدر إشتية 7 6,715 30-11-25, 07:22 AM
آخر رد: Mr_limo
  مشكلة في عرض الفورم بالحجم المحدد مصمم هاوي 1 244 29-09-25, 03:17 AM
آخر رد: مصمم هاوي
  [VB.NET] حفظ تنسيق الفورم ثم تطبيقة علي فورم اخر فيجوال بيسك abo ragab 7 1,192 09-07-25, 12:45 AM
آخر رد: abo ragab
  إغلاق الفورم مع حذف جميع البيانات الموجودة به صالح عبدالله 10 1,031 19-04-25, 08:54 PM
آخر رد: Kamil
  كيف يمكن تحريك الفورم بأستخدام زر heem1986 2 586 30-03-25, 01:58 AM
آخر رد: heem1986
  [سؤال] تغيير الفورم الرئيسي عند تشغيل البرنامج في Visual Studio مع .NET 8؟ silverlord 2 648 09-03-25, 03:52 AM
آخر رد: silverlord
  ماهو سبب اغلاق الفورم صالح عبدالله 2 511 26-02-25, 02:40 PM
آخر رد: صالح عبدالله
Lightbulb [مشروع] مطلوب برنامج نظام صيدليه بالفيجوال بيسك 2010 May-5 13 10,770 07-02-25, 07:55 PM
آخر رد: الورد2
  استفسار عن تنسيق الفورم في حالة تغيرالفورم من وضع العادي الي التكبير fireswored1 4 821 22-01-25, 09:04 PM
آخر رد: fireswored1
  تأخر فتح الفورم بالبنال لمدة طويلة F.H.M 1 345 13-11-24, 08:27 AM
آخر رد: F.H.M

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


يقوم بقرائة الموضوع: