Ejemplo n.º 1
0
        /// <summary>
        /// Show the content as a bitmap image
        /// </summary>
        private void button1_Click(object sender, System.EventArgs e)
        {
            //draw a fullsize bitmap of the grid...
            int gridHeight = this.gridControl1.RowHeights.GetTotal(0, this.gridControl1.RowCount);
            int gridWidth  = this.gridControl1.ColWidths.GetTotal(0, this.gridControl1.ColCount);

            Bitmap gridBM = new Bitmap(gridWidth, gridHeight);

            Graphics g = Graphics.FromImage(gridBM);

            this.gridControl1.GridBounds = new Rectangle(0, 0, gridWidth, gridHeight);
            this.gridControl1.DrawGrid(g);
            this.gridControl1.ResetGridBounds();

            g.Dispose();

            //create a bitmap the the proper target size
            Bitmap picBM = new Bitmap(this.pictureBox1.Size.Width, this.pictureBox1.Size.Height);

            //draw grid bitmap into the new bitmap...
            System.Drawing.GraphicsUnit gu = System.Drawing.GraphicsUnit.Point;
            g = Graphics.FromImage(picBM);
            RectangleF srcRect  = gridBM.GetBounds(ref gu);
            Rectangle  destRect = new Rectangle(0, 0, picBM.Width, picBM.Height);


            g.DrawImage(gridBM, destRect, srcRect, gu);
            g.Dispose();

            //show the new bitmap
            this.pictureBox1.Image = picBM;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获得一个单位占据的英寸数
        /// </summary>
        /// <param name="unit">单位类型</param>
        /// <returns>英寸数</returns>
        public static double GetUnit(System.Drawing.GraphicsUnit unit)
        {
            switch (unit)
            {
            case System.Drawing.GraphicsUnit.Display:
                return(1 / fDpi);

            case System.Drawing.GraphicsUnit.Document:
                return(1 / 300.0);

            case System.Drawing.GraphicsUnit.Inch:
                return(1);

            case System.Drawing.GraphicsUnit.Millimeter:
                return(1 / 25.4);

            case System.Drawing.GraphicsUnit.Pixel:
                return(1 / fDpi);

            case System.Drawing.GraphicsUnit.Point:
                return(1 / 72.0);

            default:
                throw new System.NotSupportedException("Not support " + unit.ToString());
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 创建填充背景使用的画刷对象
        /// </summary>
        /// <param name="left">要绘制背景区域的左端坐标</param>
        /// <param name="top">要绘制背景区域的顶端坐标</param>
        /// <param name="width">要绘制背景区域的宽度</param>
        /// <param name="height">要绘制背景区域的高度</param>
        /// <param name="unit">绘制图形使用的单位</param>
        /// <returns>创建的画刷对象</returns>
        /// <remarks>
        /// 若设置了背景图片则创建图片样式的画刷对象,若设置了图案则创建带图案的画刷对象,
        /// 若设置了渐变设置则创建带渐变的画刷对象,否则创建纯色画刷对象。
        /// </remarks>
        public Brush CreateBrush(
            float left,
            float top,
            float width,
            float height,
            System.Drawing.GraphicsUnit unit)
        {
            if (intStyle == XBrushStyleConst.Disabled)
            {
                return(null);
            }

            if (myImage != null && myImage.Value != null)
            {
                System.Drawing.TextureBrush brush = new TextureBrush(myImage.Value);
                if (bolRepeat)
                {
                    brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Tile;
                }
                else
                {
                    brush.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp;
                }
                float rate = (float)GraphicsUnitConvert.GetRate(
                    unit,
                    System.Drawing.GraphicsUnit.Pixel);
                //brush.Transform.Translate(fOffsetX, fOffsetY);
                brush.TranslateTransform(fOffsetX, fOffsetY);
                brush.ScaleTransform(rate, rate);
                return(brush);
            }
            if (intStyle == XBrushStyleConst.Solid)
            {
                return(new SolidBrush(intColor));
            }
            else
            {
                if (( int )intStyle < 1000)
                {
                    System.Drawing.Drawing2D.HatchStyle style = (System.Drawing.Drawing2D.HatchStyle)intStyle;
                    return(new System.Drawing.Drawing2D.HatchBrush(
                               (System.Drawing.Drawing2D.HatchStyle)intStyle,
                               intColor,
                               intColor2));
                }
                else
                {
                    return(new System.Drawing.Drawing2D.LinearGradientBrush(
                               new RectangleF(left, top, width, height),
                               intColor,
                               intColor2,
                               (System.Drawing.Drawing2D.LinearGradientMode)(intStyle - 1000)));
                }
            }
            //return new SolidBrush(intColor);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 以指定的单位获取图像的界限。
 /// </summary>
 /// <param name="unit">System.Drawing.GraphicsUnit 值之一,指示边框的测量单位。</param>
 /// <returns>System.Drawing.RectangleF,以指定的单位表示图像的界限。</returns>
 public System.Drawing.RectangleF GetBounds(ref System.Drawing.GraphicsUnit unit)
 {
     if (this.Value != null)
     {
         return(this.Value.GetBounds(ref unit));
     }
     else
     {
         return(System.Drawing.RectangleF.Empty);
     }
 }
Ejemplo n.º 5
0
 public Ruler()
 {
     this.SetStyle(ControlStyles.DoubleBuffer |
                   ControlStyles.UserPaint |
                   ControlStyles.AllPaintingInWmPaint |
                   ControlStyles.ResizeRedraw,
                   true);
     this.UpdateStyles();
     InitializeComponent();
     scaleUnit = GraphicsUnit.Millimeter;
 }
Ejemplo n.º 6
0
		public Ruler()
		{
			this.SetStyle(ControlStyles.DoubleBuffer |
			              ControlStyles.UserPaint |
			              ControlStyles.AllPaintingInWmPaint |
			              ControlStyles.ResizeRedraw,
			              true);
			this.UpdateStyles();
			InitializeComponent();
			scaleUnit = GraphicsUnit.Millimeter;
		}
Ejemplo n.º 7
0
 /// <summary>
 /// 进行单位换算
 /// </summary>
 /// <param name="vValue">长度值</param>
 /// <param name="OldUnit">旧单位</param>
 /// <param name="NewUnit">新单位</param>
 /// <returns>换算结果</returns>
 public static int Convert(
     int vValue,
     System.Drawing.GraphicsUnit OldUnit,
     System.Drawing.GraphicsUnit NewUnit)
 {
     if (OldUnit == NewUnit)
     {
         return(vValue);
     }
     else
     {
         return(( int )(vValue * GetRate(NewUnit, OldUnit)));
     }
 }
Ejemplo n.º 8
0
 public void FromFont(Font font)
 {
     if (font != null)
     {
         _fontname        = font.Name;
         _fontsize        = font.Size;
         _fontunit        = font.Unit;
         _gdicharset      = font.GdiCharSet;
         _gdiverticalfont = font.GdiVerticalFont;
         _bold            = font.Bold;
         _italic          = font.Italic;
         _strikethout     = font.Strikeout;
         _underline       = font.Underline;
     }
 }
Ejemplo n.º 9
0
        public MeasureUnits ConvertFromGraphicUnit(System.Drawing.GraphicsUnit gUnit)
        {
            switch (gUnit)
            {
            case GraphicsUnit.Inch: return(MeasureUnits.inch);

            case GraphicsUnit.Millimeter: return(MeasureUnits.mm);

            case GraphicsUnit.Pixel: return(MeasureUnits.pixel);

            case GraphicsUnit.Point: return(MeasureUnits.point);

            default:
                return(MeasureUnits.inch);
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// 进行单位换算
 /// </summary>
 /// <param name="p">长度值</param>
 /// <param name="OldUnit">旧单位</param>
 /// <param name="NewUnit">新单位</param>
 /// <returns>换算结果</returns>
 public static System.Drawing.PointF Convert(
     System.Drawing.PointF p,
     System.Drawing.GraphicsUnit OldUnit,
     System.Drawing.GraphicsUnit NewUnit)
 {
     if (OldUnit == NewUnit)
     {
         return(p);
     }
     else
     {
         double rate = GetRate(NewUnit, OldUnit);
         return(new System.Drawing.PointF(
                    (float)(p.X * rate),
                    (float)(p.Y * rate)));
     }
 }
Ejemplo n.º 11
0
 /// <summary>
 /// 进行单位换算
 /// </summary>
 /// <param name="size">旧值</param>
 /// <param name="OldUnit">旧单位</param>
 /// <param name="NewUnit">新单位</param>
 /// <returns>换算结果</returns>
 public static System.Drawing.SizeF Convert(
     System.Drawing.SizeF size,
     System.Drawing.GraphicsUnit OldUnit,
     System.Drawing.GraphicsUnit NewUnit)
 {
     if (OldUnit == NewUnit)
     {
         return(size);
     }
     else
     {
         double rate = GetRate(NewUnit, OldUnit);
         return(new System.Drawing.SizeF(
                    ( float )(size.Width * rate),
                    ( float )(size.Height * rate)));
     }
 }
Ejemplo n.º 12
0
 /// <summary>
 /// 进行单位换算
 /// </summary>
 /// <param name="x">X坐标值</param>
 /// <param name="y">Y坐标值</param>
 /// <param name="OldUnit">旧单位</param>
 /// <param name="NewUnit">新单位</param>
 /// <returns>换算结果</returns>
 public static System.Drawing.Point Convert(
     int x,
     int y,
     System.Drawing.GraphicsUnit OldUnit,
     System.Drawing.GraphicsUnit NewUnit)
 {
     if (OldUnit == NewUnit)
     {
         return(new System.Drawing.Point(x, y));
     }
     else
     {
         double rate = GetRate(NewUnit, OldUnit);
         return(new System.Drawing.Point(
                    ( int )(x * rate),
                    ( int )(y * rate)));
     }
 }
Ejemplo n.º 13
0
        public void DeleteNonWhiteCornerImages()
        {
            Console.WriteLine("Beginning deleting of non-white corner images in {0}", ImagesPath);

            Color trueWhite = System.Drawing.Color.FromArgb(255, 255, 255, 255);

            System.Drawing.GraphicsUnit pixel = GraphicsUnit.Pixel;
            int    width  = 0;
            int    height = 0;
            Bitmap bmp;

            int deleted    = 0;
            int notDeleted = 0;

            foreach (string file in Directory.GetFiles(ImagesPath, "*.jpg"))
            {
                bmp = new Bitmap(file);

                width  = Convert.ToInt32(bmp.GetBounds(ref pixel).Width) - 1;
                height = Convert.ToInt32(bmp.GetBounds(ref pixel).Height) - 1;

                //check if all the corner pixels are white
                if (!bmp.GetPixel(0, 0).Equals(trueWhite) ||
                    !bmp.GetPixel(0, height).Equals(trueWhite) ||
                    !bmp.GetPixel(width, 0).Equals(trueWhite) ||
                    !bmp.GetPixel(width, height).Equals(trueWhite))
                {
                    bmp.Dispose();
                    File.Delete(file);
                    deleted++;
                    if (deleted % 100 == 0)
                    {
                        Console.WriteLine("...deleted {0} images so far", deleted);
                    }
                }
                else
                {
                    notDeleted++;
                }
            }

            Console.WriteLine("Deleted images: {0}", deleted);
            Console.WriteLine("Remaining images: {0}", notDeleted);
        }
Ejemplo n.º 14
0
 /// <summary>
 /// 进行单位换算
 /// </summary>
 /// <param name="rect">旧值</param>
 /// <param name="OldUnit">旧单位</param>
 /// <param name="NewUnit">新单位</param>
 /// <returns>换算结果</returns>
 public static System.Drawing.RectangleF Convert(
     System.Drawing.RectangleF rect,
     System.Drawing.GraphicsUnit OldUnit,
     System.Drawing.GraphicsUnit NewUnit)
 {
     if (OldUnit == NewUnit)
     {
         return(rect);
     }
     else
     {
         double rate = GetRate(NewUnit, OldUnit);
         return(new System.Drawing.RectangleF(
                    ( float )(rect.X * rate),
                    ( float )(rect.Y * rate),
                    ( float )(rect.Width * rate),
                    ( float )(rect.Height * rate)));
     }
 }
Ejemplo n.º 15
0
        public void ScaleImages()
        {
            Console.WriteLine("Beginning scaling in {0}", ImagesPath);

            System.Drawing.GraphicsUnit pixel = GraphicsUnit.Pixel;
            int    width  = 0;
            int    height = 0;
            int    scaled = 0;
            Bitmap bmp;

            foreach (string file in Directory.GetFiles(ImagesPath, "*.jpg"))
            {
                bmp = new Bitmap(file);

                width  = Convert.ToInt32(bmp.GetBounds(ref pixel).Width);
                height = Convert.ToInt32(bmp.GetBounds(ref pixel).Height);

                bmp.Dispose();

                if (width != RESOLUTION || height != RESOLUTION)
                {
                    //now apply resolution
                    //parts from https://stackoverflow.com/a/6501997
                    using (Image image = Image.FromFile(file))
                        using (Image newImage = ScaleImage(image, RESOLUTION, RESOLUTION))
                        {
                            image.Dispose();
                            newImage.Save(file, ImageFormat.Jpeg);
                        }
                    scaled++;
                    if (scaled % 100 == 0)
                    {
                        Console.WriteLine("...scaled {0} images so far", scaled);
                    }
                }
            }

            Console.WriteLine("Scaled {0} images", scaled);
            Console.WriteLine("Scaling process has ended");
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 获得指定度量单位下的DPI值
        /// </summary>
        /// <param name="unit">指定的度量单位</param>
        /// <returns>DPI值</returns>
        public static double GetDpi(System.Drawing.GraphicsUnit unit)
        {
            switch (unit)
            {
            case System.Drawing.GraphicsUnit.Display:
                return(fDpi);

            case System.Drawing.GraphicsUnit.Document:
                return(300);

            case System.Drawing.GraphicsUnit.Inch:
                return(1);

            case System.Drawing.GraphicsUnit.Millimeter:
                return(25.4);

            case System.Drawing.GraphicsUnit.Pixel:
                return(fDpi);

            case System.Drawing.GraphicsUnit.Point:
                return(72);
            }
            return(fDpi);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Draws the supplied image with the alpha value specified.
        /// </summary>
        /// <param name="g"></param>
        /// <param name="image"></param>
        /// <param name="destRect"></param>
        /// <param name="srcRect"></param>
        /// <param name="srcUnit"></param>
        /// <param name="alpha">Per-image alpha constant from 0 (Transparent) to 255 (Opaque).</param>
        public static void DrawImageAlpha(this Graphics g, System.Drawing.Image image, System.Drawing.Rectangle destRect, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit, byte alpha)
        {
            using (Graphics g2 = Graphics.FromImage(image))
            {
                NativeMethods.BLENDFUNCTION bf = new NativeMethods.BLENDFUNCTION();
                bf.SourceConstantAlpha = alpha;
                bf.AlphaFormat         = 0;
                IntPtr hdcTarget = g.GetHdc();
                IntPtr hdcSource = g2.GetHdc();

                bool success = NativeMethods.GdiAlphaBlend(hdcTarget, destRect.X, destRect.Y, destRect.Width, destRect.Height, hdcSource, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, ref bf);
                g2.ReleaseHdc(hdcSource);
                g.ReleaseHdc(hdcTarget);
            }
        }
Ejemplo n.º 18
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="metafile"></param>
 /// <param name="bounds"></param>
 /// <param name="grfxUnit"></param>
 public MetafileNode(System.Drawing.Imaging.Metafile metafile, RectangleF bounds, System.Drawing.GraphicsUnit grfxUnit)
 {
     this.metafile = metafile;
     this.Bounds   = bounds;
     this.grfxUnit = grfxUnit;
 }
        public XtraReport GenerateLabelReport(float width, float height, float vPitch, float hPitch, System.Drawing.GraphicsUnit measurementUnit, float bottomMargin, float topMargin, float leftMargin, float rightMargin, int paperKindID)
        {
            CustomLabelReportModel model = new CustomLabelReportModel();

            model.LabelWidth      = width;
            model.LabelHeight     = height;
            model.VerticalPitch   = vPitch;
            model.HorizontalPitch = hPitch;
            model.MeasurementUnit = measurementUnit;
            model.BottomMargin    = bottomMargin;
            model.LeftMargin      = leftMargin;
            model.TopMargin       = topMargin;
            model.RightMargin     = rightMargin;
            model.PaperKindID     = paperKindID;
            return(BuildLabelReport(model));
        }
Ejemplo n.º 20
0
        /// <summary>
        /// 将指定的Twips值转化为指定单位的数值
        /// </summary>
        /// <param name="Twips">Twips值</param>
        /// <param name="unit">要转化的目标单位</param>
        /// <returns>转化的长度值</returns>
        public static double FromTwips(double twips, System.Drawing.GraphicsUnit unit)
        {
            double v = GetUnit(unit);

            return(twips / (v * 1440.0));
        }
Ejemplo n.º 21
0
        /// <summary>
        /// 将指定的Twips值转化为指定单位的数值
        /// </summary>
        /// <param name="Twips">Twips值</param>
        /// <param name="unit">要转化的目标单位</param>
        /// <returns>转化的长度值</returns>
        public static int FromTwips(int Twips, System.Drawing.GraphicsUnit unit)
        {
            double v = GetUnit(unit);

            return(( int )(Twips / (v * 1440)));
        }
Ejemplo n.º 22
0
        /// <summary>
        /// 将指定单位的指定长度转化为 Twips 单位
        /// </summary>
        /// <param name="Value">长度</param>
        /// <param name="unit">度量单位</param>
        /// <returns>转化的 Twips 数</returns>
        public static int ToTwips(float Value, System.Drawing.GraphicsUnit unit)
        {
            double v = GetUnit(unit);

            return((int)(Value * v * 1440));
        }
Ejemplo n.º 23
0
        private void labelTitle_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            const int diameter = 14;
            int       radius   = diameter / 2;
            Rectangle bounds   = labelTitle.Bounds;
            int       offsetY  = 0;

            if (null != this.image)
            {
                offsetY = this.labelTitle.Height - CollapsiblePanel.minTitleHeight;
                if (offsetY < 0)
                {
                    offsetY = 0;
                }
                bounds.Offset(0, offsetY);
                bounds.Height -= offsetY;
            }

            e.Graphics.Clear(this.Parent.BackColor);

            // Create a GraphicsPath with curved top corners
            GraphicsPath path = new GraphicsPath();

            path.AddLine(bounds.Left + radius, bounds.Top, bounds.Right - diameter - 1, bounds.Top);
            path.AddArc(bounds.Right - diameter - 1, bounds.Top, diameter, diameter, 270, 90);
            path.AddLine(bounds.Right, bounds.Top + radius, bounds.Right, bounds.Bottom);
            path.AddLine(bounds.Right, bounds.Bottom, bounds.Left - 1, bounds.Bottom);
            path.AddArc(bounds.Left, bounds.Top, diameter, diameter, 180, 90);

            // Create a colour gradient
            // <feature>Draws the title gradient grayscale when disabled.
            // <version>1.4</version>
            // <date>25-Nov-2002</date>
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            if (true == this.Enabled)
            {
                LinearGradientBrush brush = new LinearGradientBrush(
                    bounds, this.startColour, this.endColour, LinearGradientMode.Horizontal);

                // Paint the colour gradient into the title label.
                e.Graphics.FillPath(brush, path);
            }
            else
            {
                Colour grayStart = new Colour();
                grayStart.CurrentColour = this.startColour;
                grayStart.Saturation    = 0f;
                Colour grayEnd = new Colour();
                grayEnd.CurrentColour = this.endColour;
                grayEnd.Saturation    = 0f;
                LinearGradientBrush brush = new LinearGradientBrush(
                    bounds, grayStart.CurrentColour, grayEnd.CurrentColour,
                    LinearGradientMode.Horizontal);

                // Paint the grayscale gradient into the title label.
                e.Graphics.FillPath(brush, path);
            }
            // </feature>

            // Draw the header icon, if there is one
            System.Drawing.GraphicsUnit graphicsUnit = System.Drawing.GraphicsUnit.Display;
            int offsetX = CollapsiblePanel.iconBorder;

            if (null != this.image)
            {
                offsetX += this.image.Width + CollapsiblePanel.iconBorder;
                // <feature>Draws the title icon grayscale when the panel is disabled.
                // <version>1.4</version>
                // <date>25-Nov-2002</date>
                RectangleF srcRectF = this.image.GetBounds(ref graphicsUnit);
                Rectangle  destRect = new Rectangle(CollapsiblePanel.iconBorder,
                                                    CollapsiblePanel.iconBorder, this.image.Width, this.image.Height);
                if (true == this.Enabled)
                {
                    e.Graphics.DrawImage(this.image, destRect, (int)srcRectF.Left, (int)srcRectF.Top,
                                         (int)srcRectF.Width, (int)srcRectF.Height, graphicsUnit);
                }
                else
                {
                    e.Graphics.DrawImage(this.image, destRect, (int)srcRectF.Left, (int)srcRectF.Top,
                                         (int)srcRectF.Width, (int)srcRectF.Height, graphicsUnit, this.grayAttributes);
                }
                // </feature>
            }

            // Draw the title text.
            SolidBrush textBrush = new SolidBrush(this.TitleFontColour);
            // <feature>Title text truncated with an ellipsis where necessary.
            // <version>1.2</version>
            // <date>18-Oct-2002</date>
            // <source>Nnamdi Onyeyiri (mailto:[email protected])</source>
            float left  = (float)offsetX;
            float top   = (float)offsetY + (float)CollapsiblePanel.expandBorder;
            float width = (float)this.labelTitle.Width - left - this.imageList.ImageSize.Width -
                          CollapsiblePanel.expandBorder;
            float        height    = (float)CollapsiblePanel.minTitleHeight - (2f * (float)CollapsiblePanel.expandBorder);
            RectangleF   textRectF = new RectangleF(left, top, width, height);
            StringFormat format    = new StringFormat();

            format.Trimming = StringTrimming.EllipsisWord;
            // <feature>Draw title text disabled where appropriate.
            // <version>1.4</version>
            // <date>25-Nov-2002</date>
            if (true == this.Enabled)
            {
                e.Graphics.DrawString(labelTitle.Text, labelTitle.Font, textBrush,
                                      textRectF, format);
            }
            else
            {
                Color disabled = SystemColors.GrayText;
                ControlPaint.DrawStringDisabled(e.Graphics, labelTitle.Text, labelTitle.Font,
                                                disabled, textRectF, format);
            }
            // </feature>
            // </feature>

            // Draw a white line at the bottom:
            const int  lineWidth = 1;
            SolidBrush lineBrush = new SolidBrush(Color.White);
            Pen        linePen   = new Pen(lineBrush, lineWidth);

            path.Reset();
            path.AddLine(bounds.Left, bounds.Bottom - lineWidth, bounds.Right,
                         bounds.Bottom - lineWidth);
            e.Graphics.DrawPath(linePen, path);

            // Draw the expand/collapse image
            // <feature>Expand/Collapse image drawn grayscale when panel is disabled.
            // <version>1.4</version>
            // <date>25-Nov-2002</date>
            int        xPos         = bounds.Right - this.imageList.ImageSize.Width - CollapsiblePanel.expandBorder;
            int        yPos         = bounds.Top + CollapsiblePanel.expandBorder;
            RectangleF srcIconRectF = this.ImageList.Images[(int)this.state].GetBounds(ref graphicsUnit);
            Rectangle  destIconRect = new Rectangle(xPos, yPos,
                                                    this.imageList.ImageSize.Width, this.imageList.ImageSize.Height);

            if (true == this.Enabled)
            {
                e.Graphics.DrawImage(this.ImageList.Images[(int)this.state], destIconRect,
                                     (int)srcIconRectF.Left, (int)srcIconRectF.Top, (int)srcIconRectF.Width,
                                     (int)srcIconRectF.Height, graphicsUnit);
            }
            else
            {
                e.Graphics.DrawImage(this.ImageList.Images[(int)this.state], destIconRect,
                                     (int)srcIconRectF.Left, (int)srcIconRectF.Top, (int)srcIconRectF.Width,
                                     (int)srcIconRectF.Height, graphicsUnit, this.grayAttributes);
            }
            // </feature>
        }
Ejemplo n.º 24
0
 /// <summary>
 /// 将一个长度从旧单位换算成新单位使用的比率
 /// </summary>
 /// <param name="NewUnit">新单位</param>
 /// <param name="OldUnit">旧单位</param>
 /// <returns>比率数</returns>
 public static double GetRate(
     System.Drawing.GraphicsUnit NewUnit,
     System.Drawing.GraphicsUnit OldUnit)
 {
     return(GetUnit(OldUnit) / GetUnit(NewUnit));
 }
Ejemplo n.º 25
0
 public static GraphicsUnit ToNPlot(this SD.GraphicsUnit value) => (GraphicsUnit)value;
Ejemplo n.º 26
0
 public void DrawImage(System.Drawing.Image image, System.Drawing.RectangleF destRect, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit graphicsUnit)
 {
     Console.WriteLine("TODD: DrawImage");//throw new NotImplementedException();
 }
Ejemplo n.º 27
0
        protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight)
        {
            object o = this.GetColumnValueAtRow(source, rowNum);

            if (o != null)
            {
                int i = (int)o;
                g.FillRectangle(backBrush, bounds);

                Bitmap bmp = (Bitmap)theImages[i];

                GridImageCellDrawOption cellDrawOption = GridImageCellDrawOption.NoResize;
                //GridImageCellDrawOption cellDrawOption = GridImageCellDrawOption.FitProportionally;
                //GridImageCellDrawOption cellDrawOption = GridImageCellDrawOption.FitToCell;


                System.Drawing.GraphicsUnit gu = System.Drawing.GraphicsUnit.Point;

                RectangleF srcRect  = bmp.GetBounds(ref gu);
                Rectangle  destRect = Rectangle.Empty;

                Region saveRegion = g.Clip;

                int DrawX = bounds.X + (bounds.Width - (int)srcRect.Width) / 2;
                int DrawY = bounds.Y + (bounds.Height - (int)srcRect.Height) / 2;

                destRect = new Rectangle(DrawX, DrawY, (int)srcRect.Width, (int)srcRect.Height);
                g.Clip   = new Region(bounds);

//				switch(cellDrawOption)
//				{
//					case GridImageCellDrawOption.FitToCell:
//						destRect = bounds;
//						break;
//					case GridImageCellDrawOption.NoResize:
//						destRect = new Rectangle(bounds.X, bounds.Y, (int) srcRect.Width, (int) srcRect.Height);
//						g.Clip = new Region(bounds);
//						break;
//					case GridImageCellDrawOption.FitProportionally:
//					{
//						float srcRatio =  srcRect.Width / srcRect.Height;
//						float tarRatio = (float) bounds.Width / bounds.Height;
//						destRect = bounds;
//						if( tarRatio < srcRatio )
//						{
//							destRect.Height = (int) (destRect.Width * srcRatio);
//						}
//						else
//						{
//							destRect.Width = (int) (destRect.Height * srcRatio);
//						}
//					}
//						break;
//
//					default:
//						break;
//				}

                if (!destRect.IsEmpty)
                {
                    g.DrawImage(bmp, destRect, srcRect, gu);
                }

                g.Clip = saveRegion;
            }
        }
Ejemplo n.º 28
0
 public static System.Drawing.Font CreateFont(string fontFile, float fontSize, System.Drawing.FontStyle fontStyle, System.Drawing.GraphicsUnit graphicsUnit, byte gdiCharSet)
 {
     System.Drawing.Text.PrivateFontCollection privateFontCollection = new System.Drawing.Text.PrivateFontCollection();
     privateFontCollection.AddFontFile(fontFile);
     return(new System.Drawing.Font(privateFontCollection.Families[0], fontSize, fontStyle, graphicsUnit, gdiCharSet));
 }
Ejemplo n.º 29
0
        private void labelTitle_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.Clear(this.Parent.BackColor);

            int       radius = diameter / 2;
            Rectangle bounds = labelTitle.Bounds;

            int offsetY = 0;

            if (null != this.image)
            {
                offsetY = this.labelTitle.Height - PanelEx.minTitleHeight;
                if (offsetY < 0)
                {
                    offsetY = 0;
                }
                bounds.Offset(0, offsetY);
                bounds.Height -= offsetY;
            }

            SolidBrush mainBrush  = new SolidBrush(this.BackColor);
            Rectangle  helperRect = bounds;

            helperRect.Offset(new Point(0, helperRect.Height / 2));
            e.Graphics.FillRectangle(mainBrush, helperRect);

            // Create a GraphicsPath with curved top corners
            GraphicsPath path = new GraphicsPath();

            // Top line
            path.AddLine(bounds.Left + radius, bounds.Top, bounds.Right - radius, bounds.Top);
            // Right-upper
            path.AddArc(bounds.Right - diameter, bounds.Top, diameter, diameter, 270, 90);
            // Right line
            path.AddLine(bounds.Right, bounds.Top + radius, bounds.Right, bounds.Bottom - radius);
            // Right-lower
            path.AddArc(bounds.Right - diameter, bounds.Bottom - diameter, diameter, diameter, 0, 90);
            // Bottom line
            path.AddLine(bounds.Right - radius, bounds.Bottom, bounds.Left + radius, bounds.Bottom);
            //path.AddLine(bounds.Right, bounds.Bottom, bounds.Left, bounds.Bottom);
            // Left-lower
            path.AddArc(bounds.Left, bounds.Bottom - diameter, diameter, diameter, 90, 90);
            // Left line
            path.AddLine(bounds.Left, bounds.Bottom - radius, bounds.Left, bounds.Top + radius);
            // Left-upper
            path.AddArc(bounds.Left, bounds.Top, diameter, diameter, 180, 90);

            // Create a colour gradient
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            if (true == this.Enabled)
            {
                LinearGradientBrush brush = new LinearGradientBrush(
                    bounds, this.startColour, this.endColour, LinearGradientMode.Horizontal);

                // Paint the colour gradient into the title label.
                e.Graphics.FillPath(brush, path);
            }
            else
            {
                Color grayStart = new Color();
                grayStart = this.startColour;
                Color grayEnd = new Color();
                grayEnd = this.endColour;
                LinearGradientBrush brush = new LinearGradientBrush(
                    bounds, grayStart, grayEnd,
                    LinearGradientMode.Horizontal);

                // Paint the grayscale gradient into the title label.
                e.Graphics.FillPath(brush, path);
            }

            // Draw the header icon, if there is one
            System.Drawing.GraphicsUnit graphicsUnit = System.Drawing.GraphicsUnit.Display;
            int offsetX = PanelEx.iconBorder;

            if (null != this.image)
            {
                offsetX += this.image.Width + PanelEx.iconBorder;
                // Draws the title icon grayscale when the panel is disabled.
                RectangleF srcRectF = this.image.GetBounds(ref graphicsUnit);
                Rectangle  destRect = new Rectangle(PanelEx.iconBorder,
                                                    PanelEx.iconBorder, this.image.Width, this.image.Height);
                if (true == this.Enabled)
                {
                    e.Graphics.DrawImage(this.image, destRect, (int)srcRectF.Left, (int)srcRectF.Top,
                                         (int)srcRectF.Width, (int)srcRectF.Height, graphicsUnit);
                }
                else
                {
                    e.Graphics.DrawImage(this.image, destRect, (int)srcRectF.Left, (int)srcRectF.Top,
                                         (int)srcRectF.Width, (int)srcRectF.Height, graphicsUnit, this.grayAttributes);
                }
            }

            // Draw the title text.
            SolidBrush textBrush = new SolidBrush(this.TitleFontColour);
            // Title text truncated with an ellipsis where necessary.
            float left  = (float)offsetX + 2 * PanelEx.iconBorder;
            float top   = (float)offsetY + (float)PanelEx.expandBorder;
            float width = (float)this.labelTitle.Width - left - this.imageList.ImageSize.Width -
                          PanelEx.expandBorder;
            float        height    = (float)PanelEx.minTitleHeight - (2f * (float)PanelEx.expandBorder);
            RectangleF   textRectF = new RectangleF(left, top, width, height);
            StringFormat format    = new StringFormat();

            format.Trimming = StringTrimming.EllipsisWord;
            // Draw title text disabled where appropriate.
            if (true == this.Enabled)
            {
                e.Graphics.DrawString(labelTitle.Text, labelTitle.Font, textBrush,
                                      textRectF, format);
            }
            else
            {
                Color disabled = SystemColors.GrayText;
                ControlPaint.DrawStringDisabled(e.Graphics, labelTitle.Text, labelTitle.Font,
                                                disabled, textRectF, format);
            }

            // Draw the expand/collapse image
            if ((null != this.imageList) &&
                (this.imageList.Images.Count >= 2) &&
                drawCollapseExpandIcons
                )
            {
                int        xPos         = bounds.Right - this.imageList.ImageSize.Width - PanelEx.expandBorder;
                int        yPos         = bounds.Top + PanelEx.expandBorder;
                RectangleF srcIconRectF = this.ImageList.Images[(int)this.state].GetBounds(ref graphicsUnit);
                Rectangle  destIconRect = new Rectangle(xPos, yPos,
                                                        this.imageList.ImageSize.Width, this.imageList.ImageSize.Height);
                if (true == this.Enabled)
                {
                    e.Graphics.DrawImage(this.ImageList.Images[(int)this.state], destIconRect,
                                         (int)srcIconRectF.Left, (int)srcIconRectF.Top, (int)srcIconRectF.Width,
                                         (int)srcIconRectF.Height, graphicsUnit);
                }
                else
                {
                    e.Graphics.DrawImage(this.ImageList.Images[(int)this.state], destIconRect,
                                         (int)srcIconRectF.Left, (int)srcIconRectF.Top, (int)srcIconRectF.Width,
                                         (int)srcIconRectF.Height, graphicsUnit, this.grayAttributes);
                }
            }
        }