0

I have some custom user controls in my .net winforms program that do not display correctly when the user has selected larger text size. This setting: enter image description here

My controls look like this,

enter image description here

Instead of like this,

enter image description here

The bill to area and ship to area are both custom controls. I don't know if this is contributing to the problem but I do have code in each to help scale the phone/fax areas to stretch nicely, like this code from the bill to control,

    Private Sub panFaxPhone_Resize(sender As Object, e As System.EventArgs) Handles panFaxPhone.Resize
            panFax.Width = (panFaxPhone.Width / 2) - 1
            panPhone.Width = (panFaxPhone.Width / 2) - 1
            panFax.Left = panFaxPhone.Width - panFax.Width
    End Sub

How can I get my controls to size correctly while still respecting the users choice for larger text (I don't want to just set the AutoScaleMode to None) ?

Update: After playing with this for a long time it seems to be a problem with anchors in the child controls. See this below image, the inner black box is the control with its border turned on, the text boxes (like name) are anchored left and right and should stretch to fill the control, but don't.

enter image description here

1 Answer 1

1

It just plain seems like the default control scaling just isn't working with the anchors. I don't know why, and can't explain it. But I did find a work around. See below code I added to the control. If you can provide an explanation, I would appreciate it.

    Private ChildControlScale As Double = 0
    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        ChildControlScale = txtAddress.Width / Me.Width

    End Sub

    Protected Overrides Sub ScaleControl(factor As System.Drawing.SizeF, specified As System.Windows.Forms.BoundsSpecified)
        MyBase.ScaleControl(factor, specified)
        If ChildControlScale <> 0 Then
            For Each ctrl As Control In Me.Controls
                ctrl.Width = Me.Width * ChildControlScale
            Next
        End If
    End Sub

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.