CREATING Graphics.DrawArc INTO Events timer1_Tick AT Form

HI ALL
HI @c.poupin

Referring to the code you wrote in

AND

I AM ADDING TIMRE

self.timer1 =  System.Windows.Forms.Timer()

I tried to draw an arc ( Graphics .DrawArc) within the event timer1_Tick
I didn’t succeed
Can you take a look?

Thanks in advance

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *


clr.AddReference('System.Drawing')
clr.AddReference('System.Windows.Forms')
import System.Drawing
import System.Windows.Forms

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

from System.Drawing import Point, Image, Bitmap, Size , Graphics
from System.Windows.Forms import Application, Button, Form, Label, TextBox , DataGridView , DataGridViewCellCollection , ListView , ListBox , MessageBox

from System.Drawing.Drawing2D import LinearGradientBrush  
#from System.Drawing.Graphics import Graphics


class MainForm(Form):
	def __init__(self):
		self.InitializeComponent()
		self.output = []
	
	def InitializeComponent(self):
		self._button1 = System.Windows.Forms.Button()
		self._textBox1 = System.Windows.Forms.TextBox()
		self._label1 = System.Windows.Forms.Label()
		
		self.timer1 =  System.Windows.Forms.Timer()
		
		self.SuspendLayout()
		# 
		# button1
		# 
		self._button1.Location = System.Drawing.Point(98, 148)
		self._button1.Name = "button1"
		self._button1.Size = System.Drawing.Size(94, 37)
		self._button1.TabIndex = 0
		self._button1.Text = "My Button"
		self._button1.UseVisualStyleBackColor = True
		self._button1.Click += self.Button1Click
		#
		#################################################################################
		self.timer1.Interval = 15
		self.timer1.Enabled = True
		self.timer1.Start()
		
		
		self.timer1.Tick += self.timer1_Tick





		# textBox1
		# 
		self._textBox1.Location = System.Drawing.Point(61, 102)
		self._textBox1.Name = "textBox1"
		self._textBox1.Size = System.Drawing.Size(167, 20)
		self._textBox1.TabIndex = 1
		# 
		# label1
		# 
		self._label1.Location = System.Drawing.Point(61, 73)
		self._label1.Name = "label1"
		self._label1.Size = System.Drawing.Size(167, 23)
		self._label1.TabIndex = 2
		self._label1.Text = "Enter a text"
		# 
		# Form1
		# 
		self.ClientSize = System.Drawing.Size(284, 261)
		self.Controls.Add(self._label1)
		self.Controls.Add(self._textBox1)
		self.Controls.Add(self._button1)
		self.Name = "Form1"
		self.Text = "MainForm"
		self.ResumeLayout(False)
		self.PerformLayout()


	def Button1Click(self, sender, e):
		try:
			newMDIChild = ChildForm(self)
			newMDIChild.StartPosition = FormStartPosition.CenterParent
			newMDIChild.ShowDialog(self)
		except Exception as ex:
			print(ex)


	def timer1_Tick(self, sender, e):
	    #grq = 10
		g = e.Graphics
		pen = Pen(Color.Gray, 1)
		g.DrawArc(pen, 20, 40, 33 , 33, 0, 360)
		

		
		
class ChildForm(Form):
	def __init__(self, parent):
		self._parent = parent
		
		self.InitializeComponent()
	
	def InitializeComponent(self):
		self._label1 = System.Windows.Forms.Label()
		
		
		self.SuspendLayout()
		# 
		# label1
		# 
		self._label1.Location = System.Drawing.Point(47, 41)
		self._label1.Name = "label1"
		self._label1.Size = System.Drawing.Size(178, 37)
		self._label1.TabIndex = 0
		self._label1.Text = "the enter text is '{}'".format(self._parent._textBox1.Text)
		self._label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
		
		
		#self.components = System.ComponentModel.Container()
		# 
		# Form14
		# 
		self.ClientSize = System.Drawing.Size(284, 128)
		self.Controls.Add(self._label1)
		self.Name = "ChildForm"
		self.Text = "ChildForm"
		self.ResumeLayout(False)
		self.PerformLayout()
		
		
		
	    
		
		

form = MainForm()
Application.Run(form)
OUT = form.output

Q _ timer0.dyn (8.5 KB)

Hi,
here an example

test packman

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

clr.AddReference('System.Drawing')
clr.AddReference('System.Windows.Forms')
import System.Drawing
import System.Windows.Forms

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

from System.Drawing import Point, Image, Bitmap, Size , Graphics
from System.Windows.Forms import Application, Button, Form, Label, TextBox , DataGridView , DataGridViewCellCollection , ListView , ListBox , MessageBox

from System.Drawing.Drawing2D import LinearGradientBrush  
#from System.Drawing.Graphics import Graphics

class MainForm(Form):
	def __init__(self):
		self.InitializeComponent()
		self.output = []
		self._initX = -20
		self._X1, self._X2 = 315, 350
	
	def InitializeComponent(self):
		self._components = System.ComponentModel.Container()
		self._button1 = System.Windows.Forms.Button()
		self._textBox1 = System.Windows.Forms.TextBox()
		self._label1 = System.Windows.Forms.Label()
		self._timer1 =  System.Windows.Forms.Timer(self._components)
		
		self.SuspendLayout()
		# 
		# button1
		# 
		self._button1.Location = System.Drawing.Point(140, 148)
		self._button1.Name = "button1"
		self._button1.Size = System.Drawing.Size(94, 37)
		self._button1.TabIndex = 0
		self._button1.Text = "My Button"
		self._button1.UseVisualStyleBackColor = True
		self._button1.Click += self.Button1Click
		#
		# timer1
		# 
		self._timer1.Enabled = True
		self._timer1.Interval = 1000
		self._timer1.Tick += self.Timer1Tick
		# textBox1
		# 
		self._textBox1.Location = System.Drawing.Point(140, 102)
		self._textBox1.Name = "textBox1"
		self._textBox1.Size = System.Drawing.Size(167, 20)
		self._textBox1.TabIndex = 1
		# 
		# label1
		# 
		self._label1.Location = System.Drawing.Point(140, 73)
		self._label1.Name = "label1"
		self._label1.Size = System.Drawing.Size(167, 23)
		self._label1.TabIndex = 2
		self._label1.Text = "Enter a text"
		# 
		# Form1
		# 
		self.BackColor = System.Drawing.SystemColors.ActiveBorder
		self.ClientSize = System.Drawing.Size(400, 300)
		self.Controls.Add(self._label1)
		self.Controls.Add(self._textBox1)
		self.Controls.Add(self._button1)
		self.Name = "Form1"
		self.Text = "MainForm"
		self.ResumeLayout(False)
		self.PerformLayout()
		self.Paint += self.OnPaint


	def Button1Click(self, sender, e):
		try:
			newMDIChild = ChildForm(self)
			newMDIChild.StartPosition = FormStartPosition.CenterParent
			newMDIChild.ShowDialog(self)
		except Exception as ex:
			print(ex)


	def Timer1Tick(self, sender, e):
		self._X1, self._X2 = self._X2, self._X1
		self._initX += 20
		if self._initX > self.Width :
			self._initX = -20
		self.Refresh()

	def OnPaint(self, e):
		g = e.Graphics
		pen = Pen(Color.Black, 3)
		for i in range(9):
			scale = i * 0.15
			if self._initX < self.Width * scale :
				g.FillPie(Brushes.Blue , Rectangle(self.Width * scale, 210, 30, 30), 0, 360)
		g.FillPie(Brushes.Yellow , Rectangle(self._initX, 190, 90, 90), 0, self._X1)
		if self._X1 == 350:
			g.DrawArc(pen, self._initX + 60, 210, 10 , 10, 0, 360)
		else:
			g.DrawArc(pen, self._initX + 40, 200, 10 , 10, 0, 360)
		
		
class ChildForm(Form):
	def __init__(self, parent):
		self._parent = parent
		
		self.InitializeComponent()
	
	def InitializeComponent(self):
		self._label1 = System.Windows.Forms.Label()
		
		
		self.SuspendLayout()
		# 
		# label1
		# 
		self._label1.Location = System.Drawing.Point(47, 41)
		self._label1.Name = "label1"
		self._label1.Size = System.Drawing.Size(178, 37)
		self._label1.TabIndex = 0
		self._label1.Text = "the enter text is '{}'".format(self._parent._textBox1.Text)
		self._label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
		
		
		#self.components = System.ComponentModel.Container()
		# 
		# Form14
		# 
		self.BackColor = System.Drawing.SystemColors.ActiveBorder
		self.ClientSize = System.Drawing.Size(284, 128)
		self.Controls.Add(self._label1)
		self.Name = "ChildForm"
		self.Text = "ChildForm"
		self.ResumeLayout(False)
		self.PerformLayout()
		
form = MainForm()
Application.Run(form)
OUT = form.output
4 Likes

@c.poupin

I tried a lot in it and I have an example in C sharp
But I did not pass the test
You really are the king of Windows.Forms
thank you

1 Like