The following defines the definition and the creation of a WinForms.Panel
class
class Labels(WinForms.Panel):
def __init__(self):
self.BorderStyle = WinForms.BorderStyle.FixedSingle
self.rows = 7
self.hSpace = 30
self.Size = Size(300,100)
#self.Location = Point(10,10)
self.Dock = WinForms.DockStyle.Bottom # Left | Right | Fill
self.labels = []
# Create the label (after the numericupdown to avoid hiding)
for i0 in range(self.rows):
self.labels.append(WinForms.Label())
self.labels[i0].Parent = self
self.labels[i0].Size = Size(200,self.hSpace)
self.labels[i0].Location = Point((self.Width-self.labels[i0].Width)/2,self.hSpace*(i0+1))
self.labels[i0].Text = "Line" + str(i0)
newFont = Font(self.labels[i0].Font.FontFamily.Name,20.0)
self.labels[i0].Font = newFont
self.labels[i0].ForeColor = Color.Green
self.labels[i0].TextAlign = ContentAlignment.MiddleCenter
# Register event handler for Resize
self.Resize += self.ResizeHandler
def ResizeHandler(self, sender, args):
# Handles the Resize event
print 'Resize Left: ',self.Left
print 'Resize Top: ',self.Top
print 'Resize Width: ',self.Width
print 'Resize Height: ',self.Height
self.hSpace = max(200,self.Height) / (self.rows )
for i0 in range(self.rows):
self.labels[i0].Location = Point((self.Width-self.labels[i0].Width)/2,self.hSpace*(i0))
def SetLine(self, lineNo, text):
if 0 < lineNo < self.rows :
self.labels[lineNo-1].Text = text
def GetLine(self, lineNo):
if 0 < lineNo < self.rows :
text = str( self.labels[lineNo-1].Text )
return text
else:
return '-'
Example 1: Create Labels in another Panel
self.Labels = Labels()
self.Labels.Parent = self
self.Labels.Size = Size(200,200)
self.Labels.Location = Point(0,500)
|