/// <summary> /// Called when the skin is loaded. /// </summary> public override void OnLoad() { try { LoadResourceManager(); XmlDocument skinDef = new XmlDocument(); skinDef.LoadXml(_currentManager.GetString("SkinDefinition")); XmlElement elm = skinDef.DocumentElement; XmlNode form = elm["Form"]; XmlNode captionNode = form["Caption"]; XmlNode normalButton = captionNode["NormalButton"]; XmlNode smallButton = captionNode["SmallButton"]; // Background _formBorder = new ControlPaintHelper(PaintHelperData.Read(form["Border"], _currentManager, "FormBorder")); _formCaption = new ControlPaintHelper(PaintHelperData.Read(captionNode["Background"], _currentManager, "FormCaption")); // Big Buttons Size imageSize = PaintHelperData.StringToSize(normalButton["IconSize"].InnerText); _formCloseIcon = new ImageStrip(true, imageSize, (Bitmap)_currentManager.GetObject("CloseIcon")); _formRestoreIcon = new ImageStrip(true, imageSize, (Bitmap)_currentManager.GetObject("RestoreIcon")); _formMaximizeIcon = new ImageStrip(true, imageSize, (Bitmap)_currentManager.GetObject("MaximizeIcon")); _formMinimizeIcon = new ImageStrip(true, imageSize, (Bitmap)_currentManager.GetObject("MinimizeIcon")); _formCaptionButton = new ControlPaintHelper(PaintHelperData.Read(normalButton, _currentManager, "FormCaptionButton")); // Small Buttons imageSize = PaintHelperData.StringToSize(smallButton["IconSize"].InnerText); _formCloseIconSmall = new ImageStrip(true, imageSize, (Bitmap)_currentManager.GetObject("CloseIconSmall")); _formRestoreIconSmall = new ImageStrip(true, imageSize, (Bitmap)_currentManager.GetObject("RestoreIconSmall")); _formMaximizeIconSmall = new ImageStrip(true, imageSize, (Bitmap)_currentManager.GetObject("MaximizeIconSmall")); _formMinimizeIconSmall = new ImageStrip(true, imageSize, (Bitmap)_currentManager.GetObject("MinimizeIconSmall")); _formCaptionButtonSmall = new ControlPaintHelper(PaintHelperData.Read(smallButton, _currentManager, "FormCaptionButton")); // General Infos _formActiveTitleColor = PaintHelperData.StringToColor(form["ActiveCaption"].InnerText); _formInactiveTitleColor = PaintHelperData.StringToColor(form["InactiveCaption"].InnerText); _formIsTextCentered = PaintHelperData.StringToBool(form["CenterCaption"].InnerText); } catch (Exception e) { throw new ApplicationException("Invalid SkinDefinition XML", e); } }
/// <summary> /// Called when the skin is loaded. /// </summary> public override void OnLoad() { try { LoadResourceManager(); XmlDocument skinDef = new XmlDocument(); skinDef.LoadXml(_currentManager.GetString("SkinDefinition")); XmlElement elm = skinDef.DocumentElement; XmlNode form = elm["Form"]; XmlNode captionNode = form["Caption"]; XmlNode normalButton = captionNode["NormalButton"]; XmlNode smallButton = captionNode["SmallButton"]; // Background _formBorder = new ControlPaintHelper(PaintHelperData.Read(form["Border"], _currentManager, "FormBorder")); _formCaption = new ControlPaintHelper(PaintHelperData.Read(captionNode["Background"], _currentManager, "FormCaption")); // Big Buttons Size imageSize = PaintHelperData.StringToSize(normalButton["IconSize"].InnerText); _formCloseIcon = new ImageStrip(true, imageSize, (Bitmap)_currentManager.GetObject("CloseIcon")); _formRestoreIcon = new ImageStrip(true, imageSize, (Bitmap)_currentManager.GetObject("RestoreIcon")); _formMaximizeIcon = new ImageStrip(true, imageSize, (Bitmap)_currentManager.GetObject("MaximizeIcon")); _formMinimizeIcon = new ImageStrip(true, imageSize, (Bitmap)_currentManager.GetObject("MinimizeIcon")); _formCaptionButton = new ControlPaintHelper(PaintHelperData.Read(normalButton, _currentManager, "FormCaptionButton")); // Small Buttons imageSize = PaintHelperData.StringToSize(smallButton["IconSize"].InnerText); _formCloseIconSmall = new ImageStrip(true, imageSize, (Bitmap)_currentManager.GetObject("CloseIconSmall")); _formRestoreIconSmall = new ImageStrip(true, imageSize, (Bitmap)_currentManager.GetObject("RestoreIconSmall")); _formMaximizeIconSmall = new ImageStrip(true, imageSize, (Bitmap)_currentManager.GetObject("MaximizeIconSmall")); _formMinimizeIconSmall = new ImageStrip(true, imageSize, (Bitmap)_currentManager.GetObject("MinimizeIconSmall")); _formCaptionButtonSmall = new ControlPaintHelper(PaintHelperData.Read(smallButton, _currentManager, "FormCaptionButton")); // General Infos _formActiveTitleColor = PaintHelperData.StringToColor(form["ActiveCaption"].InnerText); _formInactiveTitleColor = PaintHelperData.StringToColor(form["InactiveCaption"].InnerText); _formIsTextCentered = PaintHelperData.StringToBool(form["CenterCaption"].InnerText); } catch (Exception e) { throw new ApplicationException("Invalid SkinDefinition XML", e); } }
/// <summary> /// Called when the non client area of the form needs to be painted. /// </summary> /// <param name="form">The form which gets drawn.</param> /// <param name="paintData">The paint data to use for drawing.</param> /// <returns><code>true</code> if the original painting should be suppressed, otherwise <code>false</code></returns> public override bool OnNcPaint(Form form, SkinningFormPaintData paintData) { if (form == null) { return(false); } bool isMaximized = form.WindowState == FormWindowState.Maximized; bool isMinimized = form.WindowState == FormWindowState.Minimized; // prepare bounds Rectangle windowBounds = paintData.Bounds; windowBounds.Location = Point.Empty; Rectangle captionBounds = windowBounds; Size borderSize = paintData.Borders; captionBounds.Height = borderSize.Height + paintData.CaptionHeight; Rectangle textBounds = captionBounds; Rectangle iconBounds = captionBounds; iconBounds.Inflate(-borderSize.Width, 0); iconBounds.Y += borderSize.Height; iconBounds.Height -= borderSize.Height; // Draw Caption bool active = paintData.Active; _formCaption.Draw(paintData.Graphics, captionBounds, active ? 0 : 1); // Paint Icon if (paintData.HasMenu && form.Icon != null) { iconBounds.Size = paintData.IconSize; Icon tmpIcon = new Icon(form.Icon, paintData.IconSize); iconBounds.Y = captionBounds.Y + (captionBounds.Height - iconBounds.Height) / 2; paintData.Graphics.DrawIcon(tmpIcon, iconBounds); textBounds.X = iconBounds.Right; iconBounds.Width -= iconBounds.Right; } // Paint Icons foreach (CaptionButtonPaintData data in paintData.CaptionButtons) { ControlPaintHelper painter = paintData.IsSmallCaption ? _formCaptionButtonSmall : _formCaptionButton; // Get Indices for imagestrip int iconIndex; int backgroundIndex; GetButtonData(data, paintData.Active, out iconIndex, out backgroundIndex); // get imageStrip for button icon ImageStrip iconStrip; switch (data.HitTest) { case HitTest.HTCLOSE: iconStrip = paintData.IsSmallCaption ? _formCloseIconSmall : _formCloseIcon; break; case HitTest.HTMAXBUTTON: if (isMaximized) { iconStrip = paintData.IsSmallCaption ? _formRestoreIconSmall : _formRestoreIcon; } else { iconStrip = paintData.IsSmallCaption ? _formMaximizeIconSmall : _formMaximizeIcon; } break; case HitTest.HTMINBUTTON: if (isMinimized) { iconStrip = paintData.IsSmallCaption ? _formRestoreIconSmall : _formRestoreIcon; } else { iconStrip = paintData.IsSmallCaption ? _formMinimizeIconSmall : _formMinimizeIcon; } break; default: continue; } // draw background if (backgroundIndex >= 0) { painter.Draw(paintData.Graphics, data.Bounds, backgroundIndex); } // draw Icon Rectangle b = data.Bounds; b.Y += 1; if (iconIndex >= 0) { iconStrip.Draw(paintData.Graphics, iconIndex, b, Rectangle.Empty, DrawingAlign.Center, DrawingAlign.Center); } // Ensure textbounds textBounds.Width -= data.Bounds.Width; } // draw text if (!string.IsNullOrEmpty(paintData.Text) && !textBounds.IsEmpty) { TextFormatFlags flags = TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis | TextFormatFlags.PreserveGraphicsClipping; if (_formIsTextCentered) { flags = flags | TextFormatFlags.HorizontalCenter; } Font font = paintData.IsSmallCaption ? SystemFonts.SmallCaptionFont : SystemFonts.CaptionFont; TextRenderer.DrawText(paintData.Graphics, paintData.Text, font, textBounds, paintData.Active ? _formActiveTitleColor : _formInactiveTitleColor, flags); } // exclude caption area from painting Region region = paintData.Graphics.Clip; region.Exclude(captionBounds); paintData.Graphics.Clip = region; // Paint borders and corners _formBorder.DrawFrame(paintData.Graphics, windowBounds, paintData.Active ? 0 : 1); paintData.Graphics.ResetClip(); return(true); }