ETO help with showing a bitmap and a button

Hi, when I add a button it only shows the button, what did I do wrong?

### Sketch render v01.py
### Copyright by Holo 2025


#! python 3

import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc
import System
import Eto

rs.Prompt("Installing numpy and opencv")

import numpy as np
import cv2

def ShowBitmap(bitmap):
    width = bitmap.Width
    height = bitmap.Height
    Ratio = width / height
    dialog = Eto.Forms.Dialog()
    dialog.Title = "Holo's SketchRender"
    dialog.Width = 1024
    dialog.Height = int(dialog.Width/Ratio)
    dialog.Padding = Eto.Drawing.Padding(5)
    dialog.Resizable = True

    EtoBitmap = Rhino.UI.EtoExtensions.ToEto(bitmap)

    image_view = Eto.Forms.ImageView()
    image_view.Image = EtoBitmap
    dialog.Content = image_view
    
    
    ### Add a button
    def copyToClipboard(sender, e):
        System.Windows.Forms.Clipboard.SetImage(bitmap)
        rs.Prompt("Image copied to clipboard")
    button = Eto.Forms.Button()
    button.Click += copyToClipboard
    button.Text = "Copy to clipboard"
    dialog.Content = button
    
    ### Show the content
    dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)

bitmap = sc.doc.Views.ActiveView.CaptureToBitmap()
ShowBitmap(bitmap)

Hi @Holo, you first add the image_view as content:

dialog.Content = image_view

but you later set the button as content, which replaces the image_view:

dialog.Content = button

There can only be one item set as content, so you could use a layout to put your controls in and make the layout the content:

layout = Eto.Forms.DynamicLayout()
layout.AddRow(image_view)
layout.AddRow(button)
layout.AddSpace()
dialog.Content = layout

_
c.

1 Like

I made some changes to your code and you need to use layers
Paste the code into your editor and you’ll get exactly what you want

import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc
import System
import Eto
import Eto.Forms as ef

rs.Prompt("Installing numpy and opencv")
def ShowBitmap(bitmap):
    width = bitmap.Width
    height = bitmap.Height
    Ratio = width / height
    dialog = Eto.Forms.Dialog()
    dialog.Title = "Holo's SketchRender"
    dialog.Width = 1024
    dialog.Height = int(dialog.Width/Ratio)
    dialog.Padding = Eto.Drawing.Padding(5)
    dialog.Resizable = True

    EtoBitmap = Rhino.UI.EtoExtensions.ToEto(bitmap)

    image_view = Eto.Forms.ImageView()
    image_view.Image = EtoBitmap
    dialog.Content = image_view
    
    
    ### Add a button
    def copyToClipboard(sender, e):
        System.Windows.Forms.Clipboard.SetImage(bitmap)
        rs.Prompt("Image copied to clipboard")
    button = Eto.Forms.Button()
    button.Click += copyToClipboard
    button.Text = "Copy to clipboard"

    button_2 = Eto.Forms.Button()
    button_2.Text = "this_bu_2"

    lou = ef.DynamicLayout()
    lou.AddRow(button,button_2)
    lou.AddRow(None)

    dialog.Content = lou
    
    ### Show the content
    dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)

bitmap = sc.doc.Views.ActiveView.CaptureToBitmap()
ShowBitmap(bitmap)

1 Like