التنبيهات التالية ظهرت :
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 864 - File: showthread.php PHP 7.4.33 (Linux)
File Line Function
/showthread.php 864 errorHandler->error



تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[VB.NET] كلاس ResizeControls وطريقة جديد ومميزة لتكبير وتصغير ادوات الفورم تلقائيا
#1
Rainbow 
السلام عليكم

لا امتلك حقوق الكلاس انا فقط مجرد مستخدم للكلاس لانه فى نظرى افضل واسهل من باقى الطرق الموجود عالنت

مشروع بسيط كمثال للموضوع http://www.elmagek.net/up/do.php?id=362

اولا : طريقة الاستخدام

ضع هذه الاكواد فى اى مكان فى الفورم

كود :
Dim R As New ResizeControls()
   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

ثانيا : ضيف كلاس جديد وامسح كل الاكواد الى فيه وضيف فيه كود هذا الكلاس

الكلاس

كود :
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
الرد }}}


الردود في هذا الموضوع
كلاس ResizeControls وطريقة جديد ومميزة لتكبير وتصغير ادوات الفورم تلقائيا - بواسطة الماجيك مسعد - 19-02-17, 04:59 AM

المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  حساب مكان الفورم علي شاشة الكمبيوتر silverlight 2 3,167 18-06-23, 03:26 PM
آخر رد: kebboud
  Private Text Encryption -خدمة للمبرمجين في جديد عالم التشفير- RaggiTech 1 3,549 07-05-20, 05:48 AM
آخر رد: سعود
Lightbulb [سلسلة تعليمية] شرح ادوات vb.net - DevExpress mgalal8899 2 5,484 11-02-20, 10:58 AM
آخر رد: ابو روضة
Lightbulb [VB.NET] تايمر جديد اسرع بأضعاف من التايمر العادي ؟! 3booody 9 5,319 27-11-19, 11:33 PM
آخر رد: 3booody
  [VB.NET] كود يجعل الفورم فى المقدمة دائماً [ بناءاً لطلب احد الاخوة وحتى سيتفاد منه الجميع ] elgokr 5 2,912 16-06-19, 08:32 AM
آخر رد: sendbad100
  الفورم بخاصية none محمود صالح 1 2,052 30-12-17, 03:52 AM
آخر رد: طالب برمجة
  [سؤال] ارسال بريد الكتروني في وقت معين تلقائيا coder-22 0 2,077 23-11-17, 12:34 PM
آخر رد: coder-22
  رسم الفورم و طباعته silverlight 1 2,399 19-06-17, 05:44 PM
آخر رد: silverlight
  صمم الكلاس الخاص بك - كلاس للتعامل مع SQL SERVER ابو ليلى 11 8,731 03-09-16, 07:43 PM
آخر رد: tryold
  [اقتراح] ادوات vb4arb HASAN6.0 3 3,571 07-11-15, 06:44 PM
آخر رد: HASAN6.0

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


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