2019년 8월 31일 토요일

[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;
 }
  
};

댓글 없음:

댓글 쓰기