The button,Button.image,Button.Size?

Here is my code and the result. I gave the button an image attribute and a path. The code does not show an error, but the button does not show an image
#prvb.Imager = ed.Bitmap(image_path)

import scriptcontext as sc
import rhinoscriptsyntax as rs
import Rhino
from Rhino.UI import RhinoEtoApp, EtoExtensions
import Eto.Forms as ef
import Eto.Drawing as ed
image_path = r"J:\assets\SLOGO\JCAD\curve.png"
#RhinoEtoApp.MainWindowForDocument(sc.doc)
#SampleTransparentEtoForm(Eto.Forms.Form):
parent = RhinoEtoApp.MainWindowForDocument(sc.doc)
 
table_layout = ef.TableLayout()
table_layout.Padding = ed.Padding(8)
table_layout.Spacing = ed.Size(4, 4)

ceshi_label = ef.Label()
ceshi_label.Text = "测试:"

sil_0 = ef.Slider()
sil_0.Text = ""
sil_0.MaxValue = 10
sil_0.MinValue = 0
sil_0.Value = 3

m_numeric_updown = ef.NumericUpDown()
m_numeric_updown.DecimalPlaces = 2
m_numeric_updown.Increment = 1
m_numeric_updown.MaxValue = 10.0
m_numeric_updown.MinValue = 0.0
m_numeric_updown.Value = 3.0

prvb = ef.Button()
prvb.Imager = ed.Bitmap(image_path)

#J:\assets\SLOGO\JCAD\curve.png
#prvb.Text = "测试"

m_numeric_updown.ValueBinding.Bind(sil_0, "Value", ef.DualBindingMode.TwoWay)

row_0 = ef.TableRow()
row_0.Cells.Add(ef.TableCell(sil_0))
row_0.Cells.Add(ef.TableCell(m_numeric_updown))

row_1 = ef.TableRow()
row_1.Cells.Add(ef.TableCell(prvb))
#row_1.Cells.Add(ef.TableCell(ceshi_label))
#row_N = ef.TableRow()
#row_N.Cells.Add(ef.TableCell(controls))

table_layout.Rows.Add(row_0) 
table_layout.Rows.Add(row_1)

#table_layout.Rows.Add(row_N) 

def on_print(s, e):
    #object_id = rs.GetObject("测试")
    se = sil_0.Value
    #ceshi_label.Text = rs.ObjectName(object_id, name=None)
    print(se)
prvb.Click += on_print

dialog = ef.Dialog()
dialog.Content = table_layout
#dialog.Width = 200
#dialog.Height =300
dialog.Resizable = True
dialog.Title = "测试"

EtoExtensions.ShowSemiModal(dialog, sc.doc, parent) 

Okay, so I’ll use public Image Image {get; set; } This method works

This is my current code and running results, I ran into a small issue, the width of the button inside the layer can not be limited. I used prvb.Height = prvb_size = 40
prvb.Width = prvb_size
But I only reduced the size of the image, the size of the actual control is out of my control

import scriptcontext as sc
import rhinoscriptsyntax as rs
import Rhino
from Rhino.UI import RhinoEtoApp, EtoExtensions
import Eto.Forms as ef
import Eto.Drawing as ed
image_path = r"J:\assets\SLOGO\JCAD\curve.png"
#RhinoEtoApp.MainWindowForDocument(sc.doc)
#SampleTransparentEtoForm(Eto.Forms.Form):
parent = RhinoEtoApp.MainWindowForDocument(sc.doc)
 
table_layout = ef.TableLayout()
table_layout.Padding = ed.Padding(8)
table_layout.Spacing = ed.Size(4, 4)

ceshi_label = ef.Label()
ceshi_label.Text = "测试:"

sil_0 = ef.Slider()
sil_0.Text = ""
sil_0.MaxValue = 10
sil_0.MinValue = 0
sil_0.Value = 3

m_numeric_updown = ef.NumericUpDown()
m_numeric_updown.DecimalPlaces = 2
m_numeric_updown.Increment = 1
m_numeric_updown.MaxValue = 10.0
m_numeric_updown.MinValue = 0.0
m_numeric_updown.Value = 3.0

prvb = ef.Button()
prvb.Image = ed.Bitmap(image_path)
prvb.Height = prvb_size = 40
prvb.Width = prvb_size

#J:\assets\SLOGO\JCAD\curve.png
#prvb.Text = "测试"

m_numeric_updown.ValueBinding.Bind(sil_0, "Value", ef.DualBindingMode.TwoWay)

row_0 = ef.TableRow()
row_0.Cells.Add(ef.TableCell(sil_0))
row_0.Cells.Add(ef.TableCell(m_numeric_updown))

row_1 = ef.TableRow()
row_1.Cells.Add(ef.TableCell(prvb))

#row_1.Cells.Add(ef.TableCell(ceshi_label))
#row_N = ef.TableRow()
#row_N.Cells.Add(ef.TableCell(controls))

table_layout.Rows.Add(row_0) 
table_layout.Rows.Add(row_1)

#table_layout.Rows.Add(row_N) 

def on_print(s, e):
    #object_id = rs.GetObject("测试")
    se = sil_0.Value
    #ceshi_label.Text = rs.ObjectName(object_id, name=None)
    print(se)
prvb.Click += on_print

dialog = ef.Dialog()
dialog.Content = table_layout
#dialog.Width = 200
#dialog.Height =300
dialog.Resizable = True
dialog.Title = "测试"

EtoExtensions.ShowSemiModal(dialog, sc.doc, parent) 

Hi @tom33,

This is because you are using a Table Layout so the button fills the cell size.

You could instead use DynamicLayout and put A and B in a row and then C and D in the next row.

Or keep your TableLayout but in C cell add a PixelLayout() and then add the C button control to the PixelLayout which will let you have more nuanced control over the button size and position.

Probably another/better way with TableLayouts but I haven’t used TableLayouts much so hopefully another user who has can chime in on that…

Hope that helps for now!

1 Like

Thank you very much, Sir. It is useful to me. Thank you for your inspiration to me

1 Like