def __init__(self): #the __init__ method inside a class is its constructor self.Text = "AU London" #text that appears in the GUI titlebar self.Icon = Icon.FromHandle(icon.GetHicon()) self.BackColor = Color.FromArgb(255, 255, 255) self.WindowState = FormWindowState.Normal self.CenterToScreen() self.BringToFront() self.TopMost = True screenSize = Screen.GetWorkingArea(self) self.Width = screenSize / 4 self.Height = screenSize / 4 uiWidth = self.DisplayRectangle.Width uiHeight = self.DisplayRectangle.Height spacing = 10 userMessage = Label() font = Font("Helvetica", 10) userMessage.Text = message userMessage.Font = font userMessage.Location = Point(spacing, spacing) userMessage.Size = Size(uiWidth - (spacing * 2), (uiHeight / 4)) self.Controls.Add(userMessage)
def __init__(self): #the __init__ method inside a class is its constructor self.Text = "AU London" #text that appears in the GUI titlebar self.Icon = Icon.FromHandle(icon.GetHicon()) #takes a bitmap image and converts to a file that can be used as a Icon for the titlebar self.BackColor = Color.FromArgb(255, 255, 255) self.WindowState = FormWindowState.Normal # set maximised minimised or normal size GUI self.CenterToScreen() # centres GUI to the middle of your screen self.BringToFront() #brings the GUI to the front of all opens windows. self.Topmost = True # true to display the GUI infront of any other active forms screenSize = Screen.GetWorkingArea(self) #get the size of the computers main screen, as the form will scale differently to different sized screens self.Width = screenSize.Width / 4 #set the size of the form based on the size of the users screen. this helps to ensure consistant look across different res screens. self.Height = screenSize.Height / 4 uiWidth = self.DisplayRectangle.Width #get the size of the form to use to scale form elements uiHeight = self.DisplayRectangle.Height #self.FormBorderStyle = FormBorderStyle.FixedDialog # fixed dialog stops the user from adjusting the form size. Recomended disabling this when testing to see if elements are in the wrong place. self.userOutput = userOutputDefaultStr #create a container to store the output from the form self.runNextOutput = False #set these default values #############-------------\-------------############# spacing = 10 #spacing size for GUI elements to form a consistent border # creates the text box for a info message userMessage = Label() #label displays texts font = Font("Helvetica ", 10) userMessage.Text = message userMessage.Font = font userMessage.Location = Point(spacing, spacing) #all location require a point object from system.Drawing to set the location. userMessage.Size = Size(uiWidth-(spacing*2),(uiHeight/4)) #size the control with the width of the GUI to ensure it scales with different screen self.Controls.Add(userMessage) #this adds control element to the GUI
def _initializeUserInterface(self): self.Size = Size(1600, 500) self.tlpMain.ColumnCount = len(self.columnNames) self.tlpMain.RowCount = 2 self.tlpMain.Size = self.ClientRectangle.Size #create list titles for name in self.columnNames: lbl = Label() lbl.Text = name lbl.Font = Font("Microsoft Sans Serif", 12, FontStyle.Bold) lbl.Height = 50 self.tlpMain.Controls.Add(lbl) #create lists for name in self.columnNames: lst = ListBox() lst.Name = name lst.Font = Font("Microsoft Sans Serif", 10) lst.Width = 135 if name.ToLower() == 'attribute': lst.Width = 300 if name.ToLower() == 'mode': lst.Width = 215 lst.Height = self.ClientRectangle.Height - (lbl.Height * 2) self.tlpMain.Controls.Add(lst) self._populateLists(lst)
def __init__(self): self.Title="Timer" self.timer1=Timer() self.timer1.Interval=1000 self.timer1.Tick+=self.timer1_tick label1=Label() label1.AutoSize=True label1.Location=Point(41,22) label1.Text="00:00:00" label1.Font=Font("MS UI Gothic",24.0,FontStyle.Regular) self.label1=label1 self.Controls.Add(self.label1) clientwidth=255 b1=Button() b1.Location=Point((clientwidth-b1.Width*2)/3,68) b1.Text="Click" b1.Click+=self.start_Click self.Controls.Add(b1) b2=Button() b2.Location=Point((clientwidth-b1.Width*2)*2/3+b1.Width,68) b2.Text="Stop" b2.Click+=self.stop_Click self.Controls.Add(b2) self.ClientSize=Size(clientwidth,103) self.Text="Stop Watch" self.StartPosition=FormStartPosition.CenterScreen
def add_heading_label(text, panel): # add heading label label = Label() label.Parent = panel label.Text = text label.AutoSize = True label.Font = HEADER_FONT label.Margin = Padding(0, 5, 0, 5)
def add_param_label(text, panel): # add param label label = Label() label.Parent = panel label.Text = text label.AutoSize = True label.Font = BODY_FONT label.Margin = Padding(0, 5, 0, 0) label.Width = panel.Width
def __init__(self): self.Text = "You know I'm No Good" font = Font("Serif", 10) lyrics = Label() lyrics.Parent = self lyrics.Text = text lyrics.Font = font lyrics.Location = Point(10, 10) lyrics.Size = Size(390, 390) self.Size = Size(400,400) self.CenterToScreen()
def __init__(self): self.Text = "Hello World" self.FormBorderStyle = FormBorderStyle.Fixed3D self.Height = 150 newFont = Font("Verdana", 16, FontStyle.Bold | FontStyle.Italic) label = Label() label.AutoSize = True label.Text = "My Hello World Label" label.Location = Point(10, 50) label.BackColor = Color.Aquamarine label.ForeColor = Color.DarkMagenta label.Font = newFont self.Controls.Add(label)
import clr clr.AddReference('System.Windows.Forms') clr.AddReference('System.Drawing') from System.Windows.Forms import ( Application, Form, FormBorderStyle, Label ) from System.Drawing import ( Color, Font, FontStyle, Point ) form = Form() form.Text = "Hello World" form.FormBorderStyle = FormBorderStyle.Fixed3D form.Height = 150 newFont = Font("Verdana", 16, FontStyle.Bold | FontStyle.Italic) label = Label() label.AutoSize = True label.Text = "My Hello World Label" label.Font = newFont label.BackColor = Color.Aquamarine label.ForeColor = Color.DarkMagenta label.Location = Point(10, 50) form.Controls.Add(label) Application.Run(form)
import clr clr.AddReference('System.Windows.Forms') clr.AddReference('System.Drawing') from System.Windows.Forms import (Application, Form, FormBorderStyle, Label) from System.Drawing import (Color, Font, FontStyle, Point) form = Form() form.Text = "Hello World" form.FormBorderStyle = FormBorderStyle.Fixed3D form.Height = 150 newFont = Font("Verdana", 16, FontStyle.Bold | FontStyle.Italic) label = Label() label.AutoSize = True label.Text = "My Hello World Label" label.Location = Point(10, 50) label.BackColor = Color.Aquamarine label.ForeColor = Color.DarkMagenta label.Font = newFont form.Controls.Add(label) Application.Run(form)
def __init__(self): #the __init__ method inside a class is its constructor self.Text = "AU London" #text that appears in the GUI titlebar self.Icon = Icon.FromHandle( icon.GetHicon() ) #takes a bitmap image and converts to a file that can be used as a Icon for the titlebar self.BackColor = Color.FromArgb(255, 255, 255) self.WindowState = FormWindowState.Normal # set maximised minimised or normal size GUI self.CenterToScreen() # centres GUI to the middle of your screen self.BringToFront() #brings the GUI to the front of all opens windows. self.Topmost = True # true to display the GUI infront of any other active forms screenSize = Screen.GetWorkingArea( self ) #get the size of the computers main screen, as the form will scale differently to different sized screens self.Width = screenSize.Width / 4 #set the size of the form based on the size of the users screen. this helps to ensure consistant look across different res screens. self.Height = screenSize.Height / 4 uiWidth = self.DisplayRectangle.Width #get the size of the form to use to scale form elements uiHeight = self.DisplayRectangle.Height #self.FormBorderStyle = FormBorderStyle.FixedDialog # fixed dialog stops the user from adjusting the form size. Recomended disabling this when testing to see if elements are in the wrong place. self.userOutput = userOutputDefaultStr #create a container to store the output from the form self.runNextOutput = False #set these default values #############-------------\-------------############# spacing = 10 #spacing size for GUI elements to form a consistent border # creates the text box for a info message userMessage = Label() #label displays texts font = Font("Helvetica ", 10) userMessage.Text = message userMessage.Font = font userMessage.Location = Point( spacing, spacing ) #all location require a point object from system.Drawing to set the location. userMessage.Size = Size( uiWidth - (spacing * 2), (uiHeight / 4) ) #size the control with the width of the GUI to ensure it scales with different screen self.Controls.Add(userMessage) #this adds control element to the GUI #############-------------\-------------############# #logo file logo = PictureBox() logo.Image = logoFile ratio = float(logo.Height) / float( logo.Width ) #needs to be a float as int will round to the nearest whole number logo.Size = Size( uiWidth / 4, (uiHeight / 4) * ratio ) #scale the image by the ratio between the images height & width logo.Location = Point(spacing, (uiHeight - logo.Height) - spacing) logo.SizeMode = PictureBoxSizeMode.Zoom # zooms the image to fit the extent logo.Anchor = ( AnchorStyles.Bottom | AnchorStyles.Left ) #anchor styles lock elements to a given corner of the GUI if you allow users change size self.Controls.Add(logo) #logo.BorderStyle = BorderStyle.Fixed3D #gives a border to the panel to test its location #############-------------\-------------############# #combox drop down cBox = ComboBox() #dropdown control form cBox.Location = Point(spacing, uiHeight / 3) cBox.Width = uiWidth - (spacing * 2) cBox.Items.AddRange( listInput ) # Adds an array of items to the list of items for a ComboBox. cBox.DropDownStyle = ComboBoxStyle.DropDownList #setting to dropdown list prevents users from being able to add aditional text values cBox.SelectedIndexChanged += self.dropDownOutput #.Click+= registers the press of the button to register the event handler and determine what action takes place when button clicked self.Controls.Add(cBox) #############-------------\-------------############# #Create ok button btnOk = Button() #create a button control btnOk.Text = "Next" btnOk.Location = Point(uiWidth - ((btnOk.Width * 2) + spacing), uiHeight - (btnOk.Height + spacing)) btnOk.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right) btnOk.Click += self.okButtonPressed #Register the event on the button bress to trigger the def okButtonPressed self.Controls.Add(btnOk) #Create Cancel Button btnCancel = Button() #btnCancel.Parent = self btnCancel.Text = "Cancel" btnCancel.Location = Point(uiWidth - (btnOk.Width + spacing), uiHeight - (btnOk.Height + spacing)) btnCancel.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right) btnCancel.Click += self.CnlButtonPressed self.Controls.Add(btnCancel)