/// <summary> /// 获取渐变笔刷 /// </summary> /// <param name="shadeStr">渐变类型</param> /// <param name="w_distance">宽度距离</param> /// <param name="h_distance">高度距离</param> /// <returns></returns> private static Brush GetShadeBrush(string shadeStr, int w_distance, int h_distance) { //shadeStr = shade_1_111111_100_222222_100 Point s_point = new Point(0, 0); Point e_point = new Point(0, 0); Color s_color = Color.FromArgb(0, 0, 0); Color e_color = Color.FromArgb(255, 255, 255); string[] arges = shadeStr.Split('_'); if (arges.Length != 6) { return(null); } ShadeStyle shadeStyle = (ShadeStyle)int.Parse(arges[1]); switch (shadeStyle) { case ShadeStyle.Top: e_point = new Point(0, h_distance); break; case ShadeStyle.Bottom: s_point = new Point(0, h_distance); break; case ShadeStyle.Left: e_point = new Point(w_distance, 0); break; case ShadeStyle.Right: s_point = new Point(w_distance, 0); break; case ShadeStyle.LeftBottom: e_point = new Point(w_distance, h_distance); break; case ShadeStyle.RightBottom: s_point = new Point(w_distance, h_distance); break; default: return(null); } //将颜色值及透明度转成对象 s_color = GetColor(arges[2], arges[3]); e_color = GetColor(arges[4], arges[5]); return(new LinearGradientBrush(s_point, e_point, s_color, e_color)); }
/// <summary> /// 获取渐变笔刷 /// </summary> /// <param name="shadeStr">渐变类型</param> /// <param name="w_distance">宽度距离</param> /// <param name="h_distance">高度距离</param> /// <returns></returns> private static Brush GetShadeBrush(string shadeStr, int w_distance, int h_distance) { Point s_point = new Point(0, 0); Point e_point = new Point(0, 0); Color s_color = Color.FromArgb(0, 0, 0); Color e_color = Color.FromArgb(255, 255, 255); ShadeStyle shadeStyle = (ShadeStyle)int.Parse(shadeStr); switch (shadeStyle) { case ShadeStyle.Top: e_point = new Point(0, h_distance); break; case ShadeStyle.Bottom: s_point = new Point(0, h_distance); break; case ShadeStyle.Left: e_point = new Point(w_distance, 0); break; case ShadeStyle.Right: s_point = new Point(w_distance, 0); break; case ShadeStyle.LeftBottom: e_point = new Point(w_distance, h_distance); break; case ShadeStyle.RightBottom: s_point = new Point(w_distance, h_distance); break; default: return(null); } return(new LinearGradientBrush(s_point, e_point, s_color, e_color)); }