تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
SoftWare Screen Resolution
#5
الجزء الثالث و الأخير

الكود التالي يوضح شكل الكلاس الذي من الممكن استخدامه لضبط ابعاد الفورم لتتناسب مع شاشة الكمبيوتر
الكلاس يمكن اعتباره أساس معقول لبعض المبرمجين لكي يطوروا فيه بشكل أفضل

PHP كود :
Public Structure WindowResolution

    Private _scale 
As Double
    Private _hwnd 
As IntPtr
    Private 
Const LogicDpiX As Integer 88
    Private 
Const LogicDpiY As Integer 96

    
' هنا يتم استخدام مقياس رسم يساوي 1
    Public Sub New(hwnd As IntPtr)
        Me.New(hwnd, 1)
    End Sub

    ' 
هنا يمكن تحديد مقياس رسم أكبر من أو أقل من 1
    Public Sub 
New(hwnd As IntPtrscale As Double)
 
       _hwnd hwnd
        _scale 
scale
    End Sub

    Public ReadOnly Property Controls 
As IEnumerable(Of Control)
 
       Get
            Dim _controls 
As IEnumerable(Of Control) = Nothing
            If _hwnd 
<> IntPtr.Zero Then
                Dim criteria 
As Func(Of ControlBoolean) = Function(cc IsNot Nothing AndAlso Not c.IsDisposed AndAlso c.IsHandleCreated AndAlso c.Visible
                Dim ctrl 
As Form TryCast(Control.FromHandle(_hwnd), Form)
 
               _controls = If(Not criteria(ctrl), New Control() {}, GetControls(ctrl.Controlsctrlcriteria))

 
           End If
 
           Return _controls
        End Get
    End Property

    Public ReadOnly Property Window 
As Form
        Get
            If _hwnd 
<> IntPtr.Zero Then
                Return FindWindow
(_hwnd)
 
           End If
 
           Return Nothing
        End Get
    End Property

    Public ReadOnly Property Scale 
As Double
        Get
            Return CalculateScale
(_scale)
 
       End Get
    End Property

    Public ReadOnly Property Size 
As Size
        Get
            Dim currentFormSize 
As Size Window.Size
            Dim bestFitSize 
As Size = New Size(currentFormSize.Width ScalecurrentFormSize.Height Scale)
 
           Return bestFitSize
        End Get
    End Property

    Public ReadOnly Property Font 
As Font
        Get
            Dim currentFormFont 
As Font Window.Font
            Dim bestFitFont 
As Font = New Font(currentFormFont.FontFamilycurrentFormFont.Size Scale)
 
           Return bestFitFont
        End Get
    End Property

    Private 
Function FindWindow(hwnd As IntPtr) As System.Windows.Forms.Form
        Return 
(Function()
 
                   Return TryCast(System.Windows.Forms.Control.FromHandle(hwnd), System.Windows.Forms.Form)
 
               End Function)()
 
   End Function

 
   Private Sub FindControls(parent As Controlcontrols As HashSet(Of Control), criteria As Func(Of ControlBoolean))
 
       If parent Is Nothing Then
            Return
        End 
If
 
       For Each ctrl As Control In parent.Controls
            If criteria
(ctrlThen
                controls
.Add(ctrl)
 
           End If

 
           If ctrl.HasChildren Then
                FindControls
(ctrlcontrolscriteria)
 
           End If
 
       Next
    End Sub

    Private 
Function GetControls(list As ICollectionparent As Controlcriteria As Func(Of ControlBoolean)) As HashSet(Of Control)
 
       If list Is Nothing OrElse parent Is Nothing Then
            Return Nothing
        End 
If
 
       Dim controls As HashSet(Of Control) = New HashSet(Of Control)()
 
       For Each ctrl As Control In list
 
           controls.Add(ctrl)
 
           FindControls(parentcontrolscriteria)
 
       Next
        Return controls
    End 
Function

 
   Private Function DetectResolution() As SizeF
        Return DetectResolution
(CType(NothingControl))
 
   End Function

 
   Private Function DetectResolution(control As Control) As SizeF
        Dim currentDpi 
As SizeF SizeF.Empty
 
       Dim dpiX As Single CSng(LogicDpiX)
 
       Dim dpiY As Single CSng(LogicDpiY)
 
       If control Is Nothing Then
            Using g 
As Graphics Graphics.FromHwnd(IntPtr.Zero)
 
               currentDpi = New SizeF(Math.Max(g.DpiXdpiX), Math.Max(g.DpiYdpiY))
 
               Return currentDpi
            End Using
        End 
If
 
       Using g As Graphics control.CreateGraphics()
 
           currentDpi = New SizeF(Math.Max(g.DpiXdpiX), Math.Max(g.DpiYdpiY))
 
           Return currentDpi
        End Using

        Return currentDpi
    End 
Function

 
   Private Function CalculateScale(value As Double) As Double
        Return 
(value DetectResolution().Width) / 100
    End 
Function

End Structure 

الكود التالي يوضح بعضا من الأفكار البسيطة لكيفية استخدام الكلاس

PHP كود :
       Dim res As New WindowResolution(Me.Handle1.4)
 
       Me.Size res.Size
        Me
.Font res.Font 

أتمني ان تكون الفكرة قد اتضحت للقارئ
الرد }}}


الردود في هذا الموضوع
SoftWare Screen Resolution - بواسطة silverlight - 13-04-17, 08:32 PM
RE: SoftWare Screen Resolution - بواسطة sendbad100 - 13-04-17, 09:22 PM
RE: SoftWare Screen Resolution - بواسطة silverlight - 14-04-17, 03:34 AM
RE: SoftWare Screen Resolution - بواسطة silverlight - 14-04-17, 09:01 PM
RE: SoftWare Screen Resolution - بواسطة silverlight - 15-04-17, 12:18 AM
RE: SoftWare Screen Resolution - بواسطة HASAN6.0 - 20-06-18, 10:14 PM

المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  Detect Display Screen DPI silverlight 2 3,253 11-06-16, 12:07 PM
آخر رد: Sajad
  Introduction To Screen Capture silverlight 2 3,312 09-10-15, 05:22 PM
آخر رد: silverlight
  معلومة ::: How to resize Windows form to fit Windows screen ::: RaggiTech 0 2,281 06-10-12, 09:53 PM
آخر رد: RaggiTech
  درس- كيفية عمل شاشة البدء splash Screen RaggiTech 0 4,770 05-10-12, 10:36 AM
آخر رد: RaggiTech
  مثال Screen Server RaggiTech 0 2,356 05-10-12, 01:13 AM
آخر رد: RaggiTech
  إعمل Splash Screen في دقيقة! RaggiTech 0 2,397 02-10-12, 01:01 AM
آخر رد: RaggiTech
  MultiPoint Software Development RaggiTech 1 2,176 01-10-12, 06:11 PM
آخر رد: RaggiTech

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


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