This is the first time I’ve used a class to encapsulate some custom methods. It’s a challenge for me. I failed immediately, I felt like I was going to start losing my hair, and the community was my last hope
my code:
import Eto.Forms as ef
import Eto.Drawing as ed
class Txet_draw(ef.Drawable):
def __init__(self, Txet):
self.Width = 100
self.Height = 100
self._Txet = Txet
self._font = ed.Font("Arial", 10)
self._color = ed.Colors.Black
self._darw_location = ed.PointF(0,0)
def txet(self,e):
e.Graphics.DrawText(self._font,self._color,self._darw_location,self._Txet)
form = ef.Form()
form.Width = 300
form.Height = 300
#---------
class_font = Txet_draw(Txet = "123")
a_class_font =class_font.txet()
#---------
Layout_0 = ef.DynamicLayout()
Layout_0.AddRow(a_class_font)
form.Content = Layout_0
form.Show()
Report an error:
Rhino.Runtime.Code.Execution.ExecuteException: Object reference not set to an instance of an object.
---> System.NullReferenceException: Object reference not set to an instance of an object.
at Eto.Forms.Control.set_Width(Int32 value) in D:\BuildAgent\work\dujour\src4\DotNetSDK\Eto\src\Eto\Forms\Controls\Control.cs:line 895
at __main__.Eto.Forms.Drawable__Txet_draw._BASEVIRTUAL__set_Width(Int32)
at InvokeStub_Drawable__Txet_draw._BASEVIRTUAL__set_Width(Object, Object, IntPtr*)
at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
--- End of inner exception stack trace ---
System.NullReferenceException: Object reference not set to an instance of an object.
at Eto.Forms.Control.set_Width(Int32 value) in D:\BuildAgent\work\dujour\src4\DotNetSDK\Eto\src\Eto\Forms\Controls\Control.cs:line 895
at __main__.Eto.Forms.Drawable__Txet_draw._BASEVIRTUAL__set_Width(Int32)
at InvokeStub_Drawable__Txet_draw._BASEVIRTUAL__set_Width(Object, Object, IntPtr*)
at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)