Saturday, January 25, 2014

Fix AutoScale In Windows Forms


Some pieces of your Windows.Forms application may scale differently than other pieces.  Here are some simple tricks to force Windows.Forms to scale the way you want them to.

1.  Put your form elements inside a TableLogoutPanel.  Controls inside this panel will inherit better scaling than controls on their own.

2.  Use the same AutoScaleMode on all parts of your application.

3.  When AutoScale does not work the way you want it to, create your own scaler.
  • Set all your Windows.Forms to System.Windows.Forms.AutoScaleMode.None
  • Use the following to scale your Forms:
    Private Sub LoadedInitally(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.LoadedInitally
        If mobj_WindowsForm IsNot Nothing Then

            Using g As System.Drawing.Graphics = mobj_WindowsForm.CreateGraphics
                Dim sngScaleFactor As Single = 1
                If g.DpiX > 96 Then
                    sngScaleFactor = g.DpiX / 96
                End If
                If mobj_WindowsForm.AutoScaleDimensions = mobj_WindowsForm.CurrentAutoScaleDimensions Then
                End If
            End Using

        End If
    End Sub

Tuesday, January 14, 2014

Get All Methods in a Class (VB)

Public Shared Function GetMethodInfoList(ByRef objClass As Type) As List(Of System.Reflection.MethodInfo)
'get the methods of the object.
Dim objList As New List(Of System.Reflection.MethodInfo)

Dim objClassProperties() As System.Reflection.MethodInfo 'array of methodinfo.
objClassProperties = objClass.GetMethods()

Dim objMethodItem As System.Reflection.MethodInfo

For Each mi_MethodItem In objClassProperties

Return objList
End Function

Private Shared Function GetMethodParameters(ByRef objMethodInfo As System.Reflection.MethodInfo) As List(Of MyModels.NameValue)
Dim objList As New List(Of MyModels.NameValue)

Dim objParams() As System.Reflection.ParameterInfo
objParams = objMethodInfo.GetParameters()

For Each ParamItem In objParams
Dim objNameValue As New MyModels.NameValue
objNameValue.Name = ParamItem.Name
objNameValue.Value = ParamItem.ParameterType.ToString

Return objList
End Function