| 1 | # .compile-only. |
|---|
| 2 | # .args. -c |
|---|
| 3 | """ |
|---|
| 4 | To compile: |
|---|
| 5 | cobra -c -t:winexe 380-WinForms.cobra |
|---|
| 6 | |
|---|
| 7 | To run: |
|---|
| 8 | winforms |
|---|
| 9 | |
|---|
| 10 | Or leave out the "-c" to compile and run in one shot. |
|---|
| 11 | |
|---|
| 12 | Also, leave out -t:winexe and run from the command line to see the output of |
|---|
| 13 | `print` and `trace` statements. |
|---|
| 14 | |
|---|
| 15 | Note that you don't have to explicitly reference the System.Windows.Forms.dll in |
|---|
| 16 | the command line because the `use` clause below will automatically locate it. |
|---|
| 17 | |
|---|
| 18 | Recommended reading: |
|---|
| 19 | |
|---|
| 20 | Programming Microsoft Windows Forms |
|---|
| 21 | by Charles Petzold |
|---|
| 22 | |
|---|
| 23 | Pro .NET 2.0 Windows Forms |
|---|
| 24 | by Matthew MacDonald |
|---|
| 25 | |
|---|
| 26 | Cobra tips: |
|---|
| 27 | * Combine enums: AnchorStyle(Left, Right) |
|---|
| 28 | * Hook up events: listen someObj.someEvent, ref .myMethod |
|---|
| 29 | * In event handlers, leave out the type of the sender and you can use |
|---|
| 30 | dynamic typing to easily access the senders properties and methods. |
|---|
| 31 | |
|---|
| 32 | There is more substantial WinForms code in the source code for Cobra under |
|---|
| 33 | Source/ObjectExplorer-WinForms.cobra. |
|---|
| 34 | """ |
|---|
| 35 | |
|---|
| 36 | @args t:winexe |
|---|
| 37 | |
|---|
| 38 | use System.Windows.Forms |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | class MyForm inherits Form |
|---|
| 42 | |
|---|
| 43 | cue init |
|---|
| 44 | base.init |
|---|
| 45 | .text = 'Sample Form' |
|---|
| 46 | flp = FlowLayoutPanel(parent=this, dock=DockStyle.Fill, flowDirection=FlowDirection.TopDown) |
|---|
| 47 | b = Button(parent=flp, autoSize=true, text='One', tag=1) |
|---|
| 48 | listen b.click, ref .handleClick |
|---|
| 49 | b = Button(parent=flp, autoSize=true, text='Two', tag=2) |
|---|
| 50 | listen b.click, ref .handleClick |
|---|
| 51 | |
|---|
| 52 | def handleClick(sender, args as EventArgs) |
|---|
| 53 | MessageBox.show(this, 'You clicked [sender.text]/[sender.tag]', 'Click') |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | class Program |
|---|
| 57 | |
|---|
| 58 | def main has STAThread |
|---|
| 59 | Application.run(MyForm()) |
|---|