2019년 8월 31일 토요일

[C#/Mono] Zip


wZip.cs



using System;
using System.IO;
using System.IO.Compression;

public class WZip
{
 public WZip() {
 }

 public void zipFromDirectory(string dir, string zipFile) {
        ZipFile.CreateFromDirectory(dir, zipFile);
    }
 
 public void unzipToDirectory(string zipFile, string dir) {
        ZipFile.ExtractToDirectory(zipFile, dir);
 }
 
 public void zipAddFile(string zipFile, string file, string entryName) {
  using( ZipArchive archive = ZipFile.Open(zipFile, ZipArchiveMode.Update) ) {
   archive.CreateEntryFromFile(file, entryName);
   //archive.ExtractToDirectory(extractPath);
  } 
 }
 
 public void zipExtractFile(string zipFile, string file, string entryName) {
     using( ZipArchive archive = ZipFile.OpenRead(zipFile) ) {
            foreach (ZipArchiveEntry entry in archive.Entries) {
                //if (entry.FullName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase)) {
                if( entry.FullName.Equals( entryName ) ) {
                    entry.ExtractToFile(file);
                }
            }
        }
 }
}

[C#/Mono] WebBrowser


wWeb.cs



using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;

public class WWebBrowser : WCtrl
{
 ToolStripTextBox addr;
 Panel panel;
 WebBrowser web;

 public WWebBrowser( bool toolbar ) {
  ctrl = web = new WebBrowser();
  web.Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left;
  web.Dock = DockStyle.Fill;
  web.ScrollBarsEnabled = true;

  panel = new Panel();
  panel.Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left;
  panel.Dock = DockStyle.Fill;
  panel.Controls.Add(web);

  if( toolbar ) {
   makeToolBar();
  }
 }

 public ToolStripButton addToolbarButton(ToolStrip tool, String text, EventHandler handler) {
  ToolStripButton button = new ToolStripButton();
  button.Name = text;
  button.Text = text;
  button.Click += handler;
  tool.Items.Add(button);
  return button;
 }

 public ToolStripTextBox addToolbarTextBox(ToolStrip tool, String text, KeyEventHandler handler) {
  ToolStripTextBox textbox = new ToolStripTextBox();
  textbox.Name = text;
  textbox.Text = "";
  textbox.Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left;
  textbox.Dock = DockStyle.Fill;
  if (handler != null) {
   textbox.KeyDown += handler;
  }
  tool.Items.Add(textbox);
  return textbox;
 }

 private void makeToolBar() {
  ToolStrip tool2 = new ToolStrip();
  this.addr = addToolbarTextBox(tool2, "addr", addrHandler);
  addToolbarButton(tool2, "go", goHandler).Alignment = ToolStripItemAlignment.Right;
  panel.Controls.Add(tool2);

  ToolStrip tool1 = new ToolStrip();
  addToolbarButton(tool1, "reload", reloadHandler);
  addToolbarButton(tool1, "back", backHandler);
  addToolbarButton(tool1, "forward", forwardHandler);
  addToolbarButton(tool1, "text", textHandler);
  addToolbarButton(tool1, "html", htmlHandler);
  panel.Controls.Add(tool1);
 }


 public void loadUrl(String url) {
  web.Navigate(url);
 }

 public String getHtml() {
  return web.DocumentText;
 }

 public String getInnerText() {
  List<String> htmls = getText("html");
  return htmls[0];
 }

 public String getInnerHtml() {
  List<String> htmls = getHtmlText("html");
  return htmls[0];
 }

 public List<String> getText(String tag) { //html, body, img ...
  List<String> htmls = new List<String>();
  HtmlElementCollection elm = web.Document.GetElementsByTagName(tag);
  foreach( HtmlElement html in elm ) {
   htmls.Add(html.InnerText);
  }
  return htmls;
 }

 public List<String> getHtmlText(String tag) {
  List<String> htmls = new List<String>();
  HtmlElementCollection elm = web.Document.GetElementsByTagName(tag);
  foreach( HtmlElement html in elm ) {
   htmls.Add(html.InnerHtml);
  }
  return htmls;
 }

 private void reloadHandler(object source, EventArgs e) {
  web.Refresh();
 }

 private void backHandler(object source, EventArgs e) {
  if( web.CanGoBack ) {
   web.GoBack();
  }
 }

 private void forwardHandler(object source, EventArgs e) {
  if (web.CanGoForward) {
   web.GoForward(); 
  }
 }

 private void textHandler(object source, EventArgs e) {
  Clipboard.SetText(getInnerText());
 }

 private void htmlHandler(object source, EventArgs e) {
  Clipboard.SetText(getInnerHtml());
 }

 private void addrHandler(object source, KeyEventArgs e) {
  if (e.KeyCode == Keys.Enter) {
   web.Navigate(addr.Text);
  }
 }

 private void goHandler(object source, EventArgs e) {
  web.Navigate(addr.Text);
    }
}

[C#/Mono] Toolbar


wTool.cs



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

public class WTool : WCtrl
{
 ToolStrip tool;
 
 public WTool(int fontSize, int iconSize) : base(fontSize) {
  ctrl = tool = new ToolStrip();
  if( fontSize > 0 ) {
   SetFontSize(fontSize);
  }
  if( iconSize > 0 ) {
   tool.ImageScalingSize = new Size(iconSize, iconSize);
  }
 }
 public WTool(int fontSize) : this(fontSize,0) {}
 public WTool() : this(0,0) {}
 
 public ToolStripSeparator AddSeparator() {
  ToolStripSeparator ctl = new ToolStripSeparator();
  if( fontSize > 0 ) {
   ctl.Font = new Font(ctl.Font.Name, fontSize, 
    ctl.Font.Style, ctl.Font.Unit);   
  }
  tool.Items.Add( ctl );
  return ctl;
 }

 public ToolStripLabel AddLabel(string text) {
  ToolStripLabel ctl = new ToolStripLabel(text);
  if( fontSize > 0 ) {
   ctl.Font = new Font(ctl.Font.Name, fontSize, 
    ctl.Font.Style, ctl.Font.Unit);   
  }
  tool.Items.Add( ctl );
  return ctl;
 }
 
 public ToolStripButton AddButton(string text, Image icon, EventHandler handler) {
  ToolStripButton ctl = new ToolStripButton();
  if( fontSize > 0 ) {
   ctl.Font = new Font(ctl.Font.Name, fontSize, 
    ctl.Font.Style, ctl.Font.Unit);   
  }
  if( text != null ) {
   ctl.Text = text;
  }
  if( icon != null ) {
   ctl.Image = icon;
   ctl.Height = 64;
   ctl.TextImageRelation = TextImageRelation.ImageAboveText;
   //Overlay, ImageBeforeText, TextBeforeImage, TextAboveImage, ImageAboveText
   /*
   ctl.ImageAlign = ContentAlignment.MiddleRight;    
   ctl.TextAlign = ContentAlignment.MiddleLeft;   
   */
  }
  ctl.Click += handler;
  tool.Items.Add( ctl );
  return ctl;
 }
 public ToolStripButton AddButton(string text, EventHandler handler) {
  return AddButton( text, null, handler );
 }
 public ToolStripButton AddButton(Image icon, EventHandler handler) {
  return AddButton( null, icon, handler );
 } 
 public ToolStripTextBox AddTextBox(string text, KeyEventHandler handler) {
  ToolStripTextBox ctl = new ToolStripTextBox();
  ctl.BorderStyle = BorderStyle.FixedSingle;
  if( fontSize > 0 ) {
   ctl.Font = new Font(ctl.Font.Name, fontSize, 
    ctl.Font.Style, ctl.Font.Unit);   
  }
  if( text != null ) {
   ctl.Text = text;
  }
  if( handler != null ) {
   ctl.KeyDown += handler;
  }
  tool.Items.Add( ctl );
  return ctl;
 }

 public ToolStripComboBox AddComboBox(string[] items, EventHandler handler) {
  ToolStripComboBox ctl = new ToolStripComboBox();
  ctl.FlatStyle = FlatStyle.System;
  /*
  ctl.Paint += new PaintEventHandler((s,e) => {
   Rectangle r = new Rectangle(
    ctl.ComboBox.Location.X - 1,
    ctl.ComboBox.Location.Y - 1,
    ctl.Size.Width + 1,
    ctl.Size.Height + 1);
   Pen pen = new Pen(SystemColors.Window);
   pen.Color = Color.Blue;
   e.Graphics.DrawRectangle(pen, r);
  });
  */
  if( fontSize > 0 ) {
   ctl.Font = new Font(ctl.Font.Name, fontSize, 
    ctl.Font.Style, ctl.Font.Unit);   
  }
  if( items != null ) {
   ctl.Items.AddRange(items);
   ctl.SelectedIndex = 0; 
  }
  if( handler != null ) {
   ctl.SelectedIndexChanged += handler;
  }
  tool.Items.Add(ctl);
  return ctl;
 }

 public ToolStripProgressBar AddProgressBar() {
  ToolStripProgressBar ctl = new ToolStripProgressBar();
  if( fontSize > 0 ) {
   ctl.Font = new Font(ctl.Font.Name, fontSize, 
    ctl.Font.Style, ctl.Font.Unit);   
  }
  tool.Items.Add( ctl );
  return ctl;
 }

 public ToolStripSplitButton AddSplitButton() {
  ToolStripSplitButton ctl = new ToolStripSplitButton();
  if( fontSize > 0 ) {
   ctl.Font = new Font(ctl.Font.Name, fontSize, 
    ctl.Font.Style, ctl.Font.Unit);   
  }
  tool.Items.Add( ctl );
  return ctl;
 }
  
};

[C#/Mono] TextBox


wTextBox.cs



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

public class WTextBox : WCtrl
{
 TextBox text;

 public WTextBox(int size) : base(size) {
  ctrl = text = new TextBox();
  SetFontSize(size);
  anchorAll();
  dockFill();
  text.Multiline = false;
  text.ScrollBars = ScrollBars.Both;
  text.WordWrap = false;
  text.AcceptsReturn = true;
  text.AcceptsTab = true;  
  text.Show();
 }
 public WTextBox() : this(0) {}
 
 public void clearText() {
  text.Text = "";
 }

 public void addText(String s) {
  text.Text += s;
 }

 public void enableMultiLine() {
  text.Multiline = true;
 }

 public void enableWordWrap() {
  text.WordWrap = true;
 }

 public void enableScrollBar() {
  text.ScrollBars = ScrollBars.Both;
 }

 public void enableDrop() {
  text.AllowDrop = true;
 }
}

2019년 8월 30일 금요일

[C#/Mono] Tab


wTab.cs



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

public class WTab : WCtrl
{
 TabControl tab;
 
 public WTab(int fontSize) {
  ctrl = tab = new TabControl();
  if( fontSize > 0 ) {
   SetFontSize(fontSize);
  }  
  anchorAll();
  dockFill();  
 }
 public WTab() : this(0) {}
  
 public void AddPage(string text, Control ctl) {
  TabPage page = new TabPage();
  page.Text = text;
  page.Padding = new Padding(10);
  page.Controls.Add(ctl);
  tab.Controls.Add(page);
 }
}

[C#/Mono] Status


wStatus.cs



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

public class WStatus : WCtrl
{
 StatusStrip status;
 ToolStripStatusLabel label;
 
 public WStatus() {
  ctrl = status = new StatusStrip();
  label = new ToolStripStatusLabel();
  label.Name = "StatusText";
  label.Text = "Ready";
  //this.label.Size = new Size(39, 17);
  //this.label.Click += new EventHandler(this.ToolStripStatusLabel1_Click);
  
  status.Items.Add( label );
 }
 
 public void SetText(string text) {
  label.Text = text;
 }
 
};

[C#/Mono] Split


wSplit.cs



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

public class WSplit : WCtrl
{
 class SplitPanel {
  Panel[] panel = new Panel[2];
  public Panel this[int i] {
   get{ 
    if( 0 <= i && i <= 1 )
     return panel[i];
    else
     return null;
   }
   set{ 
    if( 0 <= i && i <= 1 )
     panel[i] = value;
   }
  }
 }
 SplitPanel panel;
 SplitContainer split;

 public WSplit(bool vert) {
  ctrl = split = new SplitContainer();
  anchorAll();
  dockFill();
  if( vert ) {
   split.Orientation = Orientation.Vertical;
  } else {
   split.Orientation = Orientation.Horizontal;
  }
  split.SplitterDistance = (int)(split.ClientSize.Width * 0.8);
  
  panel = new SplitPanel();
  panel[0] = split.Panel1;
  panel[1] = split.Panel2;
  
  //split.AutoScaleMode = AutoScaleMode.None;
  //split.Size = new Size(100,200);
  //split.SplitterWidth = 6;
  //split.Location = new Point(0, 0);


  //split.FixedPanel = FixedPanel.Panel1;
  //split.Panel1MinSize = 100;
  //split.Panel1Collapsed = false;
  //split.Panel2MinSize = 100;
  //split.Panel1Collapsed = false;
  //split.Show();
 }

 public WSplit() : this(true) {}
 
 public void Add(int i, Control ctrl) {
  panel[i].Controls.Add(ctrl);
 }
 
 public void FixWidth(int i) {
  split.FixedPanel = i == 0 ? 
   FixedPanel.Panel1 : FixedPanel.Panel2;
 }

 public void SetBackColor(int i, Color color) {
  panel[i].BackColor = color; //Color.Green, Color.Yellow
 }

 public void SetForeColor(int i, Color color) {
  panel[i].ForeColor = color;
 }

 public void Hide(int i) {
  if( i == 0 ) split.Panel1Collapsed = true;
  else split.Panel2Collapsed = true;
 }
 
 public void Show(int i) {
  if( i == 0 ) split.Panel1Collapsed = false;
  else split.Panel2Collapsed = false;
 }
}

Process


wProc.cs



using System;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Collections.Generic;

public class WProc
{
 public WProc() {
 }

 public string run(string fileName) {
  System.Diagnostics.Process proc = new System.Diagnostics.Process();
  proc.StartInfo.FileName = fileName; //@"C:\Users\Vitor\ConsoleApplication1.exe";
  proc.StartInfo.Arguments = "olaa"; //argument
  proc.StartInfo.UseShellExecute = false;
  proc.StartInfo.RedirectStandardOutput = true;
  proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
  proc.StartInfo.CreateNoWindow = true; //not diplay a windows
  proc.Start();
  string output = proc.StandardOutput.ReadToEnd(); //The output result
  proc.WaitForExit();
  return output;
 }
 
 public void execute(string fileName) {
  Process proc = new Process();
  proc.StartInfo.FileName = fileName; //"Notepad.exe";
  //proc.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
  proc.Start();
  proc.WaitForExit(); 
  
  //System.Diagnostics.Process.Start("calc.exe"); 
 }
}

[C#/Mono] PictureBox


wPictureBox.cs



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

public class WPictureBox : WCtrl
{
 PictureBox pic;
 
 public WPictureBox( ) {
  ctrl = pic = new PictureBox();
  pic.BorderStyle = BorderStyle.Fixed3D; //System.Windows.Forms.
  pic.SizeMode = PictureBoxSizeMode.StretchImage;
 }

 public void setImage(Bitmap image) {
  pic.Image = image;
 }
}

[C#/Mono] Panel


wPanel.cs



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

public class WPanel : WCtrl
{
 Panel panel;
 
 public WPanel() {
  ctrl = panel = new Panel();
  panel.AutoScroll = true;
  panel.AllowDrop = true;
  panel.AutoSize = false;
 }

 public void SetBorderStyleNone() {
  panel.BorderStyle = BorderStyle.None;  
 }
 public void SetBorderStyleLine() {
  panel.BorderStyle = BorderStyle.FixedSingle;  
 }
 public void SetBorderStyle3D() {
  panel.BorderStyle = BorderStyle.Fixed3D;  
 }
}

[C#/Mono] Net


wNet.cs



using System;
using System.Net;

public class WNet
{
 public WNet() {
 }

 private void httpGet(string url, string fileName) {
  //"http://www.sayka.com/downloads/front_view.jpg"
  //"D:\\Images\\front_view.jpg"
  using( WebClient wc = new WebClient() ) {
   wc.DownloadProgressChanged += wc_DownloadProgressChanged;
   wc.DownloadFileAsync(new System.Uri(url), fileName );
  }
 }
 
 void wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) {
  //progressBar.Value = e.ProgressPercentage;
  System.Console.WriteLine( e.ProgressPercentage );
 } 
}

[C#/Mono] Menu


wMenu.cs



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

public class WMenu : WCtrl
{
 MenuStrip menu;
 ToolStripMenuItem currMenu;

 public WMenu(int fontSize, int iconSize) :  base(fontSize) {
  ctrl = menu = new MenuStrip();
  if( fontSize > 0 ) {
   SetFontSize(fontSize);
  }
  if( iconSize > 0 ) {
   menu.ImageScalingSize = new Size(iconSize, iconSize);
  }        
 }
 public WMenu(int fontSize) : this(fontSize,0) {}
 public WMenu() : this(0,0) {}

 public void AddMenu( string name ) {
        currMenu = new ToolStripMenuItem();
        currMenu.Text = name;
        currMenu.Size = new Size(80, 22);
        menu.Items.Add(this.currMenu);
 }
 
 public void AddMenuItem( string name, Image icon, EventHandler handler ) {
  ToolStripMenuItem item = new ToolStripMenuItem();
  if( icon != null ) {
   item.Image = icon;
  }
  item.Name = name;
  item.Text = name;
  item.Size = new Size(180, 22);
  item.Click += handler;
  currMenu.DropDownItems.Add(item);
 }
 public void AddMenuItem( string name, EventHandler handler ) {
  AddMenuItem( name, null, handler );
 }
}

[C#/Mono] ListBox


wListBox.cs



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

public class WListBox : WCtrl
{
 ListBox listbox;
 public ListBox lb { get { return listbox; } }
 public WListBox( String[] items, EventHandler handler, int size ) : base(size) {
  ctrl = listbox = new ListBox();
  SetFontSize(size);
  anchorAll();
  dockFill();
  if( items != null ) {
   for( int i = 0; i < items.Length; i++ ) {
    listbox.Items.Add( items[i] );
   }
  }
  if( handler != null ) {
   listbox.Click += handler;
  }
  //listbox.Show();
 } 
 public WListBox( String[] items, EventHandler handler ) : this(items,handler,0) {}
 public WListBox( String[] items ) : this(items,null,0) {}
 public WListBox( String[] items, int size ) : this(items,null,size) {}
 public WListBox( EventHandler handler) : this(null,handler,0) {}
 public WListBox( EventHandler handler, int size) : this(null,handler,size) {}
 public WListBox( int size) : this(null,null,size) {}
 public WListBox() : this(null,null,0) {}

 public void AddItem(String text) {
  listbox.Items.Add(text);
 }

 public int getSelectedIndex() {
  return listbox.SelectedIndex;
 }

 public String getSelectedText() {
  return listbox.Items[listbox.SelectedIndex].ToString();
 }

 public void selectFirstItem() {
  if( listbox.Items.Count > 0 )
            listbox.SelectedIndex = 0; 
 }
 
 public void SetEventHandler(EventHandler handler) {
  if( handler != null ) {
   listbox.Click += handler;
  }  
 }
}

[C#/Mono] Table


wLayoutTable.cs



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

public class WLayoutTable : WCtrl
{
 TableLayoutPanel table;
 
    public WLayoutTable(int row, int col) {
  ctrl = table = new TableLayoutPanel();
  table.Name = "";
  table.RowCount = row;
  table.ColumnCount = col;
  table.Location = new Point(10, 10);
    }

 public void setColumnSize( params int[] len ) {
  for( int i = 0; i < len.Length; i++ ) {
   ColumnStyle style = null;
   int length = i < len.Length ? len[i] : 0;
   if( length == 0 ) {
    style = new ColumnStyle(SizeType.AutoSize);  //style.SizeType
   } else if( length > 0 ) {
    style = new ColumnStyle(SizeType.Percent, length);
   } else if( length < 0 ) {
    style = new ColumnStyle(SizeType.Absolute, -length);
   } 
   table.ColumnStyles.Add(style);
  }
 }

 public void setRowSize( params int[] len ) {
  for( int i = 0; i < table.RowCount; i++ ) {
   RowStyle style = null;
   int length = i < len.Length ? len[i] : 0;
   if( length == 0 ) {
    style = new RowStyle(SizeType.AutoSize); //style.SizeType
   } else if( length > 0 ) {
    style = new RowStyle(SizeType.Percent, length);
   } else if( length < 0 ) {
    style = new RowStyle(SizeType.Absolute, -length);
   } 
   table.RowStyles.Add(style);
  }
 }
 
 public void Add( Control ctrl, int row, int col ) {
  table.Controls.Add( ctrl, col, row );
 }
 
 public void setColumnSpan( int row, int col, int num ) {
  Control ctl = table.GetControlFromPosition( col, row );
  if( ctl != null ) {
   table.SetColumnSpan(ctl, num);
  }
 }
 
 public void setRowSpan( int row, int col, int num ) {
  Control ctl = table.GetControlFromPosition( col, row );
  if( ctl != null ) {
   table.SetRowSpan(ctl, num);
  }  
 }
}


           

[C#/Mono] GroupBox


wGroupBox.cs



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

public class WGroupBox : WCtrl
{
 GroupBox gbox;
 
 public WGroupBox(string text, int fontSize) {
  ctrl = gbox = new GroupBox();
  if( fontSize > 0 ) {
   SetFontSize(fontSize);
  }  
  gbox.Text = "group";  
  gbox.Margin = new Padding(20);
  gbox.Padding = new Padding(20);
  anchorAll();
  dockFill();  
 }
 public WGroupBox(string text) : this(text,0) {}
 
}

[C#/Mono] Form


wForm.cs



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

public class WForm 
{
 Form form;
 
 public Form getCtrl() {
  return form;
 }
 
    public WForm( int width, int height ) {
  form = new Form();
        form.Text = "WinForm V0.0.1";
     form.MinimumSize = new Size(width, height);
  form.StartPosition = FormStartPosition.CenterScreen;
    }
 
 public void Add( Control ctrl) {
  form.Controls.Add(ctrl);
 }
 
 public int getWidth() {
  return form.Width;
 }
 
 public int getHeight() {
  return form.Height;
 }

}

[C#/Mono] Flow


wFlow.cs


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

public class WFlow : WCtrl
{
 FlowLayoutPanel flow;
 
 public WFlow(bool vert) {
  ctrl = flow = new FlowLayoutPanel();
  flow.AutoScroll = false;
  flow.AutoSize = true;
  flow.BorderStyle = BorderStyle.FixedSingle;
  if( vert ) {
   flow.FlowDirection = FlowDirection.TopDown;
  } else {
   flow.FlowDirection = FlowDirection.LeftToRight;
  }
  //anchorAll();
  dockFill();  
 }
 public WFlow() : this(false) {}

/*
 public void Add(Control ctl) {
  flow.Controls.Add(ctl);
  flow.BringToBack();  
 }
*/ 
 public void SetBorderStyleNone() {
  flow.BorderStyle = BorderStyle.None;  
 }
 public void SetBorderStyleLine() {
  flow.BorderStyle = BorderStyle.FixedSingle;  
 }
 public void SetBorderStyle3D() {
  flow.BorderStyle = BorderStyle.Fixed3D;  
 }
}

[C#/Mono] File


wFile.cs



using System;
using System.IO;
using System.Text;
using System.Collections.Generic;

public class WFile
{
 public WFile() {
 }

 public static bool exist(string fileName) {
  return File.Exists(fileName);
 }
 
 public static bool space(char charValue) {
  return char.IsWhiteSpace(charValue);
 }
 
 public static string pathJoin(string dir, string file) {
  return Path.Combine( dir, file );
 }

 public static void delete(string fileName) {
  File.Delete(fileName);
 }

 public static void create(string fileName) {
  Directory.CreateDirectory(fileName);
 }
 
 public static string parent(string fileName) {
  return Path.GetDirectoryName(fileName);
 }

 public static string getDocumentFolder() {
        return Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
 }
 
 public static List<string> getDirectoryList(string fileName) {
  return new List<string>(Directory.EnumerateDirectories(fileName));
 }
     
 public static List<string> getDirectoryList2(string fileName) {
  System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(fileName);
  foreach( System.IO.FileInfo file in dir.GetFiles() ) {
   //file.FullName
   //file.Extension
  }
  return new List<string>();
 }
       
    public static void fileWriteBinary(string fileName, int intValue ) {
        using( FileStream fs = new FileStream(fileName, FileMode.CreateNew) ) {
            using( BinaryWriter w = new BinaryWriter(fs) ) {
                w.Write(intValue);
            }
        }  
 }

    public static int fileReadBinary(string fileName ) {
        using( FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read) ) {
            using( BinaryReader r = new BinaryReader(fs) ) {
    return r.ReadInt32();
            }
        } 
 }
 
    public static void fileWriteText(string fileName, string strValue ) {
        using( StreamWriter sw = new StreamWriter(fileName) ) {
   sw.Write( strValue );
        } 
 }  

    public void fileAppendText(string fileName, string strValue ) {
        using( StreamWriter sw = new StreamWriter(fileName, true) ) {
   sw.Write( strValue );
        } 
 }  
 
    public static async void fileWriteTextAsync(string fileName, string strValue ) {
        using( StreamWriter sw = new StreamWriter(fileName) ) {
   await sw.WriteAsync( strValue );
        } 
 }  

    public static string fileReadText(string fileName ) {
        using( StreamReader sr = new StreamReader(fileName) ) {
            return sr.ReadToEnd();
        } 
 } 
 
 /*
    public static async void fileReadTextASync(string fileName ) {
  try {
   using( StreamReader sr = new StreamReader("TestFile.txt") ) {
    string line = await sr.ReadToEndAsync();
    ResultBlock.Text = line;
   }
  }
  catch( FileNotFoundException ex ) {
   ResultBlock.Text = ex.Message;
  }
 } 
 */
 
 public static void fileWriteAllText(string fileName, string text) {
  File.WriteAllText( fileName, text);
 }
 
 public static void fileWriteAllText(string fileName, string[] lines) {
  File.WriteAllLines( fileName, lines);
 }
 
 public static char[] stringRead( string strValue, int len ) {
        using (StringReader sr = new StringReader(strValue)) {
   char[] b = new char[strValue.Length];
            sr.Read(b, 0, 13);
            return b;
        }  
 }
 
 public static string stringWrite() {
        StringBuilder sb = new StringBuilder();
        using( StringWriter sw = new StringWriter(sb) ) {
            sw.Write("string1");
            sw.Write("string2");
            return sb.ToString();
        }  
 }
}

[C#/Mono] Dialog


wDialog.cs



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

public class WDialog : WCtrl
{
 public WDialog() {
 }
 
 public static void ok(string title, string message) {
  MessageBox.Show( message, title );
 }

 public static bool okcancel(string title, string message) {
  DialogResult rv = MessageBox.Show( message, title, MessageBoxButtons.OKCancel );
  if( rv == DialogResult.OK ) {
   return true;
  } else {
   return false;
  }  
 }

 public static bool yesno(string title, string message) {
  DialogResult rv = MessageBox.Show( message, title, MessageBoxButtons.YesNo );
  if( rv == DialogResult.Yes ) {
   return true;
  } else {
   return false;
  }  
 }

 public static int yesnocancel(string title, string message) {
  DialogResult rv = MessageBox.Show( message, title, MessageBoxButtons.YesNoCancel );
  if( rv == DialogResult.Yes ) return 1;
  if( rv == DialogResult.No  ) return 0;
  return -1;
 }
}

[C#/Mono] Ctrl


wCtrl.cs



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

public class WCtrl {
 
 protected Control ctrl;
 protected int fontSize = 0;
 
 protected WCtrl() {
 }

 protected WCtrl(int size) {
  fontSize = size;
 }
 
 public Control getCtrl() {
  return ctrl;
 }
 
 public Control getParent() {
  return ctrl.Parent;
 }
 
 public void SetSize( Size size ) {
  this.ctrl.Size = size;
 }

 public void setSize( Size size ) {
  this.ctrl.Size = size;
 }

 public void SetLocation( Point point ) {
  this.ctrl.Location = point;
 }
 
 public void dockTop() {
  this.ctrl.Dock = DockStyle.Top; 
 }
 
 public void dockBottom() {
  this.ctrl.Dock = DockStyle.Bottom; 
 }
 
 public void dockLeft() {
  this.ctrl.Dock = DockStyle.Left; 
 }
 
 public void dockRight() {
  this.ctrl.Dock = DockStyle.Right; 
 }

 public void dockFill() {
  this.ctrl.Dock = DockStyle.Fill; 
 }
 
 public void anchorAll() {
  this.ctrl.Anchor = AnchorStyles.Top | AnchorStyles.Bottom
    | AnchorStyles.Left | AnchorStyles.Right;  
 }

 virtual public void Add(Control ctl) {
  ctrl.Controls.Add(ctl);
 }

 public void SetBackColor(Color color) {
  ctrl.BackColor = color;
 }

 public void SetBackImage(Image image) {
  ctrl.BackgroundImage = image;
 }

 public void SetBackImage(string filename) {
  ctrl.BackgroundImage = new Bitmap(filename);
 }

 public void SetBounds(Rectangle bounds) {
  ctrl.Bounds = bounds;
 }

 public void Invalidate() {
  ctrl.Invalidate();
 } 
 
 public void SetTabIndex(int i ) {
  ctrl.TabIndex = i;
 }
 
 public void SetFontSize(int size) {
  if( size > 0 ) {
   ctrl.Font = new Font(ctrl.Font.Name, size, 
    ctrl.Font.Style, ctrl.Font.Unit); 
  }
 }
 
 public float GetFontSize(int size) {
  return ctrl.Font.Size;
 }

};

[C#/Mono] ComboBox


wComboBox.cs



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

public class WComboBox : WCtrl
{
 ComboBox cbox;

 public WComboBox() {
  ctrl = cbox = new ComboBox();
  cbox.Show();
 }

 public WComboBox( String[] items ) : this() {
  for( int i = 0; i < items.Length; i++ ) {
   cbox.Items.Add( items[i] );
  }
  cbox.Show();
 }
 
 public WComboBox( EventHandler handler ) : this() {
  if( handler != null ) {
   cbox.Click += handler;
  }
 }

 public void AddItem(String text) {
  cbox.Items.Add(text);
 }

 public int getSelectedIndex() {
  return cbox.SelectedIndex;
 }

 public String getSelectedText() {
  return cbox.Items[cbox.SelectedIndex].ToString();
 }

 public void selectFirstItem() {
  if( cbox.Items.Count > 0 )
            cbox.SelectedIndex = 0; 
 }
}

[C#/Mono] CheckBox


wCheckBox.cs



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

public class WCheckBox : WCtrl
{
 CheckBox checkbox;

 public WCheckBox(string text) {
  ctrl = checkbox = new CheckBox();
  checkbox.Text = text;
 }
}