Esempio n. 1
0
        internal static Bitmap GetDragImageHint(
            ContentAlignment textAlignment,
            Bitmap hintImage,
            RectangleF textRectangle,
            int hintImageWidth)
        {
            int width = hintImage.Width;

            if (width > hintImageWidth)
            {
                width = hintImageWidth;
                int   x        = (hintImage.Width - hintImageWidth) / 2;
                Point location = Point.Empty;
                switch (textAlignment)
                {
                case ContentAlignment.TopCenter:
                case ContentAlignment.MiddleCenter:
                case ContentAlignment.BottomCenter:
                    location = new Point(x, 0);
                    break;

                case ContentAlignment.TopRight:
                case ContentAlignment.MiddleRight:
                case ContentAlignment.BottomRight:
                    location = Point.Truncate(textRectangle.Location);
                    break;
                }
                Rectangle cropRectangle = new Rectangle(location, new Size(width, hintImage.Height));
                hintImage = ImageHelper.Crop(hintImage, cropRectangle);
            }
            ImageHelper.ApplyMask(hintImage, (Brush) new LinearGradientBrush(new Rectangle(0, 0, width, hintImage.Height), Color.White, Color.Black, LinearGradientMode.Horizontal));
            return(hintImage);
        }
Esempio n. 2
0
        protected override Image GetDragHintCore()
        {
            Bitmap bitmap = base.GetDragHintCore() as Bitmap;
            int    width  = bitmap.Width;

            if (width > 150)
            {
                width  = 150;
                bitmap = ImageHelper.Crop(bitmap, new Rectangle(Point.Empty, new Size(width, bitmap.Height)));
            }
            ImageHelper.ApplyMask(bitmap, (Brush) new LinearGradientBrush(new Rectangle(0, 0, width, bitmap.Height), Color.White, Color.Black, LinearGradientMode.Horizontal));
            return((Image)bitmap);
        }