Created
July 15, 2016 14:24
-
-
Save masoo/89bb091ae3e0f0f98fbcbee9c8d546db to your computer and use it in GitHub Desktop.
ruby-csharp_script sample #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'win32ole' | |
csharp_script = WIN32OLE.new('ruby.csharp_script.CsharpScript') | |
code = <<"EOS" | |
#r "PresentationFramework " | |
using System; | |
using System.Windows; | |
using System.Windows.Controls; | |
public partial class CodeOnlyWindow : Window | |
{ | |
public CodeOnlyWindow() | |
{ | |
this.Width = 300; | |
this.Height = 300; | |
Grid grid = new Grid(); | |
this.Content = grid; | |
Button button1 = new Button(); | |
button1.Content = "Say Hello!"; | |
button1.Height = 23; | |
button1.Margin = new Thickness(96, 50, 107, 0); | |
button1.VerticalAlignment = System.Windows.VerticalAlignment.Top; | |
button1.Click += new RoutedEventHandler(button1_Click); | |
grid.Children.Add(button1); | |
label1 = new Label(); | |
label1.Margin = new Thickness(84,115,74,119); | |
grid.Children.Add(label1); | |
} | |
private Label label1; | |
void button1_Click(object sender, RoutedEventArgs e) | |
{ | |
label1.Content = "Hello WPF!"; | |
} | |
} | |
new CodeOnlyWindow().ShowDialog(); | |
EOS | |
csharp_script.EvaluateAsync(code) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment