tom33
(tom)
March 23, 2025, 3:05pm
1
I want to draw a chamfered rectangle, I define the drawing area, use the corresponding method, it doesn’t seem to work
import Eto.Forms as ef
import Eto.Drawing as ed
form = ef.Form()
drawable = ef.Drawable()
drawable.Width = 300
drawable.Height = 300
def draw(sender, e):
rect = ed.RectangleF(10, 80, 140, 80)
ed.GraphicsPath.GetRoundRect(rect,10) #Test
drawable.Paint += draw
stack_layout = ef.StackLayout()
stack_layout.Spacing = 8
stack_layout.Padding = ed.Padding(8)
bu = ef.Button()
bu.Text = "test"
stack_layout.Items.Add(ef.StackLayoutItem(drawable))
stack_layout.Items.Add(ef.StackLayoutItem(bu))
form.Content = stack_layout
form.Show()
Hi @tom33 ,
Is this what you are after?
The issue in your code is that GetRoundRect
only creates the path it doesn’t draw it on the screen, you need to a make a separate call to DrawPath
or FillPath
for it to actually show up.
#! python3
import Eto.Forms as ef
import Eto.Drawing as ed
bg_debug = ed.Color.FromArgb(0,0,150,50)
b_debug = ed.Color.FromArgb(0,0,150,255)
form = ef.Form()
drawable = ef.Drawable()
drawable.Padding = ed.Padding(5)
drawable.Width = 300
drawable.Height = 300
# Rectangle
rectPen = ed.Pen(b_debug, 6)
strokeWidth = 14
def draw(sender, e):
try:
rect = ed.RectangleF(drawable.Padding.Left, drawable.Padding.Top, 140, 80)
rounded_rect_path = ed.GraphicsPath.GetRoundRect(rect, strokeWidth) # Test
e.Graphics.FillPath(bg_debug, rounded_rect_path)
e.Graphics.DrawPath(rectPen, rounded_rect_path)
except Exception as ex:
print(f"draw exception: {ex}")
drawable.Paint += draw
stack_layout = ef.StackLayout()
stack_layout.BackgroundColor = bg_debug
stack_layout.Spacing = 8
stack_layout.Padding = ed.Padding(8)
bu = ef.Button()
bu.Text = "test"
stack_layout.Items.Add(ef.StackLayoutItem(drawable))
stack_layout.Items.Add(ef.StackLayoutItem(bu))
form.Content = stack_layout
form.Show()
1 Like
You are welcome, happy Etoing
tom33
(tom)
March 24, 2025, 2:17am
5
Sir, I have a question for you. def draw(sender, e)
, I have a question here. Is the “e” in the function argument “Eto.Drawing
”?
So “sender
” what is this? I don’t seem to understand this