Userform in Rhino 6 Opens Half the Size

Hi,

I have a user on Rhino 6 that is having problems with how a userform is displayed on their machine. I sent them a simple test userform to try and troubleshoot this and the userform opens up about half the size and all of the controls get crammed together. They also have a version of Rhino 5 and it opens fine on the same machine. I can open it on my machine in 5 or 6 with no problem. Anyone seen this before and any and all suggestions are appreciated.

I’ve posted the code below. This came from SharpDevelop with some modifications.

Eric

805f145a-7057-410e-9ac0-fba6910ac435 UF V 5

import System.Drawing
import System.Windows.Forms

from System.Drawing import *
from System.Windows.Forms import *

mbl = 30

class MainForm(Form):
def init(self):
self.InitializeComponent()

def InitializeComponent(self):
	self._numericUpDown1 = System.Windows.Forms.NumericUpDown()
	self._groupBox1 = System.Windows.Forms.GroupBox()
	self._label1 = System.Windows.Forms.Label()
	self._lblTitle = System.Windows.Forms.Label()
	self._checkBox1 = System.Windows.Forms.CheckBox()
	self._checkBox2 = System.Windows.Forms.CheckBox()
	self._numericUpDown2 = System.Windows.Forms.NumericUpDown()
	self._numericUpDown1.BeginInit()
	self._groupBox1.SuspendLayout()
	self._numericUpDown2.BeginInit()
	self.SuspendLayout()
	# 
	# numericUpDown1
	# 
	self._numericUpDown1.DecimalPlaces = 3
	self._numericUpDown1.Increment = System.Decimal(System.Array[System.Int32](
		[5,
		0,
		0,
		65536]))
	self._numericUpDown1.Location = System.Drawing.Point(132, 19)
	self._numericUpDown1.Name = "numericUpDown1"
	self._numericUpDown1.Size = System.Drawing.Size(120, 20)
	self._numericUpDown1.TabIndex = 0
	self._numericUpDown1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
	self._numericUpDown1.Value = System.Decimal(System.Array[System.Int32](
		[24,
		0,
		0,
		0]))
	self._numericUpDown1.ValueChanged += self.NumericUpDown1ValueChanged
	# 
	# numericUpDown2
	# 
	self._numericUpDown2.Location = System.Drawing.Point(133, 42)
	self._numericUpDown2.Name = "numericUpDown2"
	self._numericUpDown2.Size = System.Drawing.Size(139, 20)
	self._numericUpDown2.TabIndex = 4
	self._numericUpDown2.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
	self._numericUpDown2.Value = System.Decimal(System.Array[System.Int32](
		[24,
		0,
		0,
		0]))
	self._numericUpDown2.ValueChanged += self.NumericUpDown2ValueChanged
	# 
	# groupBox1
	# 
	self._groupBox1.Controls.Add(self._checkBox2)
	self._groupBox1.Controls.Add(self._label1)
	self._groupBox1.Controls.Add(self._numericUpDown1)
	self._groupBox1.Location = System.Drawing.Point(13, 97)
	self._groupBox1.Name = "groupBox1"
	self._groupBox1.Size = System.Drawing.Size(259, 96)
	self._groupBox1.TabIndex = 1
	self._groupBox1.TabStop = False
	self._groupBox1.Text = "groupBox1"
	# 
	# label1
	# 
	self._label1.Location = System.Drawing.Point(17, 20)
	self._label1.Name = "label1"
	self._label1.Size = System.Drawing.Size(109, 19)
	self._label1.TabIndex = 1
	self._label1.Text = "Update MB L"
	self._label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
	# 
	# lblTitle
	# 
	self._lblTitle.Location = System.Drawing.Point(13, 9)
	self._lblTitle.Name = "lblTitle"
	self._lblTitle.Size = System.Drawing.Size(126, 23)
	self._lblTitle.TabIndex = 2
	self._lblTitle.Text = "Test Form"
	self._lblTitle.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
	# 
	# checkBox1
	# 
	self._checkBox1.Checked = True
	self._checkBox1.CheckState = System.Windows.Forms.CheckState.Checked
	self._checkBox1.Location = System.Drawing.Point(133, 12)
	self._checkBox1.Name = "checkBox1"
	self._checkBox1.Size = System.Drawing.Size(139, 24)
	self._checkBox1.TabIndex = 3
	self._checkBox1.Text = "checkBox1"
	self._checkBox1.UseVisualStyleBackColor = True
	# 
	# checkBox2
	# 
	self._checkBox2.Checked = True
	self._checkBox2.CheckState = System.Windows.Forms.CheckState.Checked
	self._checkBox2.Location = System.Drawing.Point(132, 45)
	self._checkBox2.Name = "checkBox2"
	self._checkBox2.Size = System.Drawing.Size(120, 24)
	self._checkBox2.TabIndex = 4
	self._checkBox2.Text = "checkBox2"
	self._checkBox2.UseVisualStyleBackColor = True
	# 
	# MainForm
	# 
	self.ClientSize = System.Drawing.Size(284, 205)
	self.Controls.Add(self._numericUpDown2)
	self.Controls.Add(self._checkBox1)
	self.Controls.Add(self._lblTitle)
	self.Controls.Add(self._groupBox1)
	self.Name = "MainForm"
	self.Text = "Test"
	self._numericUpDown1.EndInit()
	self._groupBox1.ResumeLayout(False)
	self._numericUpDown2.EndInit()
	self.ResumeLayout(False)
	
	
#THIS ROUTINE WILL FIND A CONTROL AND UPDATE IT WITH MACRO DEFINED DATA
def UpdateUI(self,cName,cVal):
    for i in self.Controls:
        #Get Type
        fType = type(i)
        #Find Control on Main Form
        #Labels
        if i.Name == cName and fType == Label:
            i.Text = cVal
        #Checkboxes
        if i.Name == cName and fType == CheckBox:
            i.Checked = cVal
        # Numeric UpDown
        if i.Name == cName and fType == NumericUpDown:
            i.Value = cVal
            
        #Find Control in Group Box
        if fType == GroupBox:
            for j in i.Controls:
                #Get Type
                gType = type(j)
                # Numeric UpDown
                if j.Name == cName and gType == NumericUpDown:
                    j.Value = cVal	
                #Labels
                if j.Name == cName and gType == Label:
                    j.Text = cVal	
                #Checkboxes
                if j.Name == cName and gType == CheckBox:
                    j.Checked = cVal


def NumericUpDown1ValueChanged(self, sender, e):
	self._numericUpDown1 = sender.Value
	self.UpdateUI("numericUpDown1",mbl)
	self.UpdateUI("lblTitle","Changed1")
	self.UpdateUI("label1","Changed2")
	self.UpdateUI("checkBox1",False)
	self.UpdateUI("checkBox2",False)

def NumericUpDown2ValueChanged(self, sender, e):
	self._numericUpDown1 = sender.Value
	self.UpdateUI("numericUpDown2",mbl)

def DoSomething():
form = MainForm()
if form.ShowDialog() == System.Windows.Forms.DialogResult.OK:
print(form._numericUpDown1)
else:
print(“Canceled”)

if name==“main”:
DoSomething()

Hi @eric.bunn,

Can you confirm that this user’s Window display is configured for DPI scaling?

There is also this:

– Dale

I’m guessing no. We have 3 computers all the same Dell 5520 laptops. Works fine on one and not on the other two. How does one configure the dpi scaling? Does the link you provided discuss this?

Eric

Hi @eric.bunn,

The link I provided talks about this.

You can also have him run the TestDpiScale command.

– Dale

I sent the user an example that was posted for a simple user form written in Rhino ETO and it did not exhibit the scaling issue. Can you explain why that might be?

Eric

This code did not exhibit the scaling problem.

# Imports
import Rhino
import scriptcontext
import System
import Rhino.UI
import Eto.Drawing as drawing
import Eto.Forms as forms

# SampleEtoRoomNumber dialog class
class SampleEtoRoomNumberDialog(forms.Dialog[bool]):

    # Dialog box Class initializer
    def __init__(self):
        # Initialize dialog box
        self.Title = 'Sample Eto: Room Number'
        self.Padding = drawing.Padding(10)
        self.Resizable = False

        # Create controls for the dialog
        self.m_label = forms.Label(Text = 'Enter the Room Number:')
        self.m_textbox = forms.TextBox(Text = None)

        # Create the default button
        self.DefaultButton = forms.Button(Text = 'OK')
        self.DefaultButton.Click += self.OnOKButtonClick

        # Create the abort button
        self.AbortButton = forms.Button(Text = 'Cancel')
        self.AbortButton.Click += self.OnCloseButtonClick

        # Create a table layout and add all the controls
        layout = forms.DynamicLayout()
        layout.Spacing = drawing.Size(5, 5)
        layout.AddRow(self.m_label, self.m_textbox)
        layout.AddRow(None) # spacer
        layout.AddRow(self.DefaultButton, self.AbortButton)

        # Set the dialog content
        self.Content = layout

    # Start of the class functions

    # Get the value of the textbox
    def GetText(self):
        return self.m_textbox.Text

    # Close button click handler
    def OnCloseButtonClick(self, sender, e):
        self.m_textbox.Text = ""
        self.Close(False)

    # OK button click handler
    def OnOKButtonClick(self, sender, e):
        if self.m_textbox.Text == "":
            self.Close(False)
        else:
            self.Close(True)

    ## End of Dialog Class ##

# The script that will be using the dialog.
def RequestRoomNumber():
    dialog = SampleEtoRoomNumberDialog();
    rc = dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)
    if (rc):
        print dialog.GetText() #Print the Room Number from the dialog control

##########################################################################
# Check to see if this file is being executed as the "main" python
# script instead of being used as a module by some other python script
# This allows us to use the module which ever way we want.
if __name__ == "__main__":
    RequestRoomNumber()

Hi @eric.bunn,

Eto inherently supports high DPI scaling. Winforms, which is what you are using, has some issues with high DPI scaling.

– Dale

Thank you. I was using SharpDevelop for the convenience of the editor and also because I have some users still using Rhino 5. I’m trying to get them all to upgrade to a common platform. I’ll play around with ETO and perhaps
transition to that for future userforms. Thanks for the help.

Dale,

I believe I have resolved the issue by adding these two lines of code:

self.AutoScaleDimensions = System.Drawing.SizeF(6, 13)
self.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font

The resources you sent to me verified as well that this was a fix. I also found that it is possible inside of SharpDevelop to set this up in the Userform, which is how I generated the two lines of code.

Thanks again for the help.

Eric