""" To compile: cobra -c -t:winexe 380-WinForms.cobra To run: winforms Or leave out the "-c" to compile and run in one shot. Also, leave out -t:winexe and run from the command line to see the output of `print` and `trace` statements. Note that you don't have to explicitly reference the System.Windows.Forms.dll in the command line because the `use` clause below will automatically locate it. Recommended reading: Programming Microsoft Windows Forms by Charles Petzold Pro .NET 2.0 Windows Forms by Matthew MacDonald Cobra tips: * Combine enums: AnchorStyle(Left, Right) * Hook up events: listen someObj.someEvent, ref .myMethod * In event handlers, leave out the type of the sender and you can use dynamic typing to easily access the senders properties and methods. There is more substantial WinForms code in the source code for Cobra under Source/ObjectExplorer-WinForms.cobra. """ @args -t:winexe use System.Windows.Forms class MyForm inherits Form cue init base.init .text = 'Sample Form' flp = FlowLayoutPanel(parent=this, dock=DockStyle.Fill, flowDirection=FlowDirection.TopDown) b = Button(parent=flp, autoSize=true, text='One', tag=1) listen b.click, ref .handleClick b = Button(parent=flp, autoSize=true, text='Two', tag=2) listen b.click, ref .handleClick def handleClick(sender, args as EventArgs) MessageBox.show(this, 'You clicked [sender.text]/[sender.tag]', 'Click') class Program def main has STAThread Application.run(MyForm()) |
How To Win Forms