private void CreateBrushInternal() { m_location = m_rect.Location; m_size = m_rect.Size; m_center = new Point(m_location.X + (m_size.Width / 2), m_location.Y + (m_size.Height / 2)); if (m_size.Height < 16 || m_size.Width < 16) { m_factor = 0.25f; } if (m_size.Height < 35 || m_size.Width < 35) { m_factor = 0.5f; } else { m_factor = 1; } //m_gradient *= m_factor; double dX = ((double)m_size.Width / (10f * m_factor)) / 4f; double dY = ((double)m_size.Height / (10f * m_factor)) / 4f; double pX = m_gradient / dX; double pY = m_gradient / dY; double gX = pX / m_gradient; double gY = pY / m_gradient; double gradient = m_gradient / (float)(40f / 2f); double gradW = 4f / ((float)m_size.Width / 2f); double gradH = 4f / ((float)m_size.Height / 2f); double gradX = 1 - gX; double gradY = 1 - gY; float ray = m_rounded / 2; // double alpha = 45 * (Math.PI / 180); // float delta = (float)(ray * Math.Sin(alpha)); // // PointF[] pts = new PointF[17] // { // /* 0 */ new PointF(m_center.X,m_location.Y), // /* 1 */ new PointF(m_rect.Right-ray,m_location.Y), // /* 2 */ new PointF((m_rect.Right-ray)+delta,m_location.Y+(ray-delta)), // /* 3 */ new PointF(m_rect.Right,m_location.Y+ray), // /* 4 */ new PointF(m_rect.Right,m_center.Y), // /* 5 */ new PointF(m_rect.Right,m_rect.Bottom-ray), // /* 6 */ new PointF((m_rect.Right-ray)+delta,m_rect.Bottom-(ray-delta)), // /* 7 */ new PointF(m_rect.Right-ray,m_rect.Bottom), // /* 8 */ new PointF(m_center.X,m_rect.Bottom), // /* 9 */ new PointF(m_location.X+ray,m_rect.Bottom), // /* 10 */ new PointF(m_location.X+(ray-delta),m_rect.Bottom-(ray-delta)), // /* 11 */ new PointF(m_location.X,m_rect.Bottom-ray), // /* 12 */ new PointF(m_location.X,m_center.Y), // /* 13 */ new PointF(m_location.X,m_location.Y+ray), // /* 14 */ new PointF(m_location.X+(ray-delta),m_location.Y+(ray-delta)), // /* 15 */ new PointF(m_location.X+ray,m_location.Y), // /* 16 */ new PointF(m_center.X,m_location.Y) // }; ////***************** NON UTILIZZATE A CAUSA DELLE API *******************//// //GraphicsPath gp = new GraphicsPath(); //gp.AddCurve(pts, 0, 16, 0.05F); ////**********************************************************************//// m_gp = new GraphicsPath(); //m_gp.AddCurve(pts, 0, 16, 0.05F); m_gp.AddLine(new PointF(m_center.X, m_location.Y), new PointF(m_rect.Right - ray, m_location.Y)); m_gp.AddArc(new RectangleF(m_rect.Right - m_rounded, m_location.Y, m_rounded, m_rounded), 270, 90); m_gp.AddLine(new PointF(m_rect.Right, m_location.Y + ray), new PointF(m_rect.Right, m_rect.Bottom - ray)); m_gp.AddArc(new RectangleF(m_rect.Right - m_rounded, m_rect.Bottom - m_rounded, m_rounded, m_rounded), 0, 90); m_gp.AddLine(new PointF(m_rect.Right - ray, m_rect.Bottom), new PointF(m_location.X + ray, m_rect.Bottom)); m_gp.AddArc(new RectangleF(m_location.X, m_rect.Bottom - m_rounded, m_rounded, m_rounded), 90, 90); m_gp.AddLine(new PointF(m_location.X, m_rect.Bottom - ray), new PointF(m_location.X, m_location.Y + ray)); m_gp.AddArc(new RectangleF(m_location.X, m_location.Y, m_rounded, m_rounded), 180, 90); m_gp.AddLine(new PointF(m_location.X + ray, m_location.Y), new PointF(m_center.X, m_location.Y)); m_gp.CloseFigure(); //// ******** PROVA ********** //// IntPtr nativePath = IntPtr.Zero; IntPtr ptrPoints = GDIplus.ConvertPointToMemory(m_gp.PathPoints); int iRet = GDIplus.GdipCreatePath((int)FillMode.Alternate, ref nativePath); HandleRef pathRef = new HandleRef(null, nativePath); iRet = GDIplus.GdipAddPathLine(pathRef, m_center.X, m_location.Y, m_rect.Right - ray, m_location.Y); iRet = GDIplus.GdipAddPathArc(pathRef, m_rect.Right - m_rounded, m_location.Y, m_rounded, m_rounded, 270, 90); iRet = GDIplus.GdipAddPathLine(pathRef, m_rect.Right, m_location.Y + ray, m_rect.Right, m_rect.Bottom - ray); iRet = GDIplus.GdipAddPathArc(pathRef, m_rect.Right - m_rounded, m_rect.Bottom - m_rounded, m_rounded, m_rounded, 0, 90); iRet = GDIplus.GdipAddPathLine(pathRef, m_rect.Right - ray, m_rect.Bottom, m_location.X + ray, m_rect.Bottom); iRet = GDIplus.GdipAddPathArc(pathRef, m_location.X, m_rect.Bottom - m_rounded, m_rounded, m_rounded, 90, 90); iRet = GDIplus.GdipAddPathLine(pathRef, m_location.X, m_rect.Bottom - ray, m_location.X, m_location.Y + ray); iRet = GDIplus.GdipAddPathArc(pathRef, m_location.X, m_location.Y, m_rounded, m_rounded, 180, 90); iRet = GDIplus.GdipAddPathLine(pathRef, m_location.X + ray, m_location.Y, m_center.X, m_location.Y); iRet = GDIplus.GdipClosePathFigure(pathRef); //// ************************* //// ColorBlend cblend = new ColorBlend(); float[] positions = new float[] { 0.0F, (float)gradient, 1F }; Color[] colors = new Color[] { m_color1, m_color2, m_color3 }; cblend.Positions = positions; cblend.Colors = colors; ////***************** NON UTILIZZATE A CAUSA DELLE API *******************//// //PathGradientBrush pgb = new PathGradientBrush(m_gp.PathPoints); //pgb.CenterPoint = m_center; //pgb.CenterColor = m_centercolor; //pgb.InterpolationColors = cblend; //pgb.FocusScales = new PointF((float)gradX, (float)gradY); ////**********************************************************************//// // crea il PathGradientBrush m_nativeBrush = IntPtr.Zero; //IntPtr j = GDIplus.ConvertPointToMemory(m_gp.PathPoints);//pts // /*int*/ iRet = GDIplus.GdipCreatePathGradient(new HandleRef(null, j), (int)pts.Length, (int)WrapMode.Clamp, out m_nativeBrush); iRet = GDIplus.GdipCreatePathGradientFromPath(pathRef, out m_nativeBrush); HandleRef brushRef = new HandleRef(null, m_nativeBrush); // imposta il CenterPoint iRet = GDIplus.GdipSetPathGradientCenterPoint(brushRef, new GPPOINTF(m_center)); // imposta InterpolationColors this.SetInterpolationColorsInternal(cblend); // imposta FocusScales iRet = GDIplus.GdipSetPathGradientFocusScales(brushRef, (float)gradX, (float)gradY); base.SetNativeBrush(m_nativeBrush); }