/// <summary> /// Redraws the non client area. /// </summary> /// <param name="invalidateBuffer">if set to <c>true</c> the buffer is invalidated.</param> /// <returns>true if the original painting should be suppressed otherwise false.</returns> protected internal virtual bool OnNcPaint(bool invalidateBuffer) { if (!IsProcessNcArea) { return(false); } bool result = false; try { SkinningFormPaintData paintData = CreatePaintData(); // create painting meta data for caption buttons if (_captionButtons.Count > 0) { paintData.CaptionButtons = new CaptionButtonPaintData[_captionButtons.Count]; for (int i = 0; i < _captionButtons.Count; i++) { CaptionButton button = _captionButtons[i]; CaptionButtonPaintData buttonData = new CaptionButtonPaintData() { BaseData = new PaintDataBase(_basePaintParas._bufferGraphics.Graphics, button.Bounds), Pressed = button.Pressed, Hovered = button.Hovered, Enabled = button.Enabled, HitTest = button.HitTest }; paintData.CaptionButtons[i] = buttonData; } } // paint result = OnNcPaint(paintData); // render buffered graphics if (_basePaintParas._bufferGraphics != null) { _basePaintParas._bufferGraphics.Render(_basePaintParas._g); } } catch (System.Exception) { result = false; } _basePaintParas.Reset(); return(result); }
protected internal override SkinningFormPaintData CreatePaintData() { // Create painting meta data for form SkinningFormPaintData paintData = new SkinningFormPaintData() { BaseData = base.CreatePaintDataBase(), Borders = SkinSystemInfo.BorderSize, CaptionHeight = SkinSystemInfo.CaptionHeight, //CaptionHeight =50, Active = FormIsActive, HasMenu = SkinSystemInfo.IsHasMenu, IconSize = SystemInformation.SmallIconSize, IsSmallCaption = false, Text = SkiningForm.Text }; return(paintData); }
/// <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> protected internal abstract bool OnNcPaint(SkinningFormPaintData paintData);
protected internal override bool OnNcPaint(SkinningFormPaintData paintData) { if (SkiningForm == null) { return(false); } bool isMaximized = SkiningForm.WindowState == FormWindowState.Maximized; bool isMinimized = SkiningForm.WindowState == FormWindowState.Minimized; // prepare bounds Rectangle windowBounds = paintData.BaseData.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; _skinSetting._formCaption.Draw(paintData.BaseData.Graphics, captionBounds, active ? 0 : 1); // Paint Icon if (paintData.HasMenu && SkiningForm.Icon != null) { iconBounds.Size = paintData.IconSize; Icon tmpIcon = new Icon(SkiningForm.Icon, paintData.IconSize); iconBounds.Y = captionBounds.Y + (captionBounds.Height - iconBounds.Height) / 2; paintData.BaseData.Graphics.DrawIcon(tmpIcon, iconBounds); textBounds.X = iconBounds.Right; iconBounds.Width -= iconBounds.Right; } // Paint Icons foreach (CaptionButtonPaintData data in paintData.CaptionButtons) { ControlPaintHelper painter = paintData.IsSmallCaption ? _skinSetting._formCaptionButtonSmall : _skinSetting._formCaptionButton; // Get Indices for imagestrip int iconIndex = 0; int backgroundIndex = 0; FormExtenders.GetButtonData(data, paintData.Active, out iconIndex, out backgroundIndex); // get imageStrip for button icon ImageStrip iconStrip; switch (data.HitTest) { case HitTest.HTCLOSE: iconStrip = paintData.IsSmallCaption ? _skinSetting._formCloseIconSmall : _skinSetting._formCloseIcon; break; case HitTest.HTMAXBUTTON: if (isMaximized) { iconStrip = paintData.IsSmallCaption ? _skinSetting._formRestoreIconSmall : _skinSetting._formRestoreIcon; } else { iconStrip = paintData.IsSmallCaption ? _skinSetting._formMaximizeIconSmall : _skinSetting._formMaximizeIcon; } break; case HitTest.HTMINBUTTON: if (isMinimized) { iconStrip = paintData.IsSmallCaption ? _skinSetting._formRestoreIconSmall : _skinSetting._formRestoreIcon; } else { iconStrip = paintData.IsSmallCaption ? _skinSetting._formMinimizeIconSmall : _skinSetting._formMinimizeIcon; } break; default: continue; } // draw background if (backgroundIndex >= 0) { painter.Draw(paintData.BaseData.Graphics, data.BaseData.Bounds, backgroundIndex); } // draw Icon Rectangle b = data.BaseData.Bounds; b.Y += 1; if (iconIndex >= 0) { iconStrip.Draw(paintData.BaseData.Graphics, iconIndex, b, Rectangle.Empty, DrawingAlign.Center, DrawingAlign.Center); } // Ensure textbounds textBounds.Width -= data.BaseData.Bounds.Width; } // draw text if (!string.IsNullOrEmpty(paintData.Text) && !textBounds.IsEmpty) { TextFormatFlags flags = TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis | TextFormatFlags.PreserveGraphicsClipping; if (_skinSetting._formIsTextCentered) { flags = flags | TextFormatFlags.HorizontalCenter; } Font font = paintData.IsSmallCaption ? SystemFonts.SmallCaptionFont : SystemFonts.CaptionFont; TextRenderer.DrawText(paintData.BaseData.Graphics, paintData.Text, font, textBounds, paintData.Active ? _skinSetting._formActiveTitleColor : _skinSetting._formInactiveTitleColor, flags); } // exclude caption area from painting Region region = paintData.BaseData.Graphics.Clip; region.Exclude(captionBounds); paintData.BaseData.Graphics.Clip = region; // Paint borders and corners _skinSetting._formBorder.DrawFrame(paintData.BaseData.Graphics, windowBounds, paintData.Active ? 0 : 1); paintData.BaseData.Graphics.ResetClip(); return(true); }