private void DrawArrow(Graphics g, ToolBarButton btn, Rectangle rect)
{
Point p1 = new Point(rect.X+3, rect.Y+rect.Height/2-2);
Point p2 = new Point(rect.X+rect.Width-3, rect.Y+rect.Height/2-2);
Point p3 = new Point(rect.X+rect.Width/2, rect.Y+rect.Height/2+2);
private bool getrtl()
{
//used SystemInformation.RightAlignedMenus because couldn't
//find any other system property that may be close to RTL
bool isrtl = SystemInformation.RightAlignedMenus;
if (this.RightToLeft == RightToLeft.Yes)
isrtl = true;
if (this.RightToLeft == RightToLeft.No)
isrtl = false;
return isrtl;
}
}
}
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace Iridescent.Windows.Forms
{ /// <summary>
/// Summary description for WToolBar.
/// </summary>
public class RichToolBar : System.Windows.Forms.ToolBar
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private bool rtl = false; //right to left
#region Constructor, initializer, destructor
public RichToolBar()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitForm call
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
// Get if mouse is in DropDownButton.
if(btn.Style == ToolBarButtonStyle.DropDownButton)
{
Rectangle dropDownRect = new Rectangle(buttonRect.X+buttonRect.Width-12,buttonRect.Y,12,buttonRect.Height);
mouseInDropDown = dropDownRect.Contains(mPt);
}
// If button is pressed, replace hot color with pressed color in button rect.
// For DropDownButton, don't draw pressed color for right dropDown section.
if(pressed)
{
if (mouseInDropDown)
DrawBackground(g, System.Drawing.SystemColors.Control, true, buttonRect);
else
DrawBackground(g, Iridescent.Drawing.SystemColors.PressedColor, true, buttonRect);
}
//Handle the special case of Toggle Button
if (btn.Style == ToolBarButtonStyle.ToggleButton)
{
if (btn.Pushed)
DrawBackground(g, Iridescent.Drawing.SystemColors.SelectionColor, true, buttonRect);
if (btn.PartialPush)
DrawBackground(g, Iridescent.Drawing.SystemColors.CheckedColor, true, buttonRect);
}
}
//Split the current rectangle into two
Rectangle imgRect;
Rectangle textRect;
if (this.TextAlign == ToolBarTextAlign.Right)
{
imgRect = new Rectangle(buttonRect.X+3, buttonRect.Y+(buttonRect.Height-this.ImageSize.Height)/2, this.ImageSize.Width, this.ImageSize.Height);
textRect = new Rectangle(buttonRect.X+this.ImageSize.Width+6, buttonRect.Y, buttonRect.Width-this.ImageSize.Width-6, buttonRect.Height);
}
else //if (this.TextAlign == ToolBarTextAlign.Underneath)
{
imgRect = new Rectangle(buttonRect.X+(buttonRect.Width-this.ImageSize.Width)/2, buttonRect.Y+3, this.ImageSize.Width, this.ImageSize.Height);
textRect = new Rectangle(buttonRect.X, buttonRect.Y+this.ImageSize.Height+6, buttonRect.Width, buttonRect.Height-this.ImageSize.Height-6);
}
//if we need to draw the drop down glyph as well
if(btn.Style == ToolBarButtonStyle.DropDownButton)
{
if (this.TextAlign == ToolBarTextAlign.Right)
{
textRect.Width -= 12;
}
else
{
imgRect.X -= 6;
textRect.X -= 6;
}
Rectangle glyphRect = new Rectangle(buttonRect.X+buttonRect.Width-12, buttonRect.Y, 12, buttonRect.Height);
DrawArrow(g,btn, glyphRect);
}
// Draw image for button
DrawImage(g, btn.ImageIndex, pressed, btn.Enabled, imgRect);
// Draw Text
if (btn.Text.Length != 0)
DrawText(g, btn.Text, pressed, btn.Enabled, textRect);
}
using System;
using System.Collections;
using System.Drawing;
using System.Windows.Forms;
namespace Iridescent.Windows.Forms
{
/// <summary>
/// Provides StatusBar
/// </summary>
public class RichStatusBar : System.Windows.Forms.StatusBar
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private bool rtl = false; //right to left
#region Constructor, initializer, destructor
public RichStatusBar()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitForm call
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
//Fill the area with control color
e.Graphics.FillRectangle(SystemBrushes.Control, e.ClipRectangle);
//set anti-alias mode. It looks better that way
//this is called after fill rectangle, because otherwise it leaves artifacts
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
int x = e.ClipRectangle.X;
int y = e.ClipRectangle.Y;
int h = e.ClipRectangle.Height;
int start = 0;
foreach (StatusBarPanel panel in this.Panels)
{
int width = panel.Width;
if(start < e.ClipRectangle.Width)
{
if ((start+width) > e.ClipRectangle.Width)
{
width = e.ClipRectangle.Width - start;
}
Rectangle rect = new Rectangle(start, e.ClipRectangle.Y, width, e.ClipRectangle.Height);
DrawPanel(e.Graphics, rect, panel);
start+= panel.Width;
}
}
}
#endregion
private bool getrtl()
{
//used SystemInformation.RightAlignedMenus because couldn't
//find any other system property that may be close to RTL
bool isrtl = SystemInformation.RightAlignedMenus;
if (this.RightToLeft == RightToLeft.Yes)
isrtl = true;
if (this.RightToLeft == RightToLeft.No)
isrtl = false;
return isrtl;
}
private void DrawPanel (Graphics g, Rectangle rect, StatusBarPanel panel)
{
if (panel.Icon != null)
{
int ih = panel.Icon.Height;
int iw = panel.Icon.Width;
Size ts = g.MeasureString(panel.Text, this.Font).ToSize();
int th = ts.Height;
int tw = ts.Width+2;//just to avoid ellipsis
Rectangle iconRect = new Rectangle(rect.X+4, rect.Y+(rect.Height-panel.Icon.Height)/2, panel.Icon.Width, panel.Icon.Height);
Rectangle textRect = new Rectangle(rect.X+8+iw, rect.Y+(rect.Height-th)/2, tw, th);
int contentWidth = iw+tw+12; //12 = 2(border left) +2(icon margin left) +2(icon margin right) +2 (text margin left) + 2(text margin right) + 2(border right)
if(contentWidth < panel.Width)
{
//is it to be drawn to left?
//then we don't need to shift anything
int margin = 0;
//is it to be drawn to the right
if(((panel.Alignment == HorizontalAlignment.Right)&&(!rtl)) || ((panel.Alignment == HorizontalAlignment.Left)&&(rtl)))
{
margin = rect.Width-contentWidth;
}
//it is to be drawn to the center
if(panel.Alignment == HorizontalAlignment.Center)
{
margin = (rect.Width-contentWidth)/2;
}