/// <summary> /// Draw control border. /// </summary> public void DrawBorder() { if (!Bar.ShowBorders) { return; } var rect = new Rectangle(Bounds.X, Bounds.Y, Bounds.Width - 1, Bounds.Height - 1); PaintUtility.DrawBorder(Graphics, rect, Appearance.AppearanceBorder.CornerShape, Appearance.AppearanceBorder.BorderVisibility, Appearance.AppearanceBorder.BorderLineStyle, Appearance.CornerRadius, Bar.Focused ? Appearance.FocusedBorder : Appearance.NormalBorder, null, null); }
/// <summary> /// Draws Item Border /// </summary> public void DrawItemBorder() { if (!Bar.ShowBorders && Item.ShowBorder == ShowBorder.Inherit || Item.ShowBorder == ShowBorder.NotShow) { return; } switch (State) { case State.Selected: PaintUtility.PaintBorder(Graphics, Bounds, Item.Appearance.SelectedBorder.IsEmpty ? Bar.CurrentAppearance.Item.SelectedBorder : Item.Appearance.SelectedBorder); break; case State.Disabled: PaintUtility.PaintBorder(Graphics, Bounds, Item.Appearance.DisabledBorder.IsEmpty ? Bar.CurrentAppearance.Item.DisabledBorder : Item.Appearance.DisabledBorder); break; case State.Hover: PaintUtility.PaintBorder(Graphics, Bounds, Item.Appearance.HoverBorder.IsEmpty ? Bar.CurrentAppearance.Item.HoverBorder : Item.Appearance.HoverBorder); break; case State.SelectedHover: PaintUtility.PaintBorder(Graphics, Bounds, Item.Appearance.HoverBorder.IsEmpty ? Bar.CurrentAppearance.Item.HoverBorder : Item.Appearance.HoverBorder); break; case State.Normal: PaintUtility.PaintBorder(Graphics, Bounds, Item.Appearance.NormalBorder.IsEmpty ? Bar.CurrentAppearance.Item.NormalBorder : Item.Appearance.NormalBorder); break; case State.Pressed: PaintUtility.PaintBorder(Graphics, Bounds, Item.Appearance.SelectedBorder.IsEmpty ? Bar.CurrentAppearance.Item.SelectedBorder : Item.Appearance.SelectedBorder); break; } }
/// <summary> /// Draws Item Background. /// </summary> public void DrawItemBackGround() { if (Bounds.Height == 0 || Bounds.Width == 0) { return; } switch (State) { case State.Selected: PaintUtility.PaintGradientRectangle(Graphics, Bounds, Item.Appearance.SelectedStyle.IsEmpty ? Bar.CurrentAppearance.Item.SelectedStyle : Item.Appearance.SelectedStyle); break; case State.Disabled: PaintUtility.PaintGradientRectangle(Graphics, Bounds, Item.Appearance.DisabledStyle.IsEmpty ? Bar.CurrentAppearance.Item.DisabledStyle : Item.Appearance.DisabledStyle); break; case State.Hover: PaintUtility.PaintGradientRectangle(Graphics, Bounds, Item.Appearance.HoverStyle.IsEmpty ? Bar.CurrentAppearance.Item.HoverStyle : Item.Appearance.HoverStyle); break; case State.SelectedHover: PaintUtility.PaintGradientRectangle(Graphics, Bounds, Item.Appearance.SelectedHoverStyle.IsEmpty ? Bar.CurrentAppearance.Item.SelectedHoverStyle : Item.Appearance.SelectedHoverStyle); break; case State.Normal: PaintUtility.PaintGradientRectangle(Graphics, Bounds, Item.Appearance.BackStyle.IsEmpty ? Bar.CurrentAppearance.Item.BackStyle : Item.Appearance.BackStyle); break; case State.Pressed: PaintUtility.PaintGradientRectangle(Graphics, Bounds, Item.Appearance.ClickStyle.IsEmpty ? Bar.CurrentAppearance.Item.ClickStyle : Item.Appearance.ClickStyle); break; } }
/// <summary> /// Converts an object into its XML representation. /// </summary> /// <param name="writer">The <see cref="T:System.Xml.XmlWriter" /> stream to which the object is serialized.</param> public void WriteXml(XmlWriter writer) { writer.WriteStartElement("BackStyle"); BackStyle.WriteXml(writer); writer.WriteEndElement(); writer.WriteElementString("NormalBorder", PaintUtility.GetString(NormalBorder)); writer.WriteElementString("DisabledMask", PaintUtility.GetString(DisabledMask)); writer.WriteElementString("FocusedBorder", PaintUtility.GetString(FocusedBorder)); writer.WriteStartElement("AppearanceBorder"); AppearanceBorder.WriteXml(writer); writer.WriteEndElement(); writer.WriteElementString("CornerRadius", CornerRadius.ToString()); }
/// <summary> /// Generates an object from its XML representation. /// </summary> /// <param name="reader">The <see cref="T:System.Xml.XmlReader" /> stream from which the object is deserialized.</param> public void ReadXml(XmlReader reader) { var doc = new XmlDocument(); doc.Load(reader); if (doc.GetElementsByTagName("BackColor1").Count > 0) { BackColor1 = PaintUtility.GetColor(doc.GetElementsByTagName("BackColor1")[0].InnerText); } if (doc.GetElementsByTagName("BackColor2").Count > 0) { BackColor2 = PaintUtility.GetColor(doc.GetElementsByTagName("BackColor2")[0].InnerText); } if (doc.GetElementsByTagName("Gradient").Count > 0) { Gradient = Convert.ToInt32(doc.GetElementsByTagName("Gradient")[0].InnerText); } }
/// <summary> /// Converts an object into its XML representation. /// </summary> /// <param name="writer">The <see cref="T:System.Xml.XmlWriter" /> stream to which the object is serialized.</param> public void WriteXml(XmlWriter writer) { writer.WriteStartElement("BackStyle"); BackStyle.WriteXml(writer); writer.WriteEndElement(); writer.WriteStartElement("ClickStyle"); ClickStyle.WriteXml(writer); writer.WriteEndElement(); writer.WriteStartElement("HoverStyle"); HoverStyle.WriteXml(writer); writer.WriteEndElement(); writer.WriteStartElement("SelectedStyle"); SelectedStyle.WriteXml(writer); writer.WriteEndElement(); writer.WriteStartElement("DisabledStyle"); DisabledStyle.WriteXml(writer); writer.WriteEndElement(); writer.WriteStartElement("SelectedHoverStyle"); SelectedHoverStyle.WriteXml(writer); writer.WriteEndElement(); writer.WriteElementString("NormalBorder", PaintUtility.GetString(NormalBorder)); writer.WriteElementString("HoverBorder", PaintUtility.GetString(HoverBorder)); writer.WriteElementString("NormalForeGround", PaintUtility.GetString(NormalForeGround)); writer.WriteElementString("SelectedBorder", PaintUtility.GetString(SelectedBorder)); writer.WriteElementString("HoverForeGround", PaintUtility.GetString(HoverForeGround)); writer.WriteStartElement("AppearenceText"); AppearenceText.WriteXml(writer); writer.WriteEndElement(); writer.WriteElementString("SelectedForeGround", PaintUtility.GetString(SelectedForeGround)); writer.WriteElementString("DisabledBorder", PaintUtility.GetString(DisabledBorder)); writer.WriteElementString("DisabledForeGround", PaintUtility.GetString(DisabledForeGround)); writer.WriteElementString("Gradient", Gradient.ToString()); }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.Paint" /> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { CreateMemoryBitmap(); //RefreshControl(); Graphics.Clear(BackColor); //Graphics.Clear(Color.Transparent); var bArgs = new DrawBackGroundEventArgs(Graphics, ClientRectangle, CurrentAppearance.Bar, this); OnCustomDrawBackGround(bArgs); if (!bArgs.Handeled) { bArgs.DrawBackground(); bArgs.DrawBorder(); } if (!((items == null) || (items.Count == 0))) { foreach (BarItem barItem in items) { var itemRect = new Rectangle(Padding.Left, barItem.Top, buttonWidth - Padding.Left - Padding.Right, barItem.Height); itemRect.Offset(0, AutoScrollPosition.Y); var args = new DrawItemsEventArgs(Graphics, itemRect, barItem, GetButtonState(barItem), this); OnCustomDrawItems(args); if (args.Handeled) { continue; } args.DrawItemBackGround(); args.DrawItemBorder(); args.DrawIcon(); args.DrawItemText(); } } if (!Enabled) { Graphics.FillRectangle( new SolidBrush(Color.FromArgb((int)(DisableTransparency * 2.55), CurrentAppearance.Bar.DisabledMask)), 0, 0, Width - 1, Height - 1); } PaintUtility.DrawImage(e.Graphics, new Rectangle(0, 0, Width, Height), bmp, (int)(ImageTransparency * 2.55)); }
/// <summary> /// Generates an object from its XML representation. /// </summary> /// <param name="reader">The <see cref="T:System.Xml.XmlReader" /> stream from which the object is deserialized.</param> public void ReadXml(XmlReader reader) { var doc = new XmlDocument(); doc.Load(reader); if (doc.GetElementsByTagName("BackStyle").Count > 0) { var xml = "<ColorPair>" + doc.GetElementsByTagName("BackStyle")[0].InnerXml + "</ColorPair>"; BackStyle.ReadXml(new XmlTextReader(xml, XmlNodeType.Document, null)); } if (doc.GetElementsByTagName("NormalBorder").Count > 0) { NormalBorder = PaintUtility.GetColor(doc.GetElementsByTagName("NormalBorder")[0].InnerText); } if (doc.GetElementsByTagName("DisabledMask").Count > 0) { DisabledMask = PaintUtility.GetColor(doc.GetElementsByTagName("DisabledMask")[0].InnerText); } if (doc.GetElementsByTagName("FocusedBorder").Count > 0) { FocusedBorder = PaintUtility.GetColor(doc.GetElementsByTagName("FocusedBorder")[0].InnerText); } if (doc.GetElementsByTagName("AppearanceBorder").Count > 0) { var xml = "<AppearanceBorder>" + doc.GetElementsByTagName("AppearanceBorder")[0].InnerXml + "</AppearanceBorder>"; AppearanceBorder.ReadXml(new XmlTextReader(xml, XmlNodeType.Document, null)); } if (doc.GetElementsByTagName("CornerRadius").Count > 0) { CornerRadius = Convert.ToInt32(doc.GetElementsByTagName("CornerRadius")[0].InnerText); } }
/// <summary> /// Handles the <see cref="E:CustomDrawItems" /> event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="DrawItemsEventArgs"/> instance containing the event data.</param> private void OnCustomDrawItems(object sender, DrawItemsEventArgs e) { var o = (AppearanceItem)pgrdItem.SelectedObject; var ts = o.AppearenceText.IsEmpty ? ZeroitToxicButton.DEFAULT.Item.AppearenceText : o.AppearenceText; switch (int.Parse(e.Item.Tag.ToString())) { case 1: PaintUtility.PaintGradientRectangle(e.Graphics, e.Bounds, o.DisabledStyle.IsEmpty ? ZeroitToxicButton.DEFAULT.Item.DisabledStyle : o.DisabledStyle); PaintUtility.PaintBorder(e.Graphics, e.Bounds, o.DisabledBorder.IsEmpty ? ZeroitToxicButton.DEFAULT.Item.DisabledBorder : o.DisabledBorder); PaintUtility.DrawString(e.Graphics, e.Bounds, e.Item.Caption, ts, false, o.DisabledForeGround.IsEmpty ? ZeroitToxicButton.DEFAULT.Item.DisabledForeGround : o.DisabledForeGround); break; case 2: PaintUtility.PaintGradientRectangle(e.Graphics, e.Bounds, o.SelectedStyle.IsEmpty ? ZeroitToxicButton.DEFAULT.Item.SelectedStyle : o.SelectedStyle); PaintUtility.PaintBorder(e.Graphics, e.Bounds, o.SelectedBorder.IsEmpty ? ZeroitToxicButton.DEFAULT.Item.SelectedBorder : o.SelectedBorder); PaintUtility.DrawString(e.Graphics, e.Bounds, e.Item.Caption, ts, false, o.SelectedForeGround.IsEmpty ? ZeroitToxicButton.DEFAULT.Item.SelectedForeGround : o.SelectedForeGround); break; case 3: PaintUtility.PaintGradientRectangle(e.Graphics, e.Bounds, o.ClickStyle.IsEmpty ? ZeroitToxicButton.DEFAULT.Item.ClickStyle : o.ClickStyle); PaintUtility.PaintBorder(e.Graphics, e.Bounds, o.SelectedBorder.IsEmpty ? ZeroitToxicButton.DEFAULT.Item.SelectedBorder : o.SelectedBorder); PaintUtility.DrawString(e.Graphics, e.Bounds, e.Item.Caption, ts, false, o.SelectedForeGround.IsEmpty ? ZeroitToxicButton.DEFAULT.Item.SelectedForeGround : o.SelectedForeGround); break; case 4: PaintUtility.PaintGradientRectangle(e.Graphics, e.Bounds, o.HoverStyle.IsEmpty ? ZeroitToxicButton.DEFAULT.Item.HoverStyle : o.HoverStyle); PaintUtility.PaintBorder(e.Graphics, e.Bounds, o.HoverBorder.IsEmpty ? ZeroitToxicButton.DEFAULT.Item.HoverBorder : o.HoverBorder); PaintUtility.DrawString(e.Graphics, e.Bounds, e.Item.Caption, ts, false, o.HoverForeGround.IsEmpty ? ZeroitToxicButton.DEFAULT.Item.HoverForeGround : o.HoverForeGround); break; case 5: PaintUtility.PaintGradientRectangle(e.Graphics, e.Bounds, o.SelectedHoverStyle.IsEmpty ? ZeroitToxicButton.DEFAULT.Item.SelectedHoverStyle : o.SelectedHoverStyle); PaintUtility.PaintBorder(e.Graphics, e.Bounds, o.HoverBorder.IsEmpty ? ZeroitToxicButton.DEFAULT.Item.HoverBorder : o.HoverBorder); PaintUtility.DrawString(e.Graphics, e.Bounds, e.Item.Caption, ts, false, o.HoverForeGround.IsEmpty ? ZeroitToxicButton.DEFAULT.Item.HoverForeGround : o.HoverForeGround); break; default: PaintUtility.PaintGradientRectangle(e.Graphics, e.Bounds, o.BackStyle.IsEmpty ? ZeroitToxicButton.DEFAULT.Item.BackStyle : o.BackStyle); PaintUtility.PaintBorder(e.Graphics, e.Bounds, o.NormalBorder.IsEmpty ? ZeroitToxicButton.DEFAULT.Item.NormalBorder : o.NormalBorder); PaintUtility.DrawString(e.Graphics, e.Bounds, e.Item.Caption, ts, false, o.NormalForeGround.IsEmpty ? ZeroitToxicButton.DEFAULT.Item.NormalForeGround : o.NormalForeGround); break; } e.Handeled = true; }
/// <summary> /// Draw control background. /// </summary> public void DrawBackground() { PaintUtility.DrawBackground(Graphics, Bounds, Appearance.BackStyle.GetBrush(Bounds), Appearance.AppearanceBorder.CornerShape, Appearance.CornerRadius, null); }
/// <summary> /// Draw Caption of <see cref="BarItem" /> /// </summary> public void DrawItemText() { ImageAlignment alignment = Item.ImageAlignment == ItemImageAlignment.Inherit ? Bar.ImageAlignment : ((ImageAlignment)((int)Item.ImageAlignment)); var b = new Rectangle(Bounds.Location, Bounds.Size); var iconSize = Size.Empty; if (Bar.ImageList != null && Item.ImageIndex >= 0 && Item.ImageIndex < Bar.ImageList.Images.Count) { iconSize = Bar.ImageList.ImageSize; } int iW = (!iconSize.IsEmpty && (alignment == ImageAlignment.Left || alignment == ImageAlignment.Right) ? iconSize.Width : 0); int iH = (!iconSize.IsEmpty && (alignment == ImageAlignment.Bottom || alignment == ImageAlignment.Top) ? iconSize.Height : 0); var textRect = new Rectangle(0, 0, Bounds.Width - iW - 1, Bounds.Height - iH - 2); if (alignment == ImageAlignment.Top || alignment == ImageAlignment.Bottom) { textRect.X = b.X; } else if (alignment == ImageAlignment.Left) { textRect.X = b.X + iW; } else { textRect.X = Bounds.X; } if (alignment == ImageAlignment.Bottom || alignment == ImageAlignment.Right) { textRect.Y = b.Y; } else if (alignment == ImageAlignment.Top) { textRect.Y = b.Y + iH; } else if (alignment == ImageAlignment.Left) { textRect.Y = b.Y; } string itemText = Item.Caption; var c = Color.Empty; switch (State) { case State.Selected: c = Item.Appearance.SelectedForeGround.IsEmpty ? Bar.CurrentAppearance.Item.SelectedForeGround : Item.Appearance.SelectedForeGround; break; case State.Disabled: c = Item.Appearance.DisabledForeGround.IsEmpty ? Bar.CurrentAppearance.Item.DisabledForeGround : Item.Appearance.DisabledForeGround; break; case State.Hover: c = Item.Appearance.HoverForeGround.IsEmpty ? Bar.CurrentAppearance.Item.HoverForeGround : Item.Appearance.HoverForeGround; break; case State.SelectedHover: c = Item.Appearance.HoverForeGround.IsEmpty ? Bar.CurrentAppearance.Item.HoverForeGround : Item.Appearance.HoverForeGround; break; case State.Normal: c = Item.Appearance.NormalForeGround.IsEmpty ? Bar.CurrentAppearance.Item.NormalForeGround : Item.Appearance.NormalForeGround; break; case State.Pressed: c = Item.Appearance.SelectedForeGround.IsEmpty ? Bar.CurrentAppearance.Item.SelectedForeGround : Item.Appearance.SelectedForeGround; break; } PaintUtility.DrawString(Graphics, textRect, itemText, Item.Appearance.AppearenceText.IsEmpty ? Bar.CurrentAppearance.Item.AppearenceText : Item.Appearance.AppearenceText, Bar.UseMnemonic, c); }
/// <summary> /// Generates an object from its XML representation. /// </summary> /// <param name="reader">The <see cref="T:System.Xml.XmlReader" /> stream from which the object is deserialized.</param> public void ReadXml(XmlReader reader) { var doc = new XmlDocument(); doc.Load(reader); if (doc.GetElementsByTagName("BackStyle").Count > 0) { var xml = "<ColorPair>" + doc.GetElementsByTagName("BackStyle")[0].InnerXml + "</ColorPair>"; BackStyle.ReadXml(new XmlTextReader(xml, XmlNodeType.Document, null)); } if (doc.GetElementsByTagName("ClickStyle").Count > 0) { var xml = "<ColorPair>" + doc.GetElementsByTagName("ClickStyle")[0].InnerXml + "</ColorPair>"; ClickStyle.ReadXml(new XmlTextReader(xml, XmlNodeType.Document, null)); } if (doc.GetElementsByTagName("HoverStyle").Count > 0) { var xml = "<ColorPair>" + doc.GetElementsByTagName("HoverStyle")[0].InnerXml + "</ColorPair>"; HoverStyle.ReadXml(new XmlTextReader(xml, XmlNodeType.Document, null)); } if (doc.GetElementsByTagName("SelectedStyle").Count > 0) { var xml = "<ColorPair>" + doc.GetElementsByTagName("SelectedStyle")[0].InnerXml + "</ColorPair>"; SelectedStyle.ReadXml(new XmlTextReader(xml, XmlNodeType.Document, null)); } if (doc.GetElementsByTagName("DisabledStyle").Count > 0) { var xml = "<ColorPair>" + doc.GetElementsByTagName("DisabledStyle")[0].InnerXml + "</ColorPair>"; DisabledStyle.ReadXml(new XmlTextReader(xml, XmlNodeType.Document, null)); } if (doc.GetElementsByTagName("SelectedHoverStyle").Count > 0) { var xml = "<ColorPair>" + doc.GetElementsByTagName("SelectedHoverStyle")[0].InnerXml + "</ColorPair>"; SelectedHoverStyle.ReadXml(new XmlTextReader(xml, XmlNodeType.Document, null)); } if (doc.GetElementsByTagName("NormalBorder").Count > 0) { NormalBorder = PaintUtility.GetColor(doc.GetElementsByTagName("NormalBorder")[0].InnerText); } if (doc.GetElementsByTagName("HoverBorder").Count > 0) { HoverBorder = PaintUtility.GetColor(doc.GetElementsByTagName("HoverBorder")[0].InnerText); } if (doc.GetElementsByTagName("SelectedBorder").Count > 0) { SelectedBorder = PaintUtility.GetColor(doc.GetElementsByTagName("SelectedBorder")[0].InnerText); } if (doc.GetElementsByTagName("NormalForeGround").Count > 0) { NormalForeGround = PaintUtility.GetColor(doc.GetElementsByTagName("NormalForeGround")[0].InnerText); } if (doc.GetElementsByTagName("HoverForeGround").Count > 0) { HoverForeGround = PaintUtility.GetColor(doc.GetElementsByTagName("HoverForeGround")[0].InnerText); } if (doc.GetElementsByTagName("AppearenceText").Count > 0) { var xml = "<AppearenceText>" + doc.GetElementsByTagName("AppearenceText")[0].InnerXml + "</AppearenceText>"; AppearenceText.ReadXml(new XmlTextReader(xml, XmlNodeType.Document, null)); } if (doc.GetElementsByTagName("SelectedForeGround").Count > 0) { SelectedForeGround = PaintUtility.GetColor(doc.GetElementsByTagName("SelectedForeGround")[0].InnerText); } if (doc.GetElementsByTagName("DisabledBorder").Count > 0) { DisabledBorder = PaintUtility.GetColor(doc.GetElementsByTagName("DisabledBorder")[0].InnerText); } if (doc.GetElementsByTagName("DisabledForeGround").Count > 0) { DisabledForeGround = PaintUtility.GetColor(doc.GetElementsByTagName("DisabledForeGround")[0].InnerText); } if (doc.GetElementsByTagName("Gradient").Count > 0) { Gradient = Convert.ToInt32(doc.GetElementsByTagName("Gradient")[0].InnerText); } }
/// <summary> /// Converts an object into its XML representation. /// </summary> /// <param name="writer">The <see cref="T:System.Xml.XmlWriter" /> stream to which the object is serialized.</param> public void WriteXml(XmlWriter writer) { writer.WriteElementString("BackColor1", PaintUtility.GetString(BackColor1)); writer.WriteElementString("BackColor2", PaintUtility.GetString(BackColor2)); writer.WriteElementString("Gradient", Gradient.ToString()); }