[ThreadStatic] private static System.Drawing.Imaging.ImageAttributes t_DisabledImageAttr; // A separate one for each thread, for multi-thread safety without needing locks /// <summary> /// Create a disabled version of the image. /// </summary> /// <param name="image">The image to convert</param> /// <param name="background">The Color of the background behind the image. The background parameter is used to calculate the fill color of the disabled image so that it is always visible against the background.</param> /// <returns></returns> public static Image CreateDisabledImage(Image image, Color background) { if (image == null) { return(null); } Size imgSize = image.Size; if (t_DisabledImageAttr == null) { float[][] arrayJagged = new float[5][]; arrayJagged[0] = new float[5] { 0.2125f, 0.2125f, 0.2125f, 0f, 0f }; arrayJagged[1] = new float[5] { 0.2577f, 0.2577f, 0.2577f, 0f, 0f }; arrayJagged[2] = new float[5] { 0.0361f, 0.0361f, 0.0361f, 0f, 0f }; float[] arraySingle = new float[5]; arraySingle[3] = 1f; arrayJagged[3] = arraySingle; arrayJagged[4] = new float[5] { 0.38f, 0.38f, 0.38f, 0f, 1f }; System.Drawing.Imaging.ColorMatrix matrix = new System.Drawing.Imaging.ColorMatrix(arrayJagged); t_DisabledImageAttr = new System.Drawing.Imaging.ImageAttributes(); t_DisabledImageAttr.ClearColorKey(); t_DisabledImageAttr.SetColorMatrix(matrix); } Bitmap bitmap = new Bitmap(image.Width, image.Height); using (Graphics g = Graphics.FromImage(bitmap)) { g.DrawImage(image, new Rectangle(0, 0, imgSize.Width, imgSize.Height), 0, 0, imgSize.Width, imgSize.Height, GraphicsUnit.Pixel, t_DisabledImageAttr); } return(bitmap); }
private void DrawForegroundFromButton(PaintEventArgs pevent) { if (imageButton == null) { imageButton = new Button(); imageButton.Parent = new TransparentControl(); imageButton.SuspendLayout(); imageButton.BackColor = Color.Transparent; imageButton.FlatAppearance.BorderSize = 0; imageButton.FlatStyle = FlatStyle.Flat; } else { imageButton.SuspendLayout(); } imageButton.AutoEllipsis = AutoEllipsis; if (Enabled) { imageButton.ForeColor = ForeColor; } else { imageButton.ForeColor = Color.FromArgb((3 * ForeColor.R + backColor.R) >> 2, (3 * ForeColor.G + backColor.G) >> 2, (3 * ForeColor.B + backColor.B) >> 2); } imageButton.Font = Font; imageButton.RightToLeft = RightToLeft; if (imageButton.Image != Image && imageButton.Image != null) { imageButton.Image.Dispose(); } if (Image != null) { imageButton.Image = Image; if (!Enabled) { Size size = Image.Size; float[][] newColorMatrix = new float[5][]; newColorMatrix[0] = new float[] { 0.2125f, 0.2125f, 0.2125f, 0f, 0f }; newColorMatrix[1] = new float[] { 0.2577f, 0.2577f, 0.2577f, 0f, 0f }; newColorMatrix[2] = new float[] { 0.0361f, 0.0361f, 0.0361f, 0f, 0f }; float[] arr = new float[5]; arr[3] = 1f; newColorMatrix[3] = arr; newColorMatrix[4] = new float[] { 0.38f, 0.38f, 0.38f, 0f, 1f }; System.Drawing.Imaging.ColorMatrix matrix = new System.Drawing.Imaging.ColorMatrix(newColorMatrix); System.Drawing.Imaging.ImageAttributes disabledImageAttr = new System.Drawing.Imaging.ImageAttributes(); disabledImageAttr.ClearColorKey(); disabledImageAttr.SetColorMatrix(matrix); imageButton.Image = new Bitmap(Image.Width, Image.Height); using (Graphics gr = Graphics.FromImage(imageButton.Image)) { gr.DrawImage(Image, new Rectangle(0, 0, size.Width, size.Height), 0, 0, size.Width, size.Height, GraphicsUnit.Pixel, disabledImageAttr); } } } imageButton.ImageAlign = ImageAlign; imageButton.ImageIndex = ImageIndex; imageButton.ImageKey = ImageKey; imageButton.ImageList = ImageList; imageButton.Padding = Padding; imageButton.Size = Size; imageButton.Text = Text; imageButton.TextAlign = TextAlign; imageButton.TextImageRelation = TextImageRelation; imageButton.UseCompatibleTextRendering = UseCompatibleTextRendering; imageButton.UseMnemonic = UseMnemonic; imageButton.ResumeLayout(); InvokePaint(imageButton, pevent); }
private void DrawForegroundFromButton(PaintEventArgs pevent) { if (_imageButton == null) { _imageButton = new Button(); _imageButton.Parent = new TransparentControl(); _imageButton.SuspendLayout(); _imageButton.BackColor = Color.Transparent; _imageButton.FlatAppearance.BorderSize = 0; _imageButton.FlatStyle = FlatStyle.Flat; } else { _imageButton.SuspendLayout(); } _imageButton.AutoEllipsis = AutoEllipsis; if (Enabled) { _imageButton.ForeColor = ForeColor; } else { _imageButton.ForeColor = Color.FromArgb((3 * ForeColor.R + _backColor.R) >> 2, (3 * ForeColor.G + _backColor.G) >> 2, (3 * ForeColor.B + _backColor.B) >> 2); } _imageButton.Font = Font; _imageButton.RightToLeft = RightToLeft; _imageButton.Image = Image; if (Image != null && !Enabled) { Size size = Image.Size; float[][] newColorMatrix = new float[5][]; newColorMatrix[0] = new float[] { 0.2125f, 0.2125f, 0.2125f, 0f, 0f }; newColorMatrix[1] = new float[] { 0.2577f, 0.2577f, 0.2577f, 0f, 0f }; newColorMatrix[2] = new float[] { 0.0361f, 0.0361f, 0.0361f, 0f, 0f }; float[] arr = new float[5]; arr[3] = 1f; newColorMatrix[3] = arr; newColorMatrix[4] = new float[] { 0.38f, 0.38f, 0.38f, 0f, 1f }; System.Drawing.Imaging.ColorMatrix matrix = new System.Drawing.Imaging.ColorMatrix(newColorMatrix); System.Drawing.Imaging.ImageAttributes disabledImageAttr = new System.Drawing.Imaging.ImageAttributes(); disabledImageAttr.ClearColorKey(); disabledImageAttr.SetColorMatrix(matrix); _imageButton.Image = new Bitmap(Image.Width, Image.Height); using (Graphics gr = Graphics.FromImage(_imageButton.Image)) { gr.DrawImage(Image, new Rectangle(0, 0, size.Width, size.Height), 0, 0, size.Width, size.Height, GraphicsUnit.Pixel, disabledImageAttr); } } _imageButton.ImageAlign = ImageAlign; _imageButton.ImageIndex = ImageIndex; _imageButton.ImageKey = ImageKey; _imageButton.ImageList = ImageList; _imageButton.Padding = Padding; _imageButton.Size = Size; _imageButton.Text = Text; _imageButton.TextAlign = TextAlign; _imageButton.TextImageRelation = TextImageRelation; _imageButton.UseCompatibleTextRendering = UseCompatibleTextRendering; _imageButton.UseMnemonic = UseMnemonic; _imageButton.ResumeLayout(); InvokePaint(_imageButton, pevent); if (_imageButton.Image != null && _imageButton.Image != Image) { _imageButton.Image.Dispose(); _imageButton.Image = null; } }
internal static void PaintSystemButton(System.Drawing.Graphics g, SystemButton btn, Rectangle r, bool MouseDown, bool MouseOver, bool Disabled) { // Draw state if any if (MouseDown) { g.FillRectangle(new SolidBrush(ColorFunctions.PressedBackColor(g)), r); NativeFunctions.DrawRectangle(g, SystemPens.Highlight, r); } else if (MouseOver) { g.FillRectangle(new SolidBrush(ColorFunctions.HoverBackColor(g)), r); NativeFunctions.DrawRectangle(g, SystemPens.Highlight, r); } Bitmap bmp = new Bitmap(r.Width, r.Height, g); Graphics gBmp = Graphics.FromImage(bmp); Rectangle rBtn = new Rectangle(0, 0, r.Width, r.Height); rBtn.Inflate(0, -1); Rectangle rClip = rBtn; rClip.Inflate(-1, -1); using (SolidBrush brush = new SolidBrush(SystemColors.Control)) gBmp.FillRectangle(brush, 0, 0, r.Width, r.Height); gBmp.SetClip(rClip); System.Windows.Forms.ControlPaint.DrawCaptionButton(gBmp, rBtn, (System.Windows.Forms.CaptionButton)btn, System.Windows.Forms.ButtonState.Flat); gBmp.ResetClip(); gBmp.Dispose(); bmp.MakeTransparent(SystemColors.Control); if (Disabled) { float[][] array = new float[5][]; array[0] = new float[5] { 0, 0, 0, 0, 0 }; array[1] = new float[5] { 0, 0, 0, 0, 0 }; array[2] = new float[5] { 0, 0, 0, 0, 0 }; array[3] = new float[5] { .5f, .5f, .5f, .5f, 0 }; array[4] = new float[5] { 0, 0, 0, 0, 0 }; System.Drawing.Imaging.ColorMatrix grayMatrix = new System.Drawing.Imaging.ColorMatrix(array); System.Drawing.Imaging.ImageAttributes disabledImageAttr = new System.Drawing.Imaging.ImageAttributes(); disabledImageAttr.ClearColorKey(); disabledImageAttr.SetColorMatrix(grayMatrix); g.DrawImage(bmp, r, 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, disabledImageAttr); } else { if (MouseDown) r.Offset(1, 1); g.DrawImageUnscaled(bmp, r); } }
/*public override void InternalClick(System.Windows.Forms.MouseButtons mb, System.Drawing.Point mpos) { if(m_Enabled && !this.DesignMode) { if(m_MenuVisibility==eMenuVisibility.VisibleIfRecentlyUsed && !m_RecentlyUsed && this.IsOnMenu) { // Propagate to the top m_RecentlyUsed=true; BaseItem objItem=this.Parent; while(objItem!=null) { IPersonalizedMenuItem ipm=objItem as IPersonalizedMenuItem; if(ipm!=null) ipm.RecentlyUsed=true; objItem=objItem.Parent; } } } // Since base item does not auto-collapse when clicked if it has subitems and it is on // pop-up we need to handle that here and check did user click on expand part of this button // and if they did not we need to raise click event and collapse the item. if(!this.IsOnMenu && (this.SubItemsCount>0 || this.PopupType==ePopupType.Container) && this.ShowSubItems && m_HotSubItem==null && !this.DesignMode && !this.IsOnMenuBar) { Rectangle r=new Rectangle(m_SubItemsRect.X,m_SubItemsRect.Y,m_SubItemsRect.Width,m_SubItemsRect.Height); r.Offset(m_Rect.X,m_Rect.Y); System.Windows.Forms.Control objCtrl=this.ContainerControl as System.Windows.Forms.Control; if(objCtrl==null) { base.InternalClick(mb,mpos); return; } Point p=objCtrl.PointToClient(mpos); objCtrl=null; if(!r.Contains(p)) { CollapseAll(this); RaiseClick(); } } else base.InternalClick(mb,mpos); }*/ // private void CreateDisabledImage() // { // if(m_Image==null && m_ImageIndex<0 && m_Icon==null) // return; // if(m_DisabledImage!=null) // m_DisabledImage.Dispose(); // m_DisabledImage=null; // // CompositeImage defaultImage=GetImage(ImageState.Default); // // if(defaultImage==null) // return; // if(!defaultImage.IsIcon && defaultImage.Image!=null && defaultImage.Image is Bitmap) // { // m_DisabledImage=BarFunctions.CreateDisabledBitmap((Bitmap)defaultImage.Image); // } // } private void CreateDisabledImage() { if (m_Image == null && m_ImageIndex < 0 && m_Icon == null) return; if (m_DisabledImage != null) m_DisabledImage.Dispose(); m_DisabledImage = null; if (m_DisabledIcon != null) m_DisabledIcon.Dispose(); m_DisabledIcon = null; CompositeImage defaultImage = GetImage(ImageState.Default, Color.Black); if (defaultImage == null) return; if (this.GetOwner() is IOwner && ((IOwner)this.GetOwner()).DisabledImagesGrayScale) { if (defaultImage.IsIcon) { m_DisabledIcon = BarFunctions.CreateDisabledIcon(defaultImage.Icon); } else { m_DisabledImage = ImageHelper.CreateGrayScaleImage(defaultImage.Image as Bitmap); } } if (m_DisabledIcon != null || m_DisabledImage != null) return; // Use old algorithm if first one failed... System.Drawing.Imaging.PixelFormat pixelFormat = System.Drawing.Imaging.PixelFormat.Format32bppArgb; if (!defaultImage.IsIcon && defaultImage.Image != null) pixelFormat = defaultImage.Image.PixelFormat; if (pixelFormat == System.Drawing.Imaging.PixelFormat.Format1bppIndexed || pixelFormat == System.Drawing.Imaging.PixelFormat.Format4bppIndexed || pixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed) pixelFormat = System.Drawing.Imaging.PixelFormat.Format32bppArgb; Bitmap bmp = new Bitmap(defaultImage.Width, defaultImage.Height, pixelFormat); m_DisabledImage = new Bitmap(defaultImage.Width, defaultImage.Height, pixelFormat); Graphics g2 = Graphics.FromImage(bmp); using (SolidBrush brush = new SolidBrush(System.Drawing.Color.White)) g2.FillRectangle(brush, 0, 0, defaultImage.Width, defaultImage.Height); //g2.DrawImage(defaultImage,0,0,defaultImage.Width,defaultImage.Height); defaultImage.DrawImage(g2, new Rectangle(0, 0, defaultImage.Width, defaultImage.Height)); g2.Dispose(); g2 = Graphics.FromImage(m_DisabledImage); bmp.MakeTransparent(System.Drawing.Color.White); eDotNetBarStyle effectiveStyle = EffectiveStyle; if ((effectiveStyle == eDotNetBarStyle.OfficeXP || effectiveStyle == eDotNetBarStyle.Office2003 || effectiveStyle == eDotNetBarStyle.VS2005 || BarFunctions.IsOffice2007Style(effectiveStyle)) && NativeFunctions.ColorDepth >= 8) { float[][] array = new float[5][]; array[0] = new float[5] { 0, 0, 0, 0, 0 }; array[1] = new float[5] { 0, 0, 0, 0, 0 }; array[2] = new float[5] { 0, 0, 0, 0, 0 }; array[3] = new float[5] { .5f, .5f, .5f, .5f, 0 }; array[4] = new float[5] { 0, 0, 0, 0, 0 }; System.Drawing.Imaging.ColorMatrix grayMatrix = new System.Drawing.Imaging.ColorMatrix(array); System.Drawing.Imaging.ImageAttributes disabledImageAttr = new System.Drawing.Imaging.ImageAttributes(); disabledImageAttr.ClearColorKey(); disabledImageAttr.SetColorMatrix(grayMatrix); g2.DrawImage(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, disabledImageAttr); } else System.Windows.Forms.ControlPaint.DrawImageDisabled(g2, bmp, 0, 0, ColorFunctions.MenuBackColor(g2)); // Clean up g2.Dispose(); g2 = null; bmp.Dispose(); bmp = null; defaultImage.Dispose(); }
private void PaintDotNet(ItemPaintArgs pa) { bool bIsOnMenu = pa.IsOnMenu; bool bIsOnMenuBar = pa.IsOnMenuBar; bool bThemed = this.IsThemed; if (!bIsOnMenu && !bIsOnMenuBar && bThemed) { ThemedButtonItemPainter.PaintButton(this, pa); return; } bool mouseOver = m_MouseOver; if (bIsOnMenu && this.Expanded && pa.ContainerControl != null && pa.ContainerControl.Parent != null) { if (!pa.ContainerControl.Parent.Bounds.Contains(System.Windows.Forms.Control.MousePosition)) mouseOver = true; } System.Drawing.Graphics g = pa.Graphics; Rectangle rect = Rectangle.Empty; Rectangle itemRect = new Rectangle(m_Rect.X, m_Rect.Y, m_Rect.Width, m_Rect.Height); Color textColor = System.Drawing.Color.Empty; if (mouseOver && !m_HotForeColor.IsEmpty) textColor = m_HotForeColor; else if (!m_ForeColor.IsEmpty) textColor = m_ForeColor; else if (mouseOver /*&& m_Checked*/ && !m_Expanded && /*!bIsOnMenu &&*/ m_HotTrackingStyle != eHotTrackingStyle.Image) textColor = pa.Colors.ItemHotText; else if (m_Expanded) textColor = pa.Colors.ItemExpandedText; else { if (bThemed && bIsOnMenuBar && pa.Colors.ItemText == SystemColors.ControlText) textColor = SystemColors.MenuText; else textColor = pa.Colors.ItemText; } Font objFont = null; eTextFormat objStringFormat = pa.ButtonStringFormat; CompositeImage objImage = GetImage(); System.Drawing.Size imageSize = System.Drawing.Size.Empty; if (m_Font != null) objFont = m_Font; else objFont = GetFont(pa, false); // Calculate image position if (objImage != null) { imageSize = this.ImageSize;// objImage.Size; if (!bIsOnMenu && (m_ImagePosition == eImagePosition.Top || m_ImagePosition == eImagePosition.Bottom)) rect = new Rectangle(m_ImageDrawRect.X, m_ImageDrawRect.Y, itemRect.Width, m_ImageDrawRect.Height); else rect = new Rectangle(m_ImageDrawRect.X, m_ImageDrawRect.Y, m_ImageDrawRect.Width, m_ImageDrawRect.Height); rect.Offset(itemRect.Left, itemRect.Top); //if(m_ButtonType==eButtonType.StateButton) // rect.Offset(STATEBUTTON_SPACING+(m_ImageSize.Width-STATEBUTTON_SPACING)/2+(rect.Width-m_Image.Width*2)/2,(rect.Height-m_Image.Height)/2); //else rect.Offset((rect.Width - imageSize.Width) / 2, (rect.Height - imageSize.Height) / 2); rect.Width = imageSize.Width; rect.Height = imageSize.Height; } if (bIsOnMenu) { // Draw side bar if (this.MenuVisibility == eMenuVisibility.VisibleIfRecentlyUsed && !this.RecentlyUsed) { if (!pa.Colors.MenuUnusedSide2.IsEmpty) { System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(new Rectangle(m_Rect.Left, m_Rect.Top, m_ImageDrawRect.Right, m_Rect.Height), pa.Colors.MenuUnusedSide, pa.Colors.MenuUnusedSide2, pa.Colors.MenuUnusedSideGradientAngle); g.FillRectangle(gradient, m_Rect.Left, m_Rect.Top, m_ImageDrawRect.Right, m_Rect.Height); gradient.Dispose(); } else { using (SolidBrush mybrush = new SolidBrush(pa.Colors.MenuUnusedSide/*ColorFunctions.SideRecentlyBackColor(g)*/)) g.FillRectangle(mybrush, m_Rect.Left, m_Rect.Top, m_ImageDrawRect.Right, m_Rect.Height); } } else { if (!pa.Colors.MenuSide2.IsEmpty) { System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(new Rectangle(m_Rect.Left, m_Rect.Top, m_ImageDrawRect.Right, m_Rect.Height), pa.Colors.MenuSide, pa.Colors.MenuSide2, pa.Colors.MenuSideGradientAngle); g.FillRectangle(gradient, m_Rect.Left, m_Rect.Top, m_ImageDrawRect.Right, m_Rect.Height); gradient.Dispose(); } else { using (SolidBrush mybrush = new SolidBrush(pa.Colors.MenuSide)) g.FillRectangle(mybrush, m_Rect.Left, m_Rect.Top, m_ImageDrawRect.Right, m_Rect.Height); } } // Draw Background of the item //using(SolidBrush mybrush=new SolidBrush(pa.Colors.MenuBackground)) // g.FillRectangle(mybrush,m_Rect.Left+m_ImageDrawRect.Right,m_Rect.Top,m_Rect.Width-m_ImageDrawRect.Right,m_Rect.Height); } else { // Draw button background //if(bIsOnMenuBar) // g.FillRectangle(SystemBrushes.Control,m_Rect); //else // g.FillRectangle(new SolidBrush(ColorFunctions.ToolMenuFocusBackColor(g)),m_Rect); if (!pa.Colors.ItemBackground.IsEmpty) { if (pa.Colors.ItemBackground2.IsEmpty) { using (SolidBrush mybrush = new SolidBrush(pa.Colors.ItemBackground)) g.FillRectangle(mybrush, m_Rect); } else { using (System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(this.DisplayRectangle, pa.Colors.ItemBackground, pa.Colors.ItemBackground2, pa.Colors.ItemBackgroundGradientAngle)) g.FillRectangle(gradient, this.DisplayRectangle); } } else if (!GetEnabled(pa.ContainerControl) && !pa.Colors.ItemDisabledBackground.IsEmpty) { using (SolidBrush mybrush = new SolidBrush(pa.Colors.ItemDisabledBackground)) g.FillRectangle(mybrush, m_Rect); } } if (GetEnabled(pa.ContainerControl) || this.DesignMode) { if (m_Expanded && !bIsOnMenu) { // DotNet Style if (pa.Colors.ItemExpandedBackground2.IsEmpty) { Rectangle rBack = new Rectangle(itemRect.Left, itemRect.Top, itemRect.Width, itemRect.Height); if (pa.Colors.ItemExpandedShadow.IsEmpty) rBack.Width -= 2; using (SolidBrush mybrush = new SolidBrush(pa.Colors.ItemExpandedBackground)) g.FillRectangle(mybrush, rBack); } else { System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(new Rectangle(itemRect.Left, itemRect.Top, itemRect.Width - 2, itemRect.Height), pa.Colors.ItemExpandedBackground, pa.Colors.ItemExpandedBackground2, pa.Colors.ItemExpandedBackgroundGradientAngle); Rectangle rBack = new Rectangle(itemRect.Left, itemRect.Top, itemRect.Width, itemRect.Height); if (pa.Colors.ItemExpandedShadow.IsEmpty) rBack.Width -= 2; g.FillRectangle(gradient, rBack); gradient.Dispose(); } Point[] p; if (m_Orientation == eOrientation.Horizontal && this.PopupSide == ePopupSide.Default) p = new Point[4]; else p = new Point[5]; p[0].X = itemRect.Left; p[0].Y = itemRect.Top + itemRect.Height - 1; p[1].X = itemRect.Left; p[1].Y = itemRect.Top; if (m_Orientation == eOrientation.Horizontal /*&& !pa.Colors.ItemExpandedShadow.IsEmpty*/) p[2].X = itemRect.Left + itemRect.Width - 3; else p[2].X = itemRect.Left + itemRect.Width - 1; p[2].Y = itemRect.Top; if (m_Orientation == eOrientation.Horizontal /*&& !pa.Colors.ItemExpandedShadow.IsEmpty*/) p[3].X = itemRect.Left + itemRect.Width - 3; else p[3].X = itemRect.Left + itemRect.Width - 1; p[3].Y = itemRect.Top + itemRect.Height - 1; if (m_Orientation == eOrientation.Vertical || this.PopupSide != ePopupSide.Default) { p[4].X = itemRect.Left; p[4].Y = itemRect.Top + itemRect.Height - 1; } if (!pa.Colors.ItemExpandedBorder.IsEmpty) { using (Pen mypen = new Pen(pa.Colors.ItemExpandedBorder, 1)) g.DrawLines(mypen, p); } // Draw the shadow if (!pa.Colors.ItemExpandedShadow.IsEmpty && m_Orientation == eOrientation.Horizontal) { using (SolidBrush shadow = new SolidBrush(pa.Colors.ItemExpandedShadow)) g.FillRectangle(shadow, itemRect.Left + itemRect.Width - 2, itemRect.Top + 2, 2, itemRect.Height - 2); // TODO: ADD GRADIENT SHADOW } } if ((mouseOver && m_HotTrackingStyle != eHotTrackingStyle.None) || m_Expanded && !bIsOnMenu) { // Draw Mouse over marker if (!m_Expanded || bIsOnMenu) { Rectangle r = itemRect; if (bIsOnMenu) r = new Rectangle(itemRect.Left + 1, itemRect.Top, itemRect.Width - 2, itemRect.Height); if (this.DesignMode && this.Focused) { //g.FillRectangle(new SolidBrush(ColorFunctions.MenuBackColor(g)),r); r = m_Rect; r.Inflate(-1, -1); DesignTime.DrawDesignTimeSelection(g, r, pa.Colors.ItemDesignTimeBorder); } else { if (m_MouseDown) { if (m_HotTrackingStyle == eHotTrackingStyle.Image) { r = rect; r.Inflate(2, 2); } if (pa.Colors.ItemPressedBackground2.IsEmpty) { using (SolidBrush mybrush = new SolidBrush(pa.Colors.ItemPressedBackground/*ColorFunctions.PressedBackColor(g)*/)) g.FillRectangle(mybrush, r); } else { System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemPressedBackground, pa.Colors.ItemPressedBackground2, pa.Colors.ItemPressedBackgroundGradientAngle); g.FillRectangle(gradient, r); gradient.Dispose(); } using (Pen mypen = new Pen(pa.Colors.ItemPressedBorder, 1)) NativeFunctions.DrawRectangle(g, mypen, r); } else if (m_HotTrackingStyle == eHotTrackingStyle.Image && !rect.IsEmpty) { Rectangle rImage = rect; rImage.Inflate(2, 2); if (!pa.Colors.ItemHotBackground2.IsEmpty) { System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(rImage, pa.Colors.ItemHotBackground, pa.Colors.ItemHotBackground2, pa.Colors.ItemHotBackgroundGradientAngle); g.FillRectangle(gradient, rImage); gradient.Dispose(); } else { using (SolidBrush mybrush = new SolidBrush(pa.Colors.ItemHotBackground/*ColorFunctions.HoverBackColor(g)*/)) g.FillRectangle(mybrush, rImage); } using (Pen mypen = new Pen(pa.Colors.ItemHotBorder, 1)) NativeFunctions.DrawRectangle(g, mypen, rImage); } else { if (!pa.Colors.ItemCheckedBackground2.IsEmpty && m_Checked) { System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemCheckedBackground2, pa.Colors.ItemCheckedBackground, pa.Colors.ItemCheckedBackgroundGradientAngle); g.FillRectangle(gradient, r); gradient.Dispose(); } else { if (!pa.Colors.ItemHotBackground2.IsEmpty) { System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemHotBackground, pa.Colors.ItemHotBackground2, pa.Colors.ItemHotBackgroundGradientAngle); g.FillRectangle(gradient, r); gradient.Dispose(); } else { using (SolidBrush mybrush = new SolidBrush(pa.Colors.ItemHotBackground)) g.FillRectangle(mybrush, r); } } using (Pen mypen = new Pen(pa.Colors.ItemHotBorder, 1)) NativeFunctions.DrawRectangle(g, mypen, r); } } // TODO: Beta 2 Hack for DrawRectangle Possible bug, need to verify //r.Width-=1; //r.Height-=1; //g.DrawRectangle(SystemPens.Highlight,r); } // Image needs shadow when it has focus if (objImage != null && m_ButtonStyle != eButtonStyle.TextOnlyAlways) { // We needed the image to stay "up" when button is expanded too so we removed the checking here //if(m_MouseDown || (m_Expanded && !bIsOnMenu) || m_Checked && !this.IsOnCustomizeMenu && !this.IsOnCustomizeDialog) if (m_MouseDown || m_Checked && !this.IsOnCustomizeMenu && !this.IsOnCustomizeDialog) { objImage.DrawImage(g, rect);// g.DrawImage(objImage,rect);//,0,0,imageSize.Width,imageSize.Height,System.Drawing.GraphicsUnit.Pixel); } else { if (NativeFunctions.ColorDepth >= 16 && EffectiveStyle != eDotNetBarStyle.Office2003) { float[][] array = new float[5][]; array[0] = new float[5] { 0, 0, 0, 0, 0 }; array[1] = new float[5] { 0, 0, 0, 0, 0 }; array[2] = new float[5] { 0, 0, 0, 0, 0 }; array[3] = new float[5] { .5f, .5f, .5f, .5f, 0 }; array[4] = new float[5] { 0, 0, 0, 0, 0 }; System.Drawing.Imaging.ColorMatrix grayMatrix = new System.Drawing.Imaging.ColorMatrix(array); System.Drawing.Imaging.ImageAttributes disabledImageAttr = new System.Drawing.Imaging.ImageAttributes(); disabledImageAttr.ClearColorKey(); disabledImageAttr.SetColorMatrix(grayMatrix); rect.Offset(1, 1); //g.DrawImage(objImage,rect,0,0,objImage.Width,objImage.Height,GraphicsUnit.Pixel,disabledImageAttr); objImage.DrawImage(g, rect, 0, 0, objImage.Width, objImage.Height, GraphicsUnit.Pixel, disabledImageAttr); rect.Offset(-2, -2); //g.DrawImage(objImage,rect); objImage.DrawImage(g, rect); } else { if (EffectiveStyle == eDotNetBarStyle.OfficeXP) rect.Offset(-1, -1); //g.DrawImage(objImage,rect); objImage.DrawImage(g, rect); } } } if (bIsOnMenu && this.IsOnCustomizeMenu && m_Visible && !this.SystemItem) { // Draw check box if this item is visible Rectangle r = new Rectangle(m_Rect.Left, m_Rect.Top, m_Rect.Height, m_Rect.Height); r.Inflate(-1, -1); //Color clr=g.GetNearestColor(Color.FromArgb(45,SystemColors.Highlight)); Color clr = pa.Colors.ItemCheckedBackground/*ColorFunctions.CheckBoxBackColor(g)*/; if (mouseOver && !pa.Colors.ItemHotBackground2.IsEmpty) { System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemHotBackground, pa.Colors.ItemHotBackground2, pa.Colors.ItemHotBackgroundGradientAngle); g.FillRectangle(gradient, r); gradient.Dispose(); } else { if (mouseOver) clr = pa.Colors.ItemHotBackground; if (!pa.Colors.ItemCheckedBackground2.IsEmpty && !mouseOver) { System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemCheckedBackground, pa.Colors.ItemCheckedBackground2, pa.Colors.ItemCheckedBackgroundGradientAngle); g.FillRectangle(gradient, r); gradient.Dispose(); } else { SolidBrush objBrush = new SolidBrush(clr); g.FillRectangle(objBrush, r); objBrush.Dispose(); } } } } else { if (objImage != null && m_ButtonStyle != eButtonStyle.TextOnlyAlways) { if (!m_Checked || this.IsOnCustomizeMenu) { if (m_HotTrackingStyle != eHotTrackingStyle.Color) { objImage.DrawImage(g, rect); } else { // Draw gray-scale image for this hover style... float[][] array = new float[5][]; array[0] = new float[5] { 0.2125f, 0.2125f, 0.2125f, 0, 0 }; array[1] = new float[5] { 0.5f, 0.5f, 0.5f, 0, 0 }; array[2] = new float[5] { 0.0361f, 0.0361f, 0.0361f, 0, 0 }; array[3] = new float[5] { 0, 0, 0, 1, 0 }; array[4] = new float[5] { 0.2f, 0.2f, 0.2f, 0, 1 }; System.Drawing.Imaging.ColorMatrix grayMatrix = new System.Drawing.Imaging.ColorMatrix(array); System.Drawing.Imaging.ImageAttributes att = new System.Drawing.Imaging.ImageAttributes(); att.SetColorMatrix(grayMatrix); //g.DrawImage(objImage,rect,0,0,objImage.Width,objImage.Height,GraphicsUnit.Pixel,att); objImage.DrawImage(g, rect, 0, 0, objImage.Width, objImage.Height, GraphicsUnit.Pixel, att); } } else { if ((m_Checked && bIsOnMenu || !this.Expanded) && !this.IsOnCustomizeDialog) { Rectangle r; if (bIsOnMenu) r = new Rectangle(m_Rect.X + 1, m_Rect.Y, m_ImageDrawRect.Width - 2, m_Rect.Height); else if (m_HotTrackingStyle == eHotTrackingStyle.Image) { r = rect; r.Inflate(2, 2); } else r = m_Rect; if (bIsOnMenu) r.Inflate(-1, -1); Color clr; if (mouseOver && m_HotTrackingStyle != eHotTrackingStyle.None) { if (m_Checked && !pa.Colors.ItemCheckedBackground2.IsEmpty) { System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemCheckedBackground2, pa.Colors.ItemCheckedBackground, pa.Colors.ItemCheckedBackgroundGradientAngle); g.FillRectangle(gradient, r); gradient.Dispose(); clr = System.Drawing.Color.Empty; } else { if (!pa.Colors.ItemHotBackground2.IsEmpty) { System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemHotBackground, pa.Colors.ItemHotBackground2, pa.Colors.ItemHotBackgroundGradientAngle); g.FillRectangle(gradient, r); gradient.Dispose(); clr = System.Drawing.Color.Empty; } else clr = System.Windows.Forms.ControlPaint.Dark(pa.Colors.ItemHotBackground); } } else { if (!pa.Colors.ItemCheckedBackground2.IsEmpty) { System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemCheckedBackground, pa.Colors.ItemCheckedBackground2, pa.Colors.ItemCheckedBackgroundGradientAngle); g.FillRectangle(gradient, r); gradient.Dispose(); clr = System.Drawing.Color.Empty; } else clr = pa.Colors.ItemCheckedBackground/*ColorFunctions.CheckBoxBackColor(g)*/; } if (!clr.IsEmpty) { SolidBrush objBrush = new SolidBrush(clr); g.FillRectangle(objBrush, r); objBrush.Dispose(); } } objImage.DrawImage(g, rect); } } if (bIsOnMenu && this.IsOnCustomizeMenu && m_Visible && !this.SystemItem) { // Draw check box if this item is visible Rectangle r = new Rectangle(m_Rect.Left, m_Rect.Top, m_Rect.Height, m_Rect.Height); r.Inflate(-1, -1); //Color clr=g.GetNearestColor(Color.FromArgb(96,ColorFunctions.HoverBackColor())); if (pa.Colors.ItemCheckedBackground2.IsEmpty) { Color clr = pa.Colors.ItemCheckedBackground/*ColorFunctions.CheckBoxBackColor(g)*/; SolidBrush objBrush = new SolidBrush(clr); g.FillRectangle(objBrush, r); objBrush.Dispose(); } else { System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemCheckedBackground, pa.Colors.ItemCheckedBackground2, pa.Colors.ItemCheckedBackgroundGradientAngle); g.FillRectangle(gradient, r); gradient.Dispose(); } } else if (m_Checked && !bIsOnMenu && objImage == null) { Rectangle r = m_Rect; // TODO: In 9188 GetNearestColor on the Graphics that were taken directly from Paint event did not work correctly. Check in future versions... // Draw background //Color clr=g.GetNearestColor(Color.FromArgb(96,ColorFunctions.HoverBackColor(g))); Color clr; if (mouseOver && m_HotTrackingStyle != eHotTrackingStyle.None) { if (!pa.Colors.ItemCheckedBackground2.IsEmpty) { System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemCheckedBackground2, pa.Colors.ItemCheckedBackground, pa.Colors.ItemCheckedBackgroundGradientAngle); g.FillRectangle(gradient, r); gradient.Dispose(); clr = System.Drawing.Color.Empty; } else { if (!pa.Colors.ItemHotBackground2.IsEmpty) { System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemHotBackground, pa.Colors.ItemHotBackground2, pa.Colors.ItemHotBackgroundGradientAngle); g.FillRectangle(gradient, r); gradient.Dispose(); clr = System.Drawing.Color.Empty; } else clr = pa.Colors.ItemHotBackground; } } else { if (!pa.Colors.ItemCheckedBackground2.IsEmpty) { System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemCheckedBackground, pa.Colors.ItemCheckedBackground2, pa.Colors.ItemCheckedBackgroundGradientAngle); g.FillRectangle(gradient, r); gradient.Dispose(); clr = System.Drawing.Color.Empty; } else clr = pa.Colors.ItemCheckedBackground; } if (!clr.IsEmpty) { SolidBrush objBrush = new SolidBrush(clr); g.FillRectangle(objBrush, r); objBrush.Dispose(); } } } if (bIsOnMenu && this.IsOnCustomizeMenu && m_Visible && !this.SystemItem) { Rectangle r = new Rectangle(m_Rect.Left, m_Rect.Top, m_Rect.Height, m_Rect.Height); r.Inflate(-1, -1); //Color clr=g.GetNearestColor(Color.FromArgb(200,SystemColors.Highlight)); Color clr = pa.Colors.ItemCheckedBorder/*SystemColors.Highlight*/; Pen objPen = new Pen(clr, 1); // TODO: Beta 2 fix --> g.DrawRectangle(objPen,r); NativeFunctions.DrawRectangle(g, objPen, r); objPen.Dispose(); objPen = new Pen(pa.Colors.ItemCheckedText); // Draw checker... Point[] pt = new Point[3]; pt[0].X = r.Left + (r.Width - 5) / 2 - 1; pt[0].Y = r.Top + (r.Height - 6) / 2 + 3; pt[1].X = pt[0].X + 2; pt[1].Y = pt[0].Y + 2; pt[2].X = pt[1].X + 4; pt[2].Y = pt[1].Y - 4; g.DrawLines(objPen/*SystemPens.ControlText*/, pt); pt[0].X++; pt[1].X++; pt[2].X++; g.DrawLines(objPen/*SystemPens.ControlText*/, pt); objPen.Dispose(); } if (m_Checked && !this.IsOnCustomizeMenu && !this.IsOnCustomizeDialog) { Rectangle r; if (bIsOnMenu) r = new Rectangle(m_Rect.X + 1, m_Rect.Y, m_ImageDrawRect.Width - 2, m_Rect.Height); else if (m_HotTrackingStyle == eHotTrackingStyle.Image) { r = rect; r.Inflate(2, 2); } else r = new Rectangle(m_Rect.X, m_Rect.Y, m_Rect.Width, m_Rect.Height); if (bIsOnMenu) r.Inflate(-1, -1); // Draw line around... if (bIsOnMenu || !this.Expanded) { if (objImage == null || m_ButtonStyle == eButtonStyle.TextOnlyAlways) { if (mouseOver) { if (m_Checked && !pa.Colors.ItemCheckedBackground2.IsEmpty) { System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemCheckedBackground2, pa.Colors.ItemCheckedBackground, pa.Colors.ItemCheckedBackgroundGradientAngle); g.FillRectangle(gradient, r); gradient.Dispose(); } else { if (!pa.Colors.ItemHotBackground2.IsEmpty) { System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemHotBackground, pa.Colors.ItemHotBackground2, pa.Colors.ItemHotBackgroundGradientAngle); g.FillRectangle(gradient, r); gradient.Dispose(); } else { using (SolidBrush mybrush = new SolidBrush(pa.Colors.ItemHotBackground)) g.FillRectangle(mybrush, r); } } } else { if (pa.Colors.ItemCheckedBackground2.IsEmpty) { using (SolidBrush mybrush = new SolidBrush(pa.Colors.ItemCheckedBackground)) g.FillRectangle(mybrush, r); } else { System.Drawing.Drawing2D.LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(r, pa.Colors.ItemCheckedBackground, pa.Colors.ItemCheckedBackground2, pa.Colors.ItemCheckedBackgroundGradientAngle); g.FillRectangle(gradient, r); gradient.Dispose(); } } } //Color clr=g.GetNearestColor(Color.FromArgb(200,SystemColors.Highlight)); Color clr = pa.Colors.ItemCheckedBorder/*SystemColors.Highlight*/; Pen objPen = new Pen(clr, 1); // TODO: Beta 2 fix ---> g.DrawRectangle(objPen,r); NativeFunctions.DrawRectangle(g, objPen, r); objPen.Dispose(); } if ((objImage == null || m_ButtonStyle == eButtonStyle.TextOnlyAlways) && bIsOnMenu) { // Draw checker... Pen pen = new Pen(pa.Colors.ItemCheckedText); Point[] pt = new Point[3]; pt[0].X = r.Left + (r.Width - 5) / 2 - 1; pt[0].Y = r.Top + (r.Height - 6) / 2 + 3; pt[1].X = pt[0].X + 2; pt[1].Y = pt[0].Y + 2; pt[2].X = pt[1].X + 4; pt[2].Y = pt[1].Y - 4; g.DrawLines(pen/*SystemPens.ControlText*/, pt); pt[0].X++; //pt[0].Y pt[1].X++; //pt[1].Y; pt[2].X++; //pt[2].Y; g.DrawLines(pen/*SystemPens.ControlText*/, pt); pen.Dispose(); } } } else { if (bIsOnMenu && mouseOver && m_HotTrackingStyle == eHotTrackingStyle.Default) { Rectangle r = new Rectangle(itemRect.Left + 1, itemRect.Top, itemRect.Width - 2, itemRect.Height); using (Pen mypen = new Pen(pa.Colors.ItemHotBorder, 1)) NativeFunctions.DrawRectangle(g, mypen, r); } // Replicated code from above to draw the item checked box if (m_Checked && !this.IsOnCustomizeMenu && !this.IsOnCustomizeDialog) { Rectangle r; if (bIsOnMenu) r = new Rectangle(m_Rect.X + 1, m_Rect.Y, m_ImageDrawRect.Width - 2, m_Rect.Height); else if (m_HotTrackingStyle == eHotTrackingStyle.Image) { r = rect; r.Inflate(2, 2); } else r = new Rectangle(m_Rect.X, m_Rect.Y, m_Rect.Width, m_Rect.Height); if (bIsOnMenu) r.Inflate(-1, -1); // Draw line around... if (bIsOnMenu || !this.Expanded) { Color clr = pa.Colors.ItemDisabledText; Pen objPen = new Pen(clr, 1); NativeFunctions.DrawRectangle(g, objPen, r); objPen.Dispose(); } if ((objImage == null || m_ButtonStyle == eButtonStyle.TextOnlyAlways) && bIsOnMenu) { // Draw checker... Pen pen = new Pen(pa.Colors.ItemDisabledText); Point[] pt = new Point[3]; pt[0].X = r.Left + (r.Width - 5) / 2 - 1; pt[0].Y = r.Top + (r.Height - 6) / 2 + 3; pt[1].X = pt[0].X + 2; pt[1].Y = pt[0].Y + 2; pt[2].X = pt[1].X + 4; pt[2].Y = pt[1].Y - 4; g.DrawLines(pen, pt); pt[0].X++; //pt[0].Y pt[1].X++; //pt[1].Y; pt[2].X++; //pt[2].Y; g.DrawLines(pen, pt); pen.Dispose(); } } textColor = pa.Colors.ItemDisabledText; if (objImage != null && m_ButtonStyle != eButtonStyle.TextOnlyAlways) { // Draw disabled image objImage.DrawImage(g, rect); } } // Draw menu item text if (bIsOnMenu || m_ButtonStyle != eButtonStyle.Default || objImage == null || (!bIsOnMenu && (m_ImagePosition == eImagePosition.Top || m_ImagePosition == eImagePosition.Bottom)) /*|| !this.IsOnBar*/) // Commented out becouse it caused text to be drawn if item is not on bar no matter what { if (bIsOnMenu) rect = new Rectangle(m_TextDrawRect.X, m_TextDrawRect.Y, itemRect.Width - m_ImageDrawRect.Right - 26, m_TextDrawRect.Height); else { rect = m_TextDrawRect; if (m_ImagePosition == eImagePosition.Top || m_ImagePosition == eImagePosition.Bottom) { if (m_Orientation == eOrientation.Vertical) { rect = new Rectangle(m_TextDrawRect.X, m_TextDrawRect.Y, m_TextDrawRect.Width, m_TextDrawRect.Height); } else { rect = new Rectangle(m_TextDrawRect.X, m_TextDrawRect.Y, itemRect.Width, m_TextDrawRect.Height); if ((this.SubItems.Count > 0 || this.PopupType == ePopupType.Container) && this.ShowSubItems) rect.Width -= 10; } objStringFormat |= eTextFormat.HorizontalCenter; } else if (bIsOnMenuBar && objImage == null) objStringFormat |= eTextFormat.HorizontalCenter; if (m_MouseDown && m_HotTrackingStyle != eHotTrackingStyle.Image) { if (m_ForeColor.IsEmpty) { textColor = pa.Colors.ItemPressedText; } else { textColor = System.Windows.Forms.ControlPaint.Light(m_ForeColor); } } } rect.Offset(itemRect.Left, itemRect.Top); if (m_Orientation == eOrientation.Vertical && !bIsOnMenu) { g.RotateTransform(90); TextDrawing.DrawStringLegacy(g, m_Text, objFont, textColor, new Rectangle(rect.Top, -rect.Right, rect.Height, rect.Width), objStringFormat); g.ResetTransform(); } else { if (rect.Right > m_Rect.Right) rect.Width = m_Rect.Right - rect.Left; TextDrawing.DrawString(g, m_Text, objFont, textColor, rect, objStringFormat); if (!this.DesignMode && this.Focused && !bIsOnMenu && !bIsOnMenuBar) { //SizeF szf=g.MeasureString(m_Text,objFont,rect.Width,objStringFormat); Rectangle r = rect; //r.Width=(int)Math.Ceiling(szf.Width); //r.Height=(int)Math.Ceiling(szf.Height); //r.Inflate(1,1); System.Windows.Forms.ControlPaint.DrawFocusRectangle(g, r); } } } // Draw Shortcut text if needed if (this.DrawShortcutText != "" && bIsOnMenu && !this.IsOnCustomizeDialog) { objStringFormat |= eTextFormat.HidePrefix | eTextFormat.Right; TextDrawing.DrawString(g, this.DrawShortcutText, objFont, textColor, rect, objStringFormat); } // If it has subitems draw the triangle to indicate that if ((this.SubItems.Count > 0 || this.PopupType == ePopupType.Container) && this.ShowSubItems) { if (bIsOnMenu) { Point[] p = new Point[3]; p[0].X = itemRect.Left + itemRect.Width - 12; p[0].Y = itemRect.Top + (itemRect.Height - 8) / 2; p[1].X = p[0].X; p[1].Y = p[0].Y + 8; p[2].X = p[0].X + 4; p[2].Y = p[0].Y + 4; using (SolidBrush brush = new SolidBrush(textColor)) g.FillPolygon(brush, p); } else if (!m_SubItemsRect.IsEmpty) { if (GetEnabled(pa.ContainerControl) && ((mouseOver || m_Checked) && !m_Expanded && m_HotTrackingStyle != eHotTrackingStyle.None && m_HotTrackingStyle != eHotTrackingStyle.Image)) { if (m_Orientation == eOrientation.Horizontal) { using (Pen mypen = new Pen(pa.Colors.ItemHotBorder)) g.DrawLine(mypen/*SystemPens.Highlight*/, itemRect.Left + m_SubItemsRect.Left, itemRect.Top, itemRect.Left + m_SubItemsRect.Left, itemRect.Bottom - 1); } else { using (Pen mypen = new Pen(pa.Colors.ItemHotBorder)) g.DrawLine(mypen/*SystemPens.Highlight*/, itemRect.Left, itemRect.Top + m_SubItemsRect.Top, itemRect.Right - 2, itemRect.Top + m_SubItemsRect.Top); } } Point[] p = new Point[3]; if (this.PopupSide == ePopupSide.Default) { if (m_Orientation == eOrientation.Horizontal) { p[0].X = itemRect.Left + m_SubItemsRect.Left + (m_SubItemsRect.Width - 5) / 2; p[0].Y = itemRect.Top + (m_SubItemsRect.Height - 3) / 2 + 1; p[1].X = p[0].X + 5; p[1].Y = p[0].Y; p[2].X = p[0].X + 2; p[2].Y = p[0].Y + 3; } else { p[0].X = itemRect.Left + (m_SubItemsRect.Width - 3) / 2 + 1; p[0].Y = itemRect.Top + m_SubItemsRect.Top + (m_SubItemsRect.Height - 5) / 2; p[1].X = p[0].X; p[1].Y = p[0].Y + 6; p[2].X = p[0].X - 3; p[2].Y = p[0].Y + 3; } } else { switch (this.PopupSide) { case ePopupSide.Left: { p[0].X = itemRect.Left + m_SubItemsRect.Left + m_SubItemsRect.Width / 2; p[0].Y = itemRect.Top + m_SubItemsRect.Height / 2 - 3; p[1].X = p[0].X; p[1].Y = p[0].Y + 6; p[2].X = p[0].X + 3; p[2].Y = p[0].Y + 3; break; } case ePopupSide.Right: { p[0].X = itemRect.Left + m_SubItemsRect.Left + m_SubItemsRect.Width / 2 + 3; p[0].Y = itemRect.Top + m_SubItemsRect.Height / 2 - 3; p[1].X = p[0].X; p[1].Y = p[0].Y + 6; p[2].X = p[0].X - 3; p[2].Y = p[0].Y + 3; break; } case ePopupSide.Top: { p[0].X = itemRect.Left + m_SubItemsRect.Left + (m_SubItemsRect.Width - 5) / 2; p[0].Y = itemRect.Top + (m_SubItemsRect.Height - 3) / 2 + 4; p[1].X = p[0].X + 6; p[1].Y = p[0].Y; p[2].X = p[0].X + 3; p[2].Y = p[0].Y - 4; break; } case ePopupSide.Bottom: { p[0].X = itemRect.Left + m_SubItemsRect.Left + (m_SubItemsRect.Width - 5) / 2 + 1; p[0].Y = itemRect.Top + (m_SubItemsRect.Height - 3) / 2 + 1; p[1].X = p[0].X + 5; p[1].Y = p[0].Y; p[2].X = p[0].X + 2; p[2].Y = p[0].Y + 3; break; } } } if (GetEnabled(pa.ContainerControl)) { using (SolidBrush mybrush = new SolidBrush(pa.Colors.ItemText)) g.FillPolygon(mybrush/*SystemBrushes.ControlText*/, p); } else { using (SolidBrush mybrush = new SolidBrush(pa.Colors.ItemDisabledText)) g.FillPolygon(mybrush/*SystemBrushes.ControlDark*/, p); } } } if (this.Focused && this.DesignMode) { Rectangle r = itemRect; r.Inflate(-1, -1); DesignTime.DrawDesignTimeSelection(g, r, pa.Colors.ItemDesignTimeBorder); } if (objImage != null) objImage.Dispose(); }
protected override void OnPaint(PaintEventArgs e) { try { using (Bitmap bmp = new Bitmap(this.Width, this.Height)) { using (Graphics g = Graphics.FromImage(bmp)) { //使填充矩形的颜色从红色到黄色渐变 int _height = Math.Max(this.Height - formTitleLeftImg.Height, 1); Rectangle _fillRect = new Rectangle(0, formTitleLeftImg.Height - 1, this.Width, _height); LinearGradientBrush lBrush = new LinearGradientBrush(_fillRect, LinearBackColor1, LinearBackColor2, LinearGradientMode.Vertical | LinearGradientMode.Horizontal); g.FillRectangle(lBrush, _fillRect); // g.SmoothingMode = SmoothingMode.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighSpeed; g.InterpolationMode = InterpolationMode.NearestNeighbor; System.Drawing.Imaging.ImageAttributes ia = new System.Drawing.Imaging.ImageAttributes(); ia.ClearColorKey(); //绘制角 //左边 g.DrawImage(formDegBottomLeftImg, new Rectangle(0, this.Height - formDegBottomLeftImg.Height, formDegBottomLeftImg.Width, formDegBottomLeftImg.Height), 0, 0, formDegBottomLeftImg.Width, formDegBottomLeftImg.Height, GraphicsUnit.Pixel, ia); //右边 g.DrawImage(formDegBottomRightImg, new Rectangle(this.Width - formDegBottomRightImg.Width, this.Height - formDegBottomRightImg.Height, formDegBottomRightImg.Width, formDegBottomRightImg.Height), 0, 0, formDegBottomRightImg.Width, formDegBottomRightImg.Height, GraphicsUnit.Pixel, ia); //绘制边框 //底边 ia.SetWrapMode(WrapMode.TileFlipX); g.DrawImage(formBorderBottomImg, new Rectangle(formDegBottomLeftImg.Width, this.Height - formBorderBottomImg.Height, this.Width - formDegBottomLeftImg.Width * 2, formBorderBottomImg.Height), 0, 0, formBorderBottomImg.Width, formBorderBottomImg.Height, GraphicsUnit.Pixel, ia); //左边 ia.SetWrapMode(WrapMode.TileFlipY); g.DrawImage(formBorderLeftImg, new Rectangle(0, titleHeight, formBorderLeftImg.Width, this.Height - titleHeight - formDegBottomLeftImg.Height), 0, 0, formBorderLeftImg.Width, formBorderLeftImg.Height, GraphicsUnit.Pixel, ia); //右边 g.DrawImage(formBorderRightImg, new Rectangle(this.Width - formBorderRightImg.Width, titleHeight, formBorderRightImg.Width, this.Height - titleHeight - formDegBottomLeftImg.Height), 0, 0, formBorderRightImg.Width, formBorderRightImg.Height, GraphicsUnit.Pixel, ia); //标题栏 ia.SetWrapMode(WrapMode.TileFlipX); //left g.DrawImage(formTitleLeftImg, new Rectangle(0, 0, formTitleLeftImg.Width, formTitleLeftImg.Height), 0, 0, formTitleLeftImg.Width, formTitleLeftImg.Height, GraphicsUnit.Pixel, ia); //middle g.DrawImage(formTitleMiddleImg, new Rectangle(formTitleLeftImg.Width, 0, this.Width - formTitleLeftImg.Width - formTitleRightImg.Width, formTitleMiddleImg.Height), 0, 0, formTitleMiddleImg.Width, formTitleMiddleImg.Height, GraphicsUnit.Pixel, ia); //right g.DrawImage(formTitleRightImg, new Rectangle(this.Width - formTitleRightImg.Width, 0, formTitleRightImg.Width, formTitleRightImg.Height), 0, 0, formTitleRightImg.Width, formTitleRightImg.Height, GraphicsUnit.Pixel, ia); //绘制标题信息 SizeF s = g.MeasureString(Text, Font); float x = 5; float y = (formTitleLeftImg.Height - s.Height) / 2 + 2; StringFormat sf = new StringFormat(); g.DrawString(Text, new Font(Font.FontFamily, 10), new SolidBrush(Color.FromArgb(230, 230, 230)), x, y, sf); //画到窗口上 e.Graphics.DrawImageUnscaled(bmp, 0, 0, this.Width, this.Height); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
/// <summary> /// Create a disabled version of the image. /// </summary> /// <param name="image">The image to convert</param> /// <param name="background">The Color of the background behind the image. The background parameter is used to calculate the fill color of the disabled image so that it is always visible against the background.</param> /// <returns></returns> public static Image CreateDisabledImage(Image image, Color background) { if (image == null) return null; Size imgSize = image.Size; if (s_DisabledImageAttr == null) { float[][] arrayJagged = new float[5][]; arrayJagged[0] = new float[5] { 0.2125f, 0.2125f, 0.2125f, 0f, 0f } ; arrayJagged[1] = new float[5] { 0.2577f, 0.2577f, 0.2577f, 0f, 0f } ; arrayJagged[2] = new float[5] { 0.0361f, 0.0361f, 0.0361f, 0f, 0f } ; float[] arraySingle = new float[5]; arraySingle[3] = 1f; arrayJagged[3] = arraySingle; arrayJagged[4] = new float[5] { 0.38f, 0.38f, 0.38f, 0f, 1f } ; System.Drawing.Imaging.ColorMatrix matrix = new System.Drawing.Imaging.ColorMatrix(arrayJagged); s_DisabledImageAttr = new System.Drawing.Imaging.ImageAttributes(); s_DisabledImageAttr.ClearColorKey(); s_DisabledImageAttr.SetColorMatrix(matrix); } Bitmap bitmap = new Bitmap(image.Width, image.Height); using (Graphics g = Graphics.FromImage(bitmap)) { g.DrawImage(image, new Rectangle(0, 0, imgSize.Width, imgSize.Height), 0, 0, imgSize.Width, imgSize.Height, GraphicsUnit.Pixel, s_DisabledImageAttr); } return bitmap; }
private void PaintButton(Graphics g, MDISystemItem mdi , SystemButton button, Rectangle r, Office2007ButtonItemStateColorTable ct, ColorScheme colorScheme) { Region oldClip = g.Clip; g.SetClip(r); Office2007ButtonItemPainter.PaintBackground(g, ct, r, RoundRectangleShapeDescriptor.RoundCorner2); r.Inflate(-1, -1); r.Offset(1, 0); using (Bitmap bmp = mdi.GetButtonBitmap(g, button, r, colorScheme)) { if (button == SystemButton.Minimize && !mdi.MinimizeEnabled || button == SystemButton.Restore && !mdi.RestoreEnabled || button == SystemButton.Close && !mdi.CloseEnabled) { float[][] array = new float[5][]; array[0] = new float[5] { 0, 0, 0, 0, 0 }; array[1] = new float[5] { 0, 0, 0, 0, 0 }; array[2] = new float[5] { 0, 0, 0, 0, 0 }; array[3] = new float[5] { .5f, .5f, .5f, .5f, 0 }; array[4] = new float[5] { 0, 0, 0, 0, 0 }; System.Drawing.Imaging.ColorMatrix grayMatrix = new System.Drawing.Imaging.ColorMatrix(array); System.Drawing.Imaging.ImageAttributes disabledImageAttr = new System.Drawing.Imaging.ImageAttributes(); disabledImageAttr.ClearColorKey(); disabledImageAttr.SetColorMatrix(grayMatrix); g.DrawImage(bmp, r, 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, disabledImageAttr); } else { if (button == mdi.MouseDownButton) r.Offset(1, 1); g.DrawImageUnscaled(bmp, r); } } g.Clip = oldClip; }