2019년 8월 30일 금요일

[C#/Mono] Demo.cs


Demo.cs


using System;
using System.Drawing;
using System.Windows.Forms;

public class WDemo
{
 public WForm form;
 WBorder border;
 WMenu menu;
 WStatus status;

 WTool tool;
 ToolStripTextBox toolText;
 ToolStripComboBox toolCombo;
 
 int fontSize = 11;
 
 [STAThread]   
    public static void Main() {
  WDemo demo = new WDemo();
        Application.Run( demo.form.getCtrl());
    }
 
 public WDemo() {
  border = new WBorder();
  form = new WForm( 480, 360 );
  form.Add(border.getCtrl());
  form.getCtrl().Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);  
  makeStatus();
  makeContents();
  makeTool();
  makeMenu();  
 }
 
 Bitmap getBitmap(string id) {
  return new Bitmap( System.Reflection.Assembly
   .GetEntryAssembly()
   .GetManifestResourceStream(id));
 }
 
 string[] getBitmapNames() {
  return System.Reflection.Assembly
   .GetEntryAssembly()
   .GetManifestResourceNames();  
 }
 
 void makeMenu() {
   
  menu = new WMenu(fontSize);
  menu.AddMenu( "File" );
  menu.AddMenuItem( "Exit", getBitmap("exit.png")/*Image.FromFile("exit.png")*/, (s,e) => Environment.Exit(0) ); 
  menu.AddMenu( "Help" );
  menu.AddMenuItem( "About", getBitmap("about.png") /*Image.FromFile("about.png")*/, OnAbout ); 
  border.AddTop(menu.getCtrl());
  

 }
 
 void makeTool() {
  
  tool = new WTool(fontSize,24);
  tool.AddButton( "Exit", Image.FromFile("exit.png"), (s,e) => Environment.Exit(0) );
  tool.AddSeparator( );
  tool.AddLabel( "Output: " );
  toolText = tool.AddTextBox( "D:\\Temp", (s,e) => {
   if( e.KeyCode == Keys.Enter )
    MessageBox.Show( toolText.Text, "Info" );
  });
  toolCombo = tool.AddComboBox( new string[] { "one", "two", "three" }, 
   (s,e) => MessageBox.Show( toolCombo
    .Items[toolCombo.SelectedIndex]
    .ToString(), "Info" )
  );
  
  border.AddTop(tool.getCtrl());
 }
  
 void makeStatus() {
  status = new WStatus();
  status.SetText("Ready !");
  border.AddBottom(status.getCtrl());
 }

 void makeContents() {

  WTextBox text = new WTextBox(fontSize);
  text.enableMultiLine();
  text.anchorAll();
  text.dockFill();
  
  WListBox list = new WListBox(fontSize);
  list.SetEventHandler( (s,e) =>
   text.getCtrl().Text += (list.lb
    .Items[list.lb.SelectedIndex]
    .ToString() + "\r\n")
  );
        list.AddItem( "one" ); list.AddItem( "two" );
  list.AddItem( "three" ); list.AddItem( "four" );
        list.AddItem( "one" ); list.AddItem( "two" );
  list.AddItem( "three" ); list.AddItem( "four" );
  list.selectFirstItem();
  list.anchorAll();
  list.dockFill();

  WSplit split = new WSplit();
  split.Add(0,list.getCtrl());
  split.Add(1,text.getCtrl());
     split.anchorAll();
     split.dockFill();

  WFlow hbox = new WFlow(false);
  Button b;
  b = new Button(); b.Text = "One"; hbox.Add(b);
  b = new Button(); b.Text = "Two"; hbox.Add(b);
     hbox.anchorAll();
     hbox.dockBottom();
  
  WPanel panel = new WPanel();
  panel.anchorAll();
  panel.dockFill();
  panel.Add(hbox.getCtrl());
  panel.Add(split.getCtrl());

  WGroupBox gbox = new WGroupBox("Group", fontSize);

  b = new Button(); b.Text = "One"; b.Location = new Point(20,20); gbox.Add(b);
  b = new Button(); b.Text = "Two"; b.Location = new Point(100,20);gbox.Add(b);
     gbox.anchorAll();
     gbox.dockFill();
     
  WTab tab = new WTab(fontSize);
  tab.AddPage( "One", panel.getCtrl());
  tab.AddPage( "Two", gbox.getCtrl());
  
  border.AddCenter(tab.getCtrl());
 }

    void OnAbout(object sender, System.EventArgs e) {
  
  status.SetText("About clicked");
  WDialog.ok( "About WForm V0.0.1", "WinForms Application Template\n\n2019.8" );
  status.SetText("Ready !!");
 }
}

댓글 없음:

댓글 쓰기