Pen class.
Inheritance: Respawnable
 protected void Page_Load(object sender, EventArgs e)
 {
     //新建一个Bitmap对象
     using (Bitmap image = new Bitmap(300, 200))
     {
         //根据Bitmap对象创建一个相关的Graphics对象,用于绘制。
         using (Graphics g = Graphics.FromImage(image))
         {
             //调用Graphics的FillRectangle方法来绘制一个矩形。
             g.FillRectangle(Brushes.White, 1, 1, 295, 195);
             //初始化一个字体
             Font font = new Font("Verdana",20, FontStyle.Regular|FontStyle.Bold);
             Pen pen = new Pen(Brushes.Black, 8);
             Rectangle rec=new Rectangle(10, 60, 220, 100);
             //设置SmoothingMode为支持抗锯齿功能
             g.SmoothingMode = SmoothingMode.AntiAlias;
             //为文字添加防锯齿效果
             g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
             g.DrawEllipse(pen,rec);
             g.FillEllipse(Brushes.Green, rec);
             //调用DrawingString方法在画布上绘制文本。
             g.DrawString("使用GDI+绘图", font, Brushes.Silver, 5, 2);
             Image icon = Image.FromFile(Server.MapPath("~/Images/A001.bmp"));
             g.DrawImage(icon, 210, 10, 80, 50);
             //将图像以Gif格式保存到指定的输入二进制流中
             image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
         }
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     Response.Clear();
     Response.ContentType = "image/bmp";
     string st = "",s="";
     Random rnd = new Random();
     Int32 num=0,ch=0;
     for (int i = 0; i < 5; i++)
     {
         ch=rnd.Next(2);
         if (ch == 0)
             num = rnd.Next(65, 91);
         if (ch == 0)
             num = rnd.Next(97, 122);
         else
             num = rnd.Next(48, 57);
         s += (Convert.ToChar(num)).ToString();
         st += (Convert.ToChar(num)).ToString() + " ";
     }
     Session.Add("captcha", s);
     Bitmap bmp = new Bitmap(210, 80);
     Graphics g = Graphics.FromImage(bmp);
     Pen p = new Pen(Color.Aqua);
     HatchBrush br = new HatchBrush(HatchStyle.DottedGrid, Color.Aqua, Color.LightGray);
     SolidBrush b = new SolidBrush(Color.Goldenrod);
     Font f = new Font("Chillar", 36);
     g.FillRectangle(br, new Rectangle(0, 0, 210, 80));
     g.DrawString(st, f, b, new Point(5, 5));
     bmp.Save(Response.OutputStream, ImageFormat.Bmp);
     g.DrawLine(p, 20, 10, 210, 80);
 }
Beispiel #3
0
 public Element(Pen pen, BaseBrush brush)
 {
     Id = Guid.NewGuid().ToString();
     Pen = pen;
     Brush = brush;
     Transform = Transform.Identity;
 }
Beispiel #4
0
 public Pencil(uint colorref)
 {
     fColor = colorref;
     //fPen = new Pen(Guid.NewGuid(), colorref, PenStyle.Solid, PenType.Cosmetic, PenJoinStyle.Round, PenEndCap.Round, 1);
     fPen = new CosmeticPen(PenStyle.Solid, fColor, Guid.NewGuid());
     fDrawingBounds = RECT.Empty;
 }
Beispiel #5
0
 public static void DrawLine(this ICanvas canvas, Point start, Point end, Pen pen)
 {
     var p = new Path { Pen = pen };
     p.MoveTo(start,false);
     p.LineTo(end);
     p.Draw(canvas);
 }
Beispiel #6
0
    public override void Draw()
    {
        base.Draw();

        Pen pen = new Pen (Color.Black);

        int numPoints = 5;
        Point[] pts = new Point[numPoints + 1];
        double rx = width / 2;
        double ry = height / 2;
        double cx = x + rx;
        double cy = y + ry;

        double theta = -Math.PI / 2;
        double dtheta = 4 * Math.PI / numPoints;
        int i;
        for (i = 0; i < numPoints + 1; i++)
        {
            pts [i] = new Point (
                Convert.ToInt32(cx + rx * Math.Cos (theta)),
                Convert.ToInt32(cy + ry * Math.Sin (theta)));
            theta += dtheta;
        }

        this.graphics.DrawPolyLine(pts, this.color);
    }
    /// <summary>
    /// Draws a circle
    /// </summary>
    /// <param name="x">The x coordinate of the square containing this circle</param>
    /// <param name="y">The y coordinate of the square containing this circle</param>
    /// <param name="s">The size (or weight/height) of the circle</param>
    /// <param name="color">The color of the circle border</param>
    public override void DrawCircle(int x, int y, int s, Color color)
    {
        //Create a pen
        Pen pen = new Pen(color);

        Canvas.DrawEllipse(pen, x, y, s, s);
    }
Beispiel #8
0
    public Pen setPen(Cell cell, string side)
    {
        Pen myPen = new Pen(Brushes.Gray, 3);
        if (side == "right" && cell.rightSideIsHighlighted == true)
        {
            myPen.Color = Color.Orange;
            myPen.Width = 6;
        }
        if (side == "bottom" && cell.bottomSideIsHighlighted == true)
        {
            myPen.Color = Color.Orange;
            myPen.Width = 6;
        }

        if (side == "right" && cell.hasRightWall == true)
        {
            myPen.Color = Color.Black;
            myPen.Width = 6;
        }

        if (side == "bottom" && cell.hasBottomWall == true)
        {
            myPen.Color = Color.Black;
            myPen.Width = 6;
        }

        return myPen;
    }
    private void CreateImage()
    {
        Session["captcha.guid"] = Guid.NewGuid().ToString ("N");
        string code = GetRandomText();

        Bitmap bitmap = new Bitmap(WIDTH,HEIGHT,System.Drawing.Imaging.PixelFormat.Format32bppArgb);

        Graphics g = Graphics.FromImage(bitmap);
        Pen pen = new Pen(Color.DarkSlateGray);
        Rectangle rect = new Rectangle(0,0,WIDTH,HEIGHT);

        SolidBrush background = new SolidBrush(Color.AntiqueWhite);
        SolidBrush textcolor = new SolidBrush(Color.DarkSlateGray);

        int counter = 0;

        g.DrawRectangle(pen, rect);
        g.FillRectangle(background, rect);

        for (int i = 0; i < code.Length; i++)
        {
            g.DrawString(code[i].ToString(),
                         new Font("Verdana", 10 + rand.Next(6, 14)),
                         textcolor,
                         new PointF(10 + counter, 10));
            counter += 25;
        }

        DrawRandomLines(g);

        bitmap.Save(Response.OutputStream,ImageFormat.Gif);

        g.Dispose();
        bitmap.Dispose();
    }
Beispiel #10
0
    /// <summary>
    /// Draws a rectangle
    /// </summary>
    /// <param name="p1">The starting point of the line</param>
    /// <param name="p2">The end point of the line</param>
    /// <param name="color">The color of the line</param>
    public override void DrawLine(Point p1, Point p2, Color color)
    {
        //Create a pen
        Pen pen = new Pen(color);

        Canvas.DrawLine(pen, p1, p2);
    }
        public static void Run()
        {
            // ExStart:DrawingUsingGraphics
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_DrawingAndFormattingImages() + "SampleImage_out.bmp";

            // Create an instance of BmpOptions and set its various properties
            BmpOptions imageOptions = new BmpOptions();
            imageOptions.BitsPerPixel = 24;

            // Create an instance of FileCreateSource and assign it to Source property 
            imageOptions.Source = new FileCreateSource(dataDir, false);
            using (var image =  Image.Create(imageOptions, 500, 500))
            {
                var graphics = new Graphics(image);

                // Clear the image surface with white color and Create and initialize a Pen object with blue color
                graphics.Clear(Color.White);                
                var pen = new Pen(Color.Blue);

                // Draw Ellipse by defining the bounding rectangle of width 150 and height 100 also Draw a polygon using the LinearGradientBrush
                graphics.DrawEllipse(pen, new Rectangle(10, 10, 150, 100));
                using (var linearGradientBrush = new LinearGradientBrush(image.Bounds, Color.Red, Color.White, 45f))
                {
                    graphics.FillPolygon(linearGradientBrush, new[] { new Point(200, 200), new Point(400, 200), new Point(250, 350) });
                }
                image.Save();
            }
            // ExEnd:DrawingUsingGraphics
        }
Beispiel #12
0
    /// <summary>
    /// ����ͼƬ
    /// </summary>
    /// <param name="checkCode">�����</param>
    private void CreateImage(string checkCode)
    {
        int iwidth = (int)(checkCode.Length * 11.5);//����������趨ͼƬ���
        Bitmap image = new Bitmap(iwidth, 20);//����һ������
        Graphics g = Graphics.FromImage(image);//�ڻ����϶����ͼ��ʵ��
        Font f = new Font("Arial",10,FontStyle.Bold);//���壬��С����ʽ
        Brush b = new SolidBrush(Color.Black);//������ɫ
        //g.FillRectangle(new System.Drawing.SolidBrush(Color.Blue),0,0,image.Width, image.Height);
        g.Clear(Color.White);//������ɫ
        g.DrawString(checkCode, f, b, 3, 3);

        Pen blackPen = new Pen(Color.Black, 0);
        Random rand = new Random();
        /*�����
        for (int i = 0; i < 5; i++)
        {
            int y = rand.Next(image.Height);
            g.DrawLine(blackPen, 0, y, image.Width, y);
        }
        */
        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
        Response.ClearContent();
        Response.ContentType = "image/Jpeg";
        Response.BinaryWrite(ms.ToArray());
        g.Dispose();
        image.Dispose();
    }
Beispiel #13
0
    public static Rectangle Draw(Pen pen, Form parent)
    {
        sPen = pen;
            // Record the start point
            mPos = parent.PointToClient(Control.MousePosition);
            // Create a transparent form on top of  the parent form
            mMask = new Form();
            mMask.FormBorderStyle = FormBorderStyle.None;
            mMask.BackColor = Color.Magenta;
            mMask.TransparencyKey = mMask.BackColor;

            mMask.ShowInTaskbar = false;
            mMask.StartPosition = FormStartPosition.Manual;
            mMask.Size = parent.ClientSize;
            mMask.Location = parent.PointToScreen(Point.Empty);
            mMask.MouseMove += MouseMove;
            mMask.MouseUp += MouseUp;
            mMask.Paint += PaintRectangle;
            mMask.Load += DoCapture;
            // Display the overlay
            mMask.ShowDialog(parent);
            // Clean-up and calculate return value
            mMask.Dispose();
            mMask = null;
            Point pos = parent.PointToClient(Control.MousePosition);
            int x = Math.Min(mPos.X, pos.X);
            int y = Math.Min(mPos.Y, pos.Y);
            int w = Math.Abs(mPos.X - pos.X);
            int h = Math.Abs(mPos.Y - pos.Y);

            return new Rectangle(x, y, w, h);
    }
Beispiel #14
0
        /// <summary>
        ///     Initializes a new Player class.
        /// </summary>
        /// <param name="texture">The Texture.</param>
        /// <param name="texture2">The ErasedTexture.</param>
        public Player(Texture2D texture, Texture2D texture2)
        {
            _erased = texture2;
            Bounds = new Polygon(new Vector2(1, 6), new Vector2(5, 4), new Vector2(11, 0), new Vector2(22, 0), new Vector2(28, 6),
                new Vector2(28, 11), new Vector2(31, 15), new Vector2(28, 21), new Vector2(19, 21), new Vector2(18, 23),
                new Vector2(9, 23), new Vector2(0, 13), new Vector2(1, 7));
            _pen = new Pen(Color.White, 1);
            _spriteSheet = new AnimatedSpriteSheet(texture) {AutoUpdate = true};
            _spriteSheet.Add(new Keyframe(new Rectangle(0, 0, 32, 24), 100));
            _spriteSheet.Add(new Keyframe(new Rectangle(32, 0, 32, 24), 100));
            _spriteSheet.Add(new Keyframe(new Rectangle(64, 0, 32, 24), 100));
            _spriteSheet.Add(new Keyframe(new Rectangle(96, 0, 32, 24), 100));
            _spriteSheet.Add(new Keyframe(new Rectangle(128, 0, 32, 24), 100));
            _spriteSheet.Add(new Keyframe(new Rectangle(160, 0, 32, 24), 100));
            _spriteSheet.Add(new Keyframe(new Rectangle(192, 0, 32, 24), 100));

            _spriteSheet.Add(new Keyframe(new Rectangle(224, 0, 32, 24), 100));
            _spriteSheet.Add(new Keyframe(new Rectangle(256, 0, 32, 24), 100));
            _spriteSheet.Add(new Keyframe(new Rectangle(288, 0, 32, 24), 100));
            _spriteSheet.Add(new Keyframe(new Rectangle(320, 0, 32, 24), 100));
            _spriteSheet.Add(new Keyframe(new Rectangle(352, 0, 32, 24), 100));

            Position = new Vector2(300, 230);
            Velocity = new Vector2(0, 0);
        }
Beispiel #15
0
		public void SetDashStyle (Pen widget, DashStyle dashStyle)
		{
			var swmpen = (swm.Pen)widget.ControlObject;
			if (dashStyle == null || dashStyle.IsSolid)
				swmpen.DashStyle = swm.DashStyles.Solid;
			else {
				var dashes = dashStyle.Dashes;
				double[] wpfdashes;
				if (swmpen.DashCap == swm.PenLineCap.Flat)
					wpfdashes = Array.ConvertAll (dashStyle.Dashes, x => (double)x);
				else {
					wpfdashes = new double[dashes.Length];
					for (int i = 0; i < wpfdashes.Length; i++) {
						var dash = (double)dashes[i];
						if ((i % 2) == 1) {
							// gap must include square/round thickness
							dash += 1;
						} else {
							// dash must exclude square/round thickness
							dash -= 1;
						}
						wpfdashes[i] = dash;
					}
				}
				swmpen.DashStyle = new swm.DashStyle (wpfdashes, dashStyle.Offset);
			}
		}
Beispiel #16
0
    public Star(int x, int y, int width, int height)
    {
        Pen pen = new Pen (Color.Black);

        int numPoints = 5;
        Point[] pts = new Point[numPoints];
        double rx = width / 2;
        double ry = height / 2;
        double cx = x + rx;
        double cy = y + ry;

        double theta = -Math.PI / 2;
        double dtheta = 4 * Math.PI / numPoints;
        int i;
        for (i = 0; i < numPoints; i++)
        {
            pts [i] = new Point (Convert.ToInt32(cx + rx * Math.Cos (theta)),
                                 Convert.ToInt32(cy + ry * Math.Sin (theta)));
            theta += dtheta;
        }

        for (i = 0; i < numPoints; i++)
        {
            Geo l;
            Geometrie.Add(l = new Line(pts[i].X,
                                        pts[i].Y,
                                        pts[(i+1) % numPoints].X,
                                        pts[(i+1) % numPoints].Y));
        }
    }
Beispiel #17
0
		public void SetLineCap (Pen widget, PenLineCap lineCap)
		{
			var pen = widget.ToSD ();
			pen.StartCap = pen.EndCap = lineCap.ToSD ();
			pen.DashCap = lineCap == PenLineCap.Round ? sd2.DashCap.Round : sd2.DashCap.Flat;
			SetDashStyle (widget, widget.DashStyle);
		}
    private void CreateImage()
    {
        string code = GetRandomText();

        Bitmap bitmap = new Bitmap(200, 50, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

        Graphics g = Graphics.FromImage(bitmap);
        Pen pen = new Pen(Color.Yellow);
        Rectangle rect = new Rectangle(0, 0, 200, 50);

        SolidBrush b = new SolidBrush(Color.Black);
        SolidBrush blue = new SolidBrush(Color.Blue);

        int counter = 0;

        g.DrawRectangle(pen, rect);
        g.FillRectangle(b, rect);

        for (int i = 0; i < code.Length; i++)
        {
            g.DrawString(code[i].ToString(), new Font("Verdena", 10 + rand.Next(14, 18)), blue, new PointF(10 + counter, 10));
            counter += 20;
        }

        DrawRandomLines(g);

        bitmap.Save(Response.OutputStream, ImageFormat.Gif);

        g.Dispose();
        bitmap.Dispose();
    }
Beispiel #19
0
    protected override void OnPaint(PaintEventArgs pevent)
    {
        var g = pevent.Graphics;
        g.SmoothingMode = SmoothingMode.AntiAlias;
        g.Clear(Parent.BackColor);

        var checkMarkLine = new Rectangle(1, 1, 16, 16);
        var checkmarkPath = DrawHelper.CreateRoundRect(1, 1, 17, 17, 1);

        EnabledCheckedColor = HexColor;
        SolidBrush BG = new SolidBrush(Enabled ? Checked ? EnabledCheckedColor : EnabledUnCheckedColor : DisabledColor);
        Pen Pen = new Pen(BG.Color);

        g.FillPath(BG, checkmarkPath);
        g.DrawPath(Pen, checkmarkPath);

        g.SmoothingMode = SmoothingMode.None;
        g.FillRectangle(new SolidBrush(Color.White), PointAnimationNum, PointAnimationNum, SizeAnimationNum, SizeAnimationNum);
        g.SmoothingMode = SmoothingMode.AntiAlias;
      
        //CheckMark
        g.DrawImageUnscaledAndClipped(CheckMarkBitmap(), checkMarkLine);
        
        //CheckBox Text
        g.DrawString(Text, font.Roboto_Medium10, new SolidBrush(Enabled ? EnabledStringColor : DisabledStringColor), 21, 0);
    }
        protected internal override void RenderRectangle(Bitmap bmp, Pen pen, int x, int y, int width, int height)
        {
            Color outlineColor = (pen != null) ? pen.Color : (Color)0x0;
            ushort outlineThickness = (pen != null) ? pen.Thickness : (ushort)0;

            int x1, y1;
            int x2, y2;

            switch (MappingMode)
            {
                case BrushMappingMode.RelativeToBoundingBox:
                    x1 = x + (int)((long)(width - 1) * StartX / RelativeBoundingBoxSize);
                    y1 = y + (int)((long)(height - 1) * StartY / RelativeBoundingBoxSize);
                    x2 = x + (int)((long)(width - 1) * EndX / RelativeBoundingBoxSize);
                    y2 = y + (int)((long)(height - 1) * EndY / RelativeBoundingBoxSize);
                    break;
                default: //case BrushMappingMode.Absolute:
                    x1 = StartX;
                    y1 = StartY;
                    x2 = EndX;
                    y2 = EndY;
                    break;
            }

            bmp.DrawRectangle((MSMedia.Color)outlineColor, outlineThickness, x, y, width, height, 0, 0, (MSMedia.Color)StartColor, x1, y1, (MSMedia.Color)EndColor, x2, y2, Opacity);
        }
        private static Boolean pensAreEqual(Pen p1, Pen p2)
        {
            if (ReferenceEquals(p1, p2))
            {
                return true;
            }

            if (p1 == null || p2 == null)
            {
                return false;
            }

            if (p1.Alignment != p2.Alignment) return false;
            if (!brushesAreEqual(p1.Brush, p2.Brush)) return false;
            if (p1.Color != p2.Color) return false;
            if (!elementsAreEqual(p1.CompoundArray, p2.CompoundArray)) return false;
            if (p1.DashStyle == DashStyle.Custom && p1.CustomEndCap != p2.CustomEndCap) return false;
            if (p1.DashStyle == DashStyle.Custom && p1.CustomStartCap != p2.CustomStartCap) return false;
            if (p1.DashCap != p2.DashCap) return false;
            if (p1.DashOffset != p2.DashOffset) return false;
            if (p1.DashStyle == DashStyle.Custom && !elementsAreEqual(p1.DashPattern, p2.DashPattern)) return false;
            if (p1.DashStyle != p2.DashStyle) return false;
            if (p1.EndCap != p2.EndCap) return false;
            if (p1.LineJoin != p2.LineJoin) return false;
            if (p1.MiterLimit != p2.MiterLimit) return false;
            if (p1.PenType != p2.PenType) return false;
            if (p1.StartCap != p2.StartCap) return false;
            if (!elementsAreEqual(p1.Transform.Elements, p2.Transform.Elements)) return false;
            if (p1.Width != p2.Width) return false;

            return true;
        }
Beispiel #22
0
 /// <summary>
 /// Initializes a new VectorStyle and sets the default values
 /// </summary>
 /// <remarks>
 /// Default style values when initialized:<br/>
 /// *LineStyle: 1px solid black<br/>
 /// *FillStyle: Solid black<br/>
 /// *Outline: No Outline
 /// *Symbol: null-reference
 /// </remarks>
 public VectorStyle()
 {
     Outline = new Pen(Color.Black, 1);
     Line = new Pen(Color.Black, 1);
     Fill = Brushes.Black;
     EnableOutline = false;
     SymbolScale = 1f;
 }
Beispiel #23
0
 public static void DrawMultiLineString(Graphics g, IMultiLineString lines, Pen pen, Map map, float offset)
 {
     for(var i = 0; i < lines.NumGeometries; i++)
     {
         var line = (ILineString) lines[i];
         DrawLineString(g, line, pen, map, offset);
     }
 }
Beispiel #24
0
 public override void Draw(Graphics Canvas)
 {
     Pen pen = new Pen(Color.Black);
     Canvas.DrawLine(pen, pts[0].X, pts[0].Y, pts[1].X, pts[1].Y);
     Canvas.DrawLine(pen, pts[1].X, pts[1].Y, pts[2].X, pts[2].Y);
     Canvas.DrawLine(pen, pts[2].X, pts[2].Y, pts[3].X, pts[3].Y);
     Canvas.DrawLine(pen, pts[3].X, pts[3].Y, pts[0].X, pts[0].Y);
 }
Beispiel #25
0
    public NSButton()
    {
        SetStyle((ControlStyles)139286, true);
        SetStyle(ControlStyles.Selectable, false);

        P1 = new Pen(Color.FromArgb(35, 35, 35));
        P2 = new Pen(Color.FromArgb(65, 65, 65));
    }
Beispiel #26
0
        public LineTool(uint colorref)
            :base(2)
        {
            fColor = colorref;
            fPen = new CosmeticPen(PenStyle.Solid, fColor, Guid.NewGuid());

            base.PointsAvailableEvent += new OnPointArrayToolFinished(DigitizerFinished);
        }
        protected internal override void RenderEllipse(Bitmap bmp, Pen pen, int x, int y, int xRadius, int yRadius)
        {
            Color outlineColor = (pen != null) ? pen.Color : (Color)0x0;
            ushort outlineThickness = (pen != null) ? pen.Thickness : (ushort)0;

            if (bmp != null)
                bmp.DrawEllipse((MSMedia.Color)outlineColor, outlineThickness, x, y, xRadius, yRadius, (MSMedia.Color)Color, 0, 0, (MSMedia.Color)Color, 0, 0, Opacity);
        }
	// Constructor.
	public DrawingPen(IToolkit toolkit, Pen properties) : base(properties.Color, (int)properties.Width)
			{
				this.toolkit = toolkit;
				this.properties = properties;
				//TODO: Rest of the properties
				win32Color = DrawingGraphics.ColorToWin32(properties.Color);
				hPen = Win32.Api.CreatePen((int)properties.DashStyle, (int)properties.Width, win32Color);
			}
Beispiel #29
0
 public Text(string text, Rect frame, Font font, TextAlignment alignment = TextAlignment.Left, Pen pen = null, BaseBrush brush = null)
     : base(pen, brush)
 {
     String = text;
     Frame = frame;
     Font = font;
     Alignment = alignment;
 }
Beispiel #30
0
 // Use this for initialization
 protected void Initialize(string imageName)
 {
     isPushed = false;
     penScript = GameObject.Find ("Pen").GetComponent<Pen> ();
     SetTexture (imageName);
     transform.localScale = new Vector3 (rate,rate,1f);
     ButtonAnimation.SetAnimation (transform, "", "button_click02");
 }
Beispiel #31
0
 public void DrawPolygon(Pen pen, Point[] points)
 {
     graphics.DrawPolygon(PenToXPen(pen), points);
 }
Beispiel #32
0
 public void DrawPath(Pen pen, GraphicsPath path)
 {
     graphics.DrawPath(PenToXPen(pen), GraphicsPathToXGraphicsPath(path));
 }
        /// <summary>
        /// Method responsible for drawing inter link peptide
        /// </summary>
        /// <param name="peptide1"></param>
        /// <param name="peptide2"></param>
        /// <param name="anotationAlfa"></param>
        /// <param name="anotationBeta"></param>
        /// <param name="xlPos1"></param>
        /// <param name="xlPos2"></param>
        public void DrawInterLink(string peptide1, string peptide2, string anotationAlfa, string anotationBeta, int xlPos1, int xlPos2)
        {
            #region Setting Values
            Peptide1      = peptide1;
            Peptide2      = peptide2;
            AnotationAlfa = anotationAlfa;
            AnotationBeta = anotationBeta;
            XlPos1        = xlPos1;
            XlPos2        = xlPos2;
            #endregion

            imageBuffer          = new Bitmap(panelAnotator.Width, panelAnotator.Height);
            graphicsPeptAnotator = Graphics.FromImage(imageBuffer);
            graphicsPeptAnotator.Clear(Color.White);

            double xLastPosPept1 = 0.0;
            double xLastPosPept2 = 0.0;
            double yLastPosPept1 = 0.0;
            double yLastPosPept2 = 0.0;

            //Getting Series b and y
            List <AnnotationItem> myAnnotationsAlfa = ParseAnnotation(anotationAlfa);
            List <AnnotationItem> myAnnotationsBeta = ParseAnnotation(anotationBeta);
            //Setting font
            Font f = new System.Drawing.Font("Courier New", FONTSIZE);

            #region Calculating offset
            //Find out who will get an offset
            int DeltaXLOffset = xlPos1 - xlPos2;
            if (xlPos1 > xlPos2)
            {
                //Add spaces to peptide 2
                for (int i = 0; i < DeltaXLOffset; i++)
                {
                    peptide2 = " " + peptide2;
                }
                xlPos2 += DeltaXLOffset;
            }
            else if (xlPos2 > xlPos1)
            {
                //Add spaces to peptide 1
                for (int i = 0; i < Math.Abs(DeltaXLOffset); i++)
                {
                    peptide1 = " " + peptide1;
                }
                xlPos1 += Math.Abs(DeltaXLOffset);
            }
            #endregion

            #region Writing peptides

            using (graphicsPeptAnotator)
            {
                graphicsPeptAnotator.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

                //Draw Peptide 1
                for (int i = 0; i < peptide1.Length; i++)
                {
                    graphicsPeptAnotator.DrawString(peptide1[i].ToString(), f, Brushes.Green, new Point((i * SPACER) + X1OFFSET, Y1OFFSET));

                    //Write the b series
                    int increment = 0;
                    if (xlPos2 - DeltaXLOffset > xlPos1)
                    {
                        increment = Math.Abs(DeltaXLOffset);
                    }

                    if (myAnnotationsAlfa.Exists(a => a.Series.Equals("b") && a.IonNo == i - increment))
                    {
                        DrawLeftBreak((i * SPACER) + X1OFFSET + 2, 4 + Y1OFFSET);
                    }

                    //Write the y series
                    if (myAnnotationsAlfa.Exists(a => a.Series.Equals("y") && a.IonNo == i - increment))
                    {
                        DrawRightBreak(((peptide1.Length - (i - increment)) * SPACER) + X1OFFSET + 2, 4 + Y1OFFSET);
                    }
                }
                xLastPosPept1 = ((peptide1.Length - 1) * SPACER) + X1OFFSET;
                yLastPosPept1 = Y1OFFSET + FONTSIZE + 4;

                //Draw Peptide 2
                for (int i = 0; i < peptide2.Length; i++)
                {
                    int increment = 0;
                    if (xlPos1 - DeltaXLOffset < xlPos2)
                    {
                        increment = DeltaXLOffset;
                    }

                    if (myAnnotationsBeta.Exists(a => a.Series.Equals("b") && a.IonNo == i - increment))
                    {
                        DrawLeftBreak((i * SPACER) + X1OFFSET + 2, Y1OFFSET + (3 * FONTSIZE) - 2);
                    }

                    //Write the y series
                    if (myAnnotationsBeta.Exists(a => a.Series.Equals("y") && a.IonNo == i - increment))
                    {
                        DrawRightBreak(((peptide2.Length - (i - increment)) * SPACER) + X1OFFSET + 2, Y1OFFSET + (3 * FONTSIZE) - 2);
                    }

                    graphicsPeptAnotator.DrawString(peptide2[i].ToString(), f, Brushes.Green, new Point((i * SPACER) + X1OFFSET, Y1OFFSET + (3 * FONTSIZE) - 5));
                }
                xLastPosPept2 = ((peptide2.Length - 1) * SPACER) + X1OFFSET;
                yLastPosPept2 = Y1OFFSET + FONTSIZE + 4;

                //Draw the Interlinker
                Pen p = new Pen(Brushes.Black);
                p.Width = 3;
                Point p1 = new Point(((xlPos1 - 1) * SPACER) + X1OFFSET + (FONTSIZE / 2) + 2, Y1OFFSET + FONTSIZE + 5);
                Point p2 = new Point(((xlPos1 - 1) * SPACER) + X1OFFSET + (FONTSIZE / 2) + 2, Y1OFFSET + FONTSIZE + (2 * FONTSIZE));
                graphicsPeptAnotator.DrawLine(p, p1, p2);
            }
            #endregion

            int       newHeightRect = (int)(yLastPosPept1 + yLastPosPept2 + (2 * FONTSIZE));
            int       newWidthRect  = (int)(xLastPosPept1 > xLastPosPept2 ? xLastPosPept1 : xLastPosPept2);
            Rectangle cropRect      = new Rectangle(0, 0, newWidthRect + FONTSIZE, newHeightRect);
            imageBuffer = this.CropImage(imageBuffer, cropRect);
            panelAnotator.BackgroundImage = imageBuffer;
        }
 public void DrawLines(Pen P, PointF[] Points)
 {
     G.DrawLines(P, Points);
 }
Beispiel #35
0
 public Rectangle(Pen p, int x1, int y1) : base(p, x1, y1)
 {
 }
 public void DrawLine(Pen P, PointF p1, PointF p2)
 {
     DrawLine(P, p1.X, p1.Y, p2.X, p2.Y);
 }
Beispiel #37
0
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.SmoothingMode     = SmoothingMode.HighQuality;
            e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;

            float down = 0.0f;

            // Colors and brushes
            Pen brushBorder                = null;
            LinearGradientMode  mode       = LinearGradientMode.Vertical;
            LinearGradientBrush brushOuter = null;
            LinearGradientBrush brushInner = null;

            Rectangle newRect    = new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 1);
            Color     text_color = Color.White;

            if (Enabled)
            {
                if (base.Focused)
                {
                    brushBorder = new Pen(Color.FromArgb(24, 24, 24), 1f);
                }
                else
                {
                    brushBorder = new Pen(Color.FromArgb(56, 56, 56), 1f);
                }

                switch (m_State)
                {
                case eButtonState.Normal:
                    brushOuter = new LinearGradientBrush(newRect, Color.FromArgb(123, 123, 123), Color.FromArgb(77, 77, 77), mode);
                    brushInner = new LinearGradientBrush(newRect, Color.FromArgb(104, 104, 104), Color.FromArgb(71, 71, 71), mode);
                    e.Graphics.FillRectangle(brushOuter, newRect);
                    newRect.Inflate(-1, -1);
                    e.Graphics.FillRectangle(brushInner, newRect);
                    newRect.Inflate(1, 1);

                    e.Graphics.DrawLine(brushBorder, new Point(0, 0), new Point(this.Width, this.Height));
                    e.Graphics.DrawLine(brushBorder, new Point(this.Width, 0), new Point(0, this.Height));
                    break;

                case eButtonState.MouseOver:
                    brushOuter = new LinearGradientBrush(newRect, Color.FromArgb(140, 140, 140), Color.FromArgb(87, 87, 87), mode);
                    brushInner = new LinearGradientBrush(newRect, Color.FromArgb(118, 118, 118), Color.FromArgb(81, 81, 81), mode);
                    e.Graphics.FillRectangle(brushOuter, newRect);
                    newRect.Inflate(-1, -1);
                    e.Graphics.FillRectangle(brushInner, newRect);
                    newRect.Inflate(1, 1);

                    e.Graphics.DrawLine(brushBorder, new Point(0, 0), new Point(this.Width, this.Height));
                    e.Graphics.DrawLine(brushBorder, new Point(this.Width, 0), new Point(0, this.Height));

                    break;

                case eButtonState.Down:
                    down       = 1.0f;
                    brushOuter = new LinearGradientBrush(newRect, Color.FromArgb(108, 108, 108), Color.FromArgb(68, 68, 68), mode);
                    brushInner = new LinearGradientBrush(newRect, Color.FromArgb(92, 92, 92), Color.FromArgb(62, 62, 62), mode);
                    e.Graphics.FillRectangle(brushOuter, newRect);
                    newRect.Inflate(-1, -1);
                    e.Graphics.FillRectangle(brushInner, newRect);
                    newRect.Inflate(1, 1);


                    e.Graphics.DrawLine(brushBorder, new Point(0, 0), new Point(this.Width, this.Height));
                    e.Graphics.DrawLine(brushBorder, new Point(this.Width, 0), new Point(0, this.Height));

                    break;
                }

                e.Graphics.DrawRectangle(brushBorder, newRect);
            }
            else
            {
                text_color  = Color.FromArgb(110, 110, 110);
                brushBorder = new Pen(Color.FromArgb(48, 48, 48), 1f);
                brushOuter  = new LinearGradientBrush(newRect, Color.FromArgb(82, 82, 82), Color.FromArgb(67, 67, 67), mode);
                brushInner  = new LinearGradientBrush(newRect, Color.FromArgb(76, 76, 76), Color.FromArgb(65, 65, 65), mode);
                e.Graphics.FillRectangle(brushOuter, newRect);
                newRect.Inflate(-1, -1);
                e.Graphics.FillRectangle(brushInner, newRect);
                newRect.Inflate(1, 1);
                e.Graphics.DrawRectangle(brushBorder, newRect);


                e.Graphics.DrawLine(brushBorder, new Point(0, 0), new Point(this.Width, this.Height));
                e.Graphics.DrawLine(brushBorder, new Point(this.Width, 0), new Point(0, this.Height));
            }


            string largetext = this.Text;

            SizeF szL = e.Graphics.MeasureString(this.Text, base.Font, this.Width);

            if (Enabled)
            {
                e.Graphics.DrawString(largetext, base.Font, Brushes.Black,
                                      new RectangleF(new PointF((this.Width - szL.Width) / 2, (this.Height - szL.Height) / 2 + 1 + down), szL));
            }
            e.Graphics.DrawString(largetext, base.Font, new SolidBrush(text_color),
                                  new RectangleF(new PointF((this.Width - szL.Width) / 2, (this.Height - szL.Height) / 2 + down), szL));

            Pen pen = new Pen(new SolidBrush(text_color));

            //e.Graphics.DrawLine(pen, new Point(0, 0), new Point(this.Width, this.Height));
            //e.Graphics.DrawLine(pen, new Point(this.Width, 0), new Point(0, this.Height));

            brushOuter.Dispose();
            brushInner.Dispose();
            brushBorder.Dispose();
        }
 private void DrawButton(string message, Rectangle rect, Brush foregroundBrush, Pen backgroundPen, Brush backgroundBrush)
 {
     paintbrush.FillRectangle(backgroundBrush, rect);
     paintbrush.DrawRectangle(backgroundPen, rect);
     paintbrush.DrawRectangle(backgroundPen, new Rectangle(rect.X + 2, rect.Y + 2, rect.Width - 4, rect.Height - 4));
     paintbrush.DrawString(message, Font, Brushes.White, rect.X + rect.Width / 2 - (int)(message.Length * Font.Size / 2) / 2 + 1, rect.Y + rect.Height / 2 - (int)(Font.Size / 2) + 1);
     paintbrush.DrawString(message, Font, foregroundBrush, rect.X + rect.Width / 2 - (int)(message.Length * Font.Size / 2) / 2, rect.Y + rect.Height / 2 - (int)(Font.Size / 2));
 }
Beispiel #39
0
        internal void RenderBackgroundInternal(
            Graphics g,
            Rectangle rect,
            Color baseColor,
            Color borderColor,
            Color innerBorderColor,
            float basePosition,
            bool drawBorder,
            LinearGradientMode mode)
        {
            if (drawBorder)
            {
                rect.Width--;
                rect.Height--;
            }
            using (LinearGradientBrush brush = new LinearGradientBrush(
                       rect, Color.Transparent, Color.Transparent, mode))
            {
                Color[] colors = new Color[4];
                colors[0] = GetColor(baseColor, 0, 35, 24, 9);
                colors[1] = GetColor(baseColor, 0, 13, 8, 3);
                colors[2] = baseColor;
                colors[3] = GetColor(baseColor, 0, 68, 69, 54);

                ColorBlend blend = new ColorBlend();
                blend.Positions           = new float[] { 0.0f, basePosition, basePosition + 0.05f, 1.0f };
                blend.Colors              = colors;
                brush.InterpolationColors = blend;
                g.FillRectangle(brush, rect);
            }
            if (baseColor.A > 80)
            {
                Rectangle rectTop = rect;
                if (mode == LinearGradientMode.Vertical)
                {
                    rectTop.Height = (int)(rectTop.Height * basePosition);
                }
                else
                {
                    rectTop.Width = (int)(rect.Width * basePosition);
                }
                using (SolidBrush brushAlpha =
                           new SolidBrush(Color.FromArgb(80, 255, 255, 255)))
                {
                    g.FillRectangle(brushAlpha, rectTop);
                }
            }

            if (drawBorder)
            {
                using (Pen pen = new Pen(borderColor))
                {
                    g.DrawRectangle(pen, rect);
                }

                rect.Inflate(-1, -1);
                using (Pen pen = new Pen(innerBorderColor))
                {
                    g.DrawRectangle(pen, rect);
                }
            }
        }
Beispiel #40
0
        /********************************************************************************************************
         *
         *     以下都是辅助绘图的静态方法
         *
         *
         *
         *
         ***********************************************************************************************************/

        /// <summary>
        /// 获取一个直方图
        /// </summary>
        /// <param name="array">数据数组</param>
        /// <param name="width">宽度</param>
        /// <param name="height">高度</param>
        /// <param name="degree">刻度划分等级</param>
        /// <param name="lineColor">线条颜色</param>
        /// <returns></returns>
        public static Bitmap GetGraphicFromArray(int[] array, int width, int height, int degree, Color lineColor)
        {
            if (width < 10 && height < 10)
            {
                throw new ArgumentException("长宽不能小于等于10");
            }
            int Max   = array.Max();
            int Min   = 0;
            int Count = array.Length;

            StringFormat sf = new StringFormat();

            sf.Alignment = StringAlignment.Far;
            Pen dash = new Pen(Color.LightGray, 1f);

            dash.DashStyle   = System.Drawing.Drawing2D.DashStyle.Custom;
            dash.DashPattern = new float[] { 5, 5 };

            Font     font_8 = new Font("宋体", 9f);
            Bitmap   bitmap = new Bitmap(width, height);
            Graphics g      = Graphics.FromImage(bitmap);

            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            g.Clear(Color.White);
            //计算边框长度及图像边距
            int left = 60, right = 8, up = 8, down = 8;
            int paint_width = width - left - right;
            int paint_heigh = height - up - down;

            Rectangle rect = new Rectangle(left - 1, up - 1, paint_width + 1, paint_heigh + 1);

            //g.FillRectangle(Brushes.WhiteSmoke, rect);
            g.DrawLine(Pens.Gray, left - 1, up, left + paint_width + 1, up);
            g.DrawLine(Pens.Gray, left - 1, up + paint_heigh + 1, left + paint_width + 1, up + paint_heigh + 1);
            g.DrawLine(Pens.Gray, left - 1, up - 1, left - 1, up + paint_heigh + 1);

            //画刻度
            //for (int i = 0; i <= degree; i++)
            //{
            //    int value = (Max - Min) * i / degree + Min;
            //    int location = (int)ComputePaintLocationY(Max, Min, paint_heigh, value) + up + 1;
            //    g.DrawLine(Pens.DimGray, left - 1, location, left - 4, location);
            //    if (i != 0 && i < degree)
            //    {
            //        g.DrawLine(dash, left, location, width - right, location);
            //    }
            //    g.DrawString(value.ToString(), font_8, Brushes.DimGray, new Rectangle(-5, location - 4, left, 10), sf);
            //}

            PaintCoordinateDivide(g, Pens.DimGray, dash, font_8, Brushes.DimGray, sf, degree, Max, Min, width, height, left, right, up, down);


            PointF[] alldata = new PointF[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                alldata[i].X = paint_width * 1.0f / (array.Length - 1) * i + left;
                alldata[i].Y = ComputePaintLocationY(Max, Min, paint_heigh, array[i]) + up + 1;
            }

            Pen pen = new Pen(lineColor);

            g.DrawLines(pen, alldata);

            pen.Dispose();
            dash.Dispose();
            font_8.Dispose();
            sf.Dispose();
            g.Dispose();
            return(bitmap);
        }
Beispiel #41
0
 public Pen fPenInfo(Color oColor)
 {
     _Pen = new Pen(oColor);
     return(_Pen);
 }
Beispiel #42
0
        private void RefreshHUD()
        {
            float  life   = lifePercentage.ClampPercentage();
            float  mana   = manaPercentage.ClampPercentage();
            Bitmap bitmap = new Bitmap(pictureBox.Size.Width, pictureBox.Size.Height);

            int width  = bitmap.Width;
            int height = bitmap.Height;

            using (Graphics gr = Graphics.FromImage(bitmap)) {
                // we set the interpolation mode to nearest neighbor because other interpolation modes modify the colors
                // which causes the transparency key to appear around the edges of the object

                gr.Clear(StyleManager.BlendTransparencyKey);
                Rectangle lifeRectangle = new Rectangle();
                lifeRectangle.X      = (int)(height * 0.7);
                lifeRectangle.Y      = (int)(height * 0.15) - 2;
                lifeRectangle.Width  = width - lifeRectangle.X;
                lifeRectangle.Height = (int)(height * 0.2) + 4;

                gr.FillRectangle(Brushes.Black, lifeRectangle);
                lifeRectangle.Y      += 2;
                lifeRectangle.Height -= 4;
                lifeRectangle.Width   = (int)(lifeRectangle.Width * life) - 2;
                using (Brush brush = new SolidBrush(StyleManager.GetHealthColor(life))) {
                    gr.FillRectangle(brush, lifeRectangle);
                }

                Rectangle manaRectangle = new Rectangle();
                manaRectangle.X      = (int)(height * 0.7);
                manaRectangle.Y      = (int)(height * 0.15) - 2 + lifeRectangle.Height + 2;
                manaRectangle.Width  = (int)((width - lifeRectangle.X) * 0.95);
                manaRectangle.Height = (int)(height * 0.2) + 4;

                gr.FillRectangle(Brushes.Black, manaRectangle);
                manaRectangle.Y      += 2;
                manaRectangle.Height -= 4;
                manaRectangle.Width   = (int)(manaRectangle.Width * mana) - 2;
                using (Brush brush = new SolidBrush(StyleManager.ManaColor)) {
                    gr.FillRectangle(brush, manaRectangle);
                }

                int backgroundSize       = (int)(height * backgroundScale / 100.0);
                int backgroundBaseOffset = (height - backgroundSize) / 2;
                int centerSize           = (int)(height * centerScale / 100.0);
                int centerBaseOffset     = (height - centerSize) / 2;

                SummaryForm.RenderImageResized(gr, backgroundImage, new Rectangle(backgroundBaseOffset + backgroundOffset.X, backgroundBaseOffset + backgroundOffset.Y, backgroundSize, backgroundSize));
                SummaryForm.RenderImageResized(gr, centerImage, new Rectangle(centerBaseOffset + centerOffset.X, centerBaseOffset + centerOffset.Y, centerSize, centerSize));

                Rectangle levelRect = new Rectangle((int)(height * 0.7), (int)(height * 0.6), (int)(height * 0.35), (int)(height * 0.35));
                using (Brush brush = new SolidBrush(StyleManager.MainFormButtonColor)) {
                    gr.FillEllipse(brush, levelRect);
                }
                using (Pen pen = new Pen(StyleManager.MainFormButtonForeColor, 2)) {
                    gr.DrawEllipse(pen, levelRect);
                }
                using (Brush brush = new SolidBrush(StyleManager.MainFormButtonForeColor)) {
                    string levelString = level.ToString();
                    gr.DrawString(levelString, StyleManager.MainFormLabelFont, brush, new PointF(height * (0.725f + (3 - levelString.Length) * 0.0375f), height * 0.7f));
                }
            }
            bitmap.MakeTransparent(StyleManager.TransparencyKey);
            Image oldImage = pictureBox.Image;

            pictureBox.Image = bitmap;
            if (oldImage != null)
            {
                lock (oldImage) {
                    oldImage.Dispose();
                }
            }
        }
Beispiel #43
0
 public Pen fPenInfo(Color oColor, int iWidth)
 {
     _Pen = new Pen(oColor, iWidth);
     return(_Pen);
 }
Beispiel #44
0
 public void DrawRectangle(Pen pen, Rectangle rect)
 {
     graphics.DrawRectangle(PenToXPen(pen), rect);
 }
Beispiel #45
0
 public void DrawEllipse(Pen pen, int x, int y, int width, int height)
 {
     graphics.DrawEllipse(PenToXPen(pen), x, y, width, height);
 }
Beispiel #46
0
 public void DrawLine(Pen pen, Point pt1, Point pt2)
 {
     graphics.DrawLine(PenToXPen(pen), pt1, pt2);
 }
Beispiel #47
0
        public void OverwriteTransparentCircle(int x_centre, int y_centre, int r)
        {
            // Force every pixel within a circle to have full transparancy

            int x = r, y = 0;

            // The 2 points between which a line will be drawn
            Point    p0, p1;
            Graphics g   = Graphics.FromImage(this.bmp);
            Pen      pen = new Pen(Color.White, 1);

            p0 = new Point(x + x_centre, y + y_centre);
            p1 = p0;

            // When radius is zero only a single point will be drawn
            if (r > 0)
            {
                p1 = new Point(x + x_centre, -y + y_centre);
                this.OverwriteTransparentLine(p0.X, p0.Y, p1.X, p1.Y);
                p0 = new Point(y + x_centre, x + y_centre);
                p1 = new Point(-y + x_centre, x + y_centre);
            }

            this.OverwriteTransparentLine(p0.X, p0.Y, p1.X, p1.Y);

            // Initialising the value of P
            int P = 1 - r;

            while (x > y)
            {
                y++;

                // Mid-point is inside or on the perimeter
                if (P <= 0)
                {
                    P = P + 2 * y + 1;
                }
                // Mid-point is outside the perimeter
                else
                {
                    x--;
                    P = P + 2 * y - 2 * x + 1;
                }

                // All the perimeter points have already been drawn
                if (x < y)
                {
                    break;
                }

                // Drawing the generated point and its reflection
                // in the other octants after translation
                p0 = new Point(x + x_centre, y + y_centre);
                p1 = new Point(-x + x_centre, y + y_centre);
                this.OverwriteTransparentLine(p0.X, p0.Y, p1.X, p1.Y);
                p0 = new Point(x + x_centre, -y + y_centre);
                p1 = new Point(-x + x_centre, -y + y_centre);
                this.OverwriteTransparentLine(p0.X, p0.Y, p1.X, p1.Y);

                // If the generated point is on the line x = y then
                // the perimeter points have already been drawn
                if (x != y)
                {
                    p0 = new Point(y + x_centre, x + y_centre);
                    p1 = new Point(-y + x_centre, x + y_centre);
                    this.OverwriteTransparentLine(p0.X, p0.Y, p1.X, p1.Y);
                    p0 = new Point(y + x_centre, -x + y_centre);
                    p1 = new Point(-y + x_centre, -x + y_centre);
                    this.OverwriteTransparentLine(p0.X, p0.Y, p1.X, p1.Y);
                }
            }

            // Draw the last line (which doesn't get drawn by the algorithm and I don't know why)
            // Use width 2 because it doesn't work otherwise, this is confusing
            p0 = new Point(x_centre - r, y_centre);
            p1 = new Point(x_centre + r, y_centre);
            this.OverwriteTransparentLine(p0.X, p0.Y, p1.X, p1.Y);
            p0 = new Point(x_centre - r, y_centre + 1);
            p1 = new Point(x_centre + r, y_centre + 1);
            this.OverwriteTransparentLine(p0.X, p0.Y, p1.X, p1.Y);
        }
 public void DrawLine(Pen P, float x1, float y1, float x2, float y2)
 {
     G.DrawLine(P, x1, y1, x2, y2);
 }
Beispiel #49
0
 public void DrawLines(Pen pen, Point[] points)
 {
     graphics.DrawLines(PenToXPen(pen), points);
 }
Beispiel #50
0
        public static Image CreateBanner(int nWidth, int nHeight, BannerStyle bs,
                                         Image imgIcon, string strTitle, string strLine, bool bNoCache)
        {
            // imgIcon may be null
            if (strTitle == null)
            {
                Debug.Assert(false); strTitle = string.Empty;
            }
            if (strLine == null)
            {
                Debug.Assert(false); strLine = string.Empty;
            }

            Debug.Assert((nHeight == StdHeight) || DpiUtil.ScalingRequired ||
                         UISystemFonts.OverrideUIFont);
            if (MonoWorkarounds.IsRequired(12525) && (nHeight > 0))
            {
                --nHeight;
            }

            if (bs == BannerStyle.Default)
            {
                bs = Program.Config.UI.BannerStyle;
            }
            if (bs == BannerStyle.Default)
            {
                Debug.Assert(false);
                bs = BannerStyle.WinVistaBlack;
            }

            NumberFormatInfo nfi       = NumberFormatInfo.InvariantInfo;
            ulong            uIconHash = ((imgIcon != null) ? GfxUtil.HashImage64(imgIcon) : 0);
            string           strID     = nWidth.ToString(nfi) + "x" + nHeight.ToString(nfi) +
                                         ":" + ((uint)bs).ToString(nfi) + ":" + strTitle + ":/:" + strLine +
                                         ":" + uIconHash.ToString(nfi);

            Image img = null;

            if (!bNoCache && g_dCache.TryGetValue(strID, out img))
            {
                return(img);
            }

            if (g_pCustomGen != null)
            {
                img = g_pCustomGen(new BfBannerInfo(nWidth, nHeight, bs, imgIcon,
                                                    strTitle, strLine));
            }

            const float fHorz = 0.90f;
            const float fVert = 90.0f;

            if (img == null)
            {
                img = new Bitmap(nWidth, nHeight, PixelFormat.Format24bppRgb);
                Graphics g = Graphics.FromImage(img);

                Color clrStart = Color.White;
                Color clrEnd   = Color.LightBlue;
                float fAngle   = fHorz;

                if (bs == BannerStyle.BlueCarbon)
                {
                    fAngle = fVert;

                    g.Clear(Color.Black);                     // Area from 3/8 to 1/2 height

                    clrStart = Color.LightGray;
                    clrEnd   = Color.Black;

                    Rectangle rect = new Rectangle(0, 0, nWidth, (nHeight * 3) / 8);
                    using (LinearGradientBrush brCarbonT = new LinearGradientBrush(
                               rect, clrStart, clrEnd, fAngle, true))
                    {
                        g.FillRectangle(brCarbonT, rect);
                    }

                    // clrStart = Color.FromArgb(0, 0, 32);
                    clrStart = Color.FromArgb(0, 0, 28);
                    // clrEnd = Color.FromArgb(192, 192, 255);
                    clrEnd = Color.FromArgb(155, 155, 214);

                    // rect = new Rectangle(0, nHeight / 2, nWidth, (nHeight * 5) / 8);
                    int hMid = nHeight / 2;
                    rect = new Rectangle(0, hMid - 1, nWidth, nHeight - hMid);
                    using (LinearGradientBrush brCarbonB = new LinearGradientBrush(
                               rect, clrStart, clrEnd, fAngle, true))
                    {
                        g.FillRectangle(brCarbonB, rect);
                    }

                    // Workaround gradient drawing bug (e.g. occuring on
                    // Windows 8.1 with 150% DPI)
                    using (Pen pen = new Pen(Color.Black))
                    {
                        g.DrawLine(pen, 0, hMid - 1, nWidth - 1, hMid - 1);
                    }
                }
                else
                {
                    if (bs == BannerStyle.WinXPLogin)
                    {
                        clrStart = Color.FromArgb(200, 208, 248);
                        clrEnd   = Color.FromArgb(40, 64, 216);
                    }
                    else if (bs == BannerStyle.WinVistaBlack)
                    {
                        clrStart = Color.FromArgb(151, 154, 173);
                        clrEnd   = Color.FromArgb(27, 27, 37);

                        fAngle = fVert;
                    }
                    else if (bs == BannerStyle.KeePassWin32)
                    {
                        clrStart = Color.FromArgb(235, 235, 255);
                        clrEnd   = Color.FromArgb(192, 192, 255);
                    }

                    Rectangle rect = new Rectangle(0, 0, nWidth, nHeight);
                    using (LinearGradientBrush brBack = new LinearGradientBrush(
                               rect, clrStart, clrEnd, fAngle, true))
                    {
                        g.FillRectangle(brBack, rect);
                    }
                }

                bool bRtl = Program.Translation.Properties.RightToLeft;
                // Matrix mxTrfOrg = g.Transform;
                // if(bRtl)
                // {
                //	g.TranslateTransform(nWidth, 0.0f);
                //	g.ScaleTransform(-1.0f, 1.0f);
                // }

                int xIcon       = DpiScaleInt(10, nHeight);
                int wIconScaled = StdIconDim;
                int hIconScaled = StdIconDim;
                if (imgIcon != null)
                {
                    float fIconRel = (float)imgIcon.Width / (float)imgIcon.Height;
                    wIconScaled = (int)Math.Round(DpiScaleFloat(fIconRel *
                                                                (float)StdIconDim, nHeight));
                    hIconScaled = DpiScaleInt(StdIconDim, nHeight);

                    int xIconR = (bRtl ? (nWidth - xIcon - wIconScaled) : xIcon);
                    int yIconR = (nHeight - hIconScaled) / 2;
                    if (hIconScaled == imgIcon.Height)
                    {
                        g.DrawImageUnscaled(imgIcon, xIconR, yIconR);
                    }
                    else
                    {
                        g.DrawImage(imgIcon, xIconR, yIconR, wIconScaled, hIconScaled);
                    }

                    ColorMatrix cm = new ColorMatrix();
                    cm.Matrix33 = 0.1f;
                    ImageAttributes ia = new ImageAttributes();
                    ia.SetColorMatrix(cm);

                    int       w = wIconScaled * 3, h = hIconScaled * 3;
                    int       x        = (bRtl ? xIcon : (nWidth - w - xIcon));
                    int       y        = (nHeight - h) / 2;
                    Rectangle rectDest = new Rectangle(x, y, w, h);
                    g.DrawImage(imgIcon, rectDest, 0, 0, imgIcon.Width, imgIcon.Height,
                                GraphicsUnit.Pixel, ia);
                }

                if ((bs == BannerStyle.WinXPLogin) || (bs == BannerStyle.WinVistaBlack) ||
                    (bs == BannerStyle.BlueCarbon))
                {
                    int sh = DpiUtil.ScaleIntY(20) / 10;                     // Force floor

                    Rectangle rect = new Rectangle(0, nHeight - sh, 0, sh);

                    rect.Width = nWidth / 2 + 1;
                    rect.X     = nWidth / 2;
                    clrStart   = Color.FromArgb(248, 136, 24);
                    clrEnd     = Color.White;
                    using (LinearGradientBrush brushOrangeWhite = new LinearGradientBrush(
                               rect, clrStart, clrEnd, fHorz, true))
                    {
                        g.FillRectangle(brushOrangeWhite, rect);
                    }

                    rect.Width = nWidth / 2 + 1;
                    rect.X     = 0;
                    clrStart   = Color.White;
                    clrEnd     = Color.FromArgb(248, 136, 24);
                    using (LinearGradientBrush brushWhiteOrange = new LinearGradientBrush(
                               rect, clrStart, clrEnd, fHorz, true))
                    {
                        g.FillRectangle(brushWhiteOrange, rect);
                    }
                }
                else if (bs == BannerStyle.KeePassWin32)
                {
                    int sh = DpiUtil.ScaleIntY(10) / 10;                     // Force floor

                    // Black separator line
                    using (Pen penBlack = new Pen(Color.Black))
                    {
                        for (int i = 0; i < sh; ++i)
                        {
                            g.DrawLine(penBlack, 0, nHeight - i - 1,
                                       nWidth - 1, nHeight - i - 1);
                        }
                    }
                }

                // if(bRtl) g.Transform = mxTrfOrg;

                // Brush brush;
                Color clrText;
                if (bs == BannerStyle.KeePassWin32)
                {
                    // brush = Brushes.Black;
                    clrText = Color.Black;
                }
                else
                {
                    // brush = Brushes.White;
                    clrText = Color.White;
                }

                // float fx = 2 * xIcon, fy = 9.0f;
                int tx = 2 * xIcon, ty = DpiScaleInt(9, nHeight);
                if (imgIcon != null)
                {
                    tx += wIconScaled;                                 // fx
                }
                // TextFormatFlags tff = (TextFormatFlags.PreserveGraphicsClipping |
                //	TextFormatFlags.NoPrefix);
                // if(bRtl) tff |= TextFormatFlags.RightToLeft;

                float fFontSize = DpiScaleFloat((12.0f * 96.0f) / g.DpiY, nHeight);
                using (Font font = FontUtil.CreateFont(FontFamily.GenericSansSerif,
                                                       fFontSize, FontStyle.Bold))
                {
                    int txT = (!bRtl ? tx : (nWidth - tx));
                    // - TextRenderer.MeasureText(g, strTitle, font).Width));
                    // g.DrawString(strTitle, font, brush, fx, fy);
                    BannerFactory.DrawText(g, strTitle, txT, ty, font,
                                           clrText, bRtl, nWidth);
                }

                tx += xIcon;                 // fx
                ty += xIcon * 2 + 2;         // fy

                float fFontSizeSm = DpiScaleFloat((9.0f * 96.0f) / g.DpiY, nHeight);
                using (Font fontSmall = FontUtil.CreateFont(FontFamily.GenericSansSerif,
                                                            fFontSizeSm, FontStyle.Regular))
                {
                    int txL = (!bRtl ? tx : (nWidth - tx));
                    // - TextRenderer.MeasureText(g, strLine, fontSmall).Width));
                    // g.DrawString(strLine, fontSmall, brush, fx, fy);
                    BannerFactory.DrawText(g, strLine, txL, ty, fontSmall,
                                           clrText, bRtl, nWidth);
                }

                g.Dispose();
            }

            if (!bNoCache)
            {
                if (g_dCache.Count >= MaxCachedImages)
                {
                    List <string> lK = new List <string>(g_dCache.Keys);
                    g_dCache.Remove(lK[Program.GlobalRandom.Next(lK.Count)]);
                }

                g_dCache[strID] = img;
            }

            return(img);
        }
Beispiel #51
0
 public void DrawLine(Pen pen, int x1, int y1, int x2, int y2)
 {
     graphics.DrawLine(PenToXPen(pen), x1, y1, x2, y2);
 }
        internal void DrawControl(Graphics g)
        {
            if (DwmApi.DwmIsCompositionEnabled())
            {
                g.Clear(Color.Transparent);
            }
            else
            {
                g.Clear(SystemColors.ControlLightLight);
            }
            if (TabCount > 0)
            {
                g.FillRectangle(Brushes.White, GetTabRect(0).X, GetTabRect(0).Bottom, ClientRectangle.Width, ClientRectangle.Height);
                Rectangle contentRect = Rectangle.FromLTRB(ClientRectangle.X, GetTabRect(0).Bottom, ClientRectangle.Right - 1, ClientRectangle.Bottom - 1);
                g.DrawRectangle(Pens.Gray, contentRect);
            }

            for (int i = 0; i < TabCount; i++)
            {
                TabPage   tab     = TabPages[i];
                Rectangle tabRect = GetTabRect(i);
                tabRect.Inflate(-2, 0);

                //draw shadow
                Rectangle shadowRect = tabRect;
                shadowRect.Offset(2, 2);

                using (GraphicsPath path = CreateCompleteTabPath(shadowRect))
                {
                    Rectangle tabBar = Rectangle.FromLTRB(ClientRectangle.Left, ClientRectangle.Top,
                                                          ClientRectangle.Right, tabRect.Bottom);

                    Region region = g.Clip;
                    g.SetClip(tabBar);
                    SolidBrush shadow = new SolidBrush(Color.FromArgb(100, Color.Gray));
                    g.FillPath(shadow, path);
                    g.Clip = region;
                }

                if (tab == SelectedTab)
                {
                    using (GraphicsPath path = CreateTabPath(tabRect))
                    {
                        g.SmoothingMode = SmoothingMode.AntiAlias;
                        g.FillPath(Brushes.White, path);
                        g.DrawPath(Pens.Gray, path);
                    }

                    Rectangle fillRect = tabRect;
                    fillRect.Offset(0, 2);
                    using (GraphicsPath path = CreateCompleteTabPath(fillRect))
                    {
                        g.FillPath(Brushes.White, path);
                    }
                }
                else
                {
                    using (GraphicsPath path = CreateCompleteTabPath(tabRect))
                    {
                        g.SmoothingMode = SmoothingMode.AntiAlias;
                        g.FillPath(Brushes.White, path);
                        g.DrawPath(Pens.Gray, path);
                    }
                }

                if (i == mouseIsOn)
                {
                    using (GraphicsPath path = CreateTabPath(tabRect))
                    {
                        using (Pen p = new Pen(Color.FromArgb(80, SystemColors.Highlight)))
                        {
                            p.Width = 4;
                            g.DrawPath(p, path);
                        }

                        using (Pen p = new Pen(Color.FromArgb(150, SystemColors.Highlight)))
                        {
                            p.Width = 2;
                            g.DrawPath(p, path);
                        }
                    }
                }


                StringFormat stringFormat = new StringFormat();
                stringFormat.Alignment     = StringAlignment.Center;
                stringFormat.LineAlignment = StringAlignment.Center;

                g.DrawString(tab.Text, tab.Font, new SolidBrush(tab.ForeColor), tabRect, stringFormat);
            }
        }
Beispiel #53
0
        private void document_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            Pen blackPen = new Pen(Color.Black, 1);//黑色,1像素

            //打印样式
            System.Drawing.Font f         = new System.Drawing.Font("黑体", 10, System.Drawing.FontStyle.Regular);
            System.Drawing.Font TableFont = new Font("宋体", 10, FontStyle.Regular);
            System.Drawing.Font boldFont  = new System.Drawing.Font("黑体", 12, System.Drawing.FontStyle.Bold);
            System.Drawing.Font msgf      = new System.Drawing.Font("黑体", 14, System.Drawing.FontStyle.Regular);

            string[,] strArr = new string[2, 6];  //声明一个二维数组.
            strArr[0, 0]     = "类别";
            strArr[0, 1]     = "老师";
            strArr[0, 2]     = "工作单位";
            strArr[0, 3]     = "信息大学";
            strArr[0, 4]     = "收费标准";
            strArr[0, 5]     = 12 + "元";

            strArr[1, 0] = "姓名";
            strArr[1, 1] = "陈小莉";
            strArr[1, 2] = "性别";
            strArr[1, 3] = "女";
            strArr[1, 4] = "年龄";
            strArr[1, 5] = "" + 20;

            int docX     = 90;
            int docY     = 50;
            int tableW   = 600;        //表宽
            int tableH   = 2 * 50;     //表高
            int tableX   = docX;       //表的起点X坐标
            int tableY   = docY;       //表的起点Y坐标
            int rowWidth = 50;         //行宽
            int colwidth = tableW / 6; //列宽

            for (int i = 0; i <= 2; i++)
            {
                e.Graphics.DrawLine(blackPen, tableX, tableY + i * rowWidth, tableX + tableW, tableY + i * rowWidth);
                for (int j = 0; j <= 6; j++)
                {
                    if (i != 2)
                    {
                        e.Graphics.DrawLine(blackPen,
                                            tableX + j * colwidth, tableY + i * rowWidth,
                                            tableX + j * colwidth, tableY + i * rowWidth + rowWidth);
                        if (j != 6)
                        {
                            if (j % 2 == 0)
                            {
                                int textWidth  = Convert.ToInt32(e.Graphics.MeasureString(strArr[i, j], boldFont).Width);
                                int textHeight = Convert.ToInt32(e.Graphics.MeasureString(strArr[i, j], boldFont).Height);
                                int centerX    = (colwidth - textWidth) / 2;                                             //字体X轴居中
                                int centerY    = (rowWidth - textHeight) / 2;                                            //字体Y轴居中
                                e.Graphics.DrawString(strArr[i, j], boldFont, Brushes.Black,
                                                      tableX + j * colwidth + centerX, tableY + i * rowWidth + centerY); //写列名
                            }
                            else
                            {
                                e.Graphics.DrawString(strArr[i, j], TableFont, Brushes.Black,
                                                      tableX + j * colwidth + 15, tableY + i * rowWidth + 15);//写列名
                            }
                        }
                    }
                }
            }
        }
Beispiel #54
0
        public void AddLines(Graphics g, ChartStyle cs)
        {
            // Plot lines:
            foreach (DataSeries ds in DataSeriesList)
            {
                if (ds.LineStyle.IsVisible == true)
                {
                    Pen aPen = new Pen(ds.LineStyle.LineColor, ds.LineStyle.Thickness);
                    aPen.DashStyle = ds.LineStyle.Pattern;
                    if (ds.LineStyle.PlotMethod == LineStyle.PlotLinesMethodEnum.Lines)
                    {
                        for (int i = 1; i < ds.PointList.Count; i++)
                        {
                            if (!ds.IsY2Data)
                            {
                                g.DrawLine(aPen, cs.Point2D((PointF)ds.PointList[i - 1]),
                                           cs.Point2D((PointF)ds.PointList[i]));
                            }
                            else
                            {
                                g.DrawLine(aPen, cs.Point2DY2((PointF)ds.PointList[i - 1]),
                                           cs.Point2DY2((PointF)ds.PointList[i]));
                            }
                        }
                    }
                    else if (ds.LineStyle.PlotMethod == LineStyle.PlotLinesMethodEnum.Splines)
                    {
                        ArrayList al = new ArrayList();
                        for (int i = 0; i < ds.PointList.Count; i++)
                        {
                            PointF pt = (PointF)ds.PointList[i];
                            if (!ds.IsY2Data)
                            {
                                if (pt.X >= cs.XLimMin && pt.X <= cs.XLimMax &&
                                    pt.Y >= cs.YLimMin && pt.Y <= cs.YLimMax)
                                {
                                    al.Add(pt);
                                }
                            }
                            else
                            {
                                if (pt.X >= cs.XLimMin && pt.X <= cs.XLimMax &&
                                    pt.Y >= cs.Y2LimMin && pt.Y <= cs.Y2LimMax)
                                {
                                    al.Add(pt);
                                }
                            }
                        }
                        PointF[] pts = new PointF[al.Count];
                        for (int i = 0; i < pts.Length; i++)
                        {
                            if (!ds.IsY2Data)
                            {
                                pts[i] = cs.Point2D((PointF)(al[i]));
                            }
                            else
                            {
                                pts[i] = cs.Point2DY2((PointF)(al[i]));
                            }
                        }
                        g.DrawCurve(aPen, pts);
                    }
                    aPen.Dispose();
                }
            }

            // Plot Symbols:
            foreach (DataSeries ds in DataSeriesList)
            {
                for (int i = 0; i < ds.PointList.Count; i++)
                {
                    PointF pt = (PointF)ds.PointList[i];
                    if (!ds.IsY2Data)
                    {
                        if (pt.X >= cs.XLimMin && pt.X <= cs.XLimMax &&
                            pt.Y >= cs.YLimMin && pt.Y <= cs.YLimMax)
                        {
                            ds.SymbolStyle.DrawSymbol(g, cs.Point2D((PointF)ds.PointList[i]));
                        }
                    }
                    else
                    {
                        if (pt.X >= cs.XLimMin && pt.X <= cs.XLimMax &&
                            pt.Y >= cs.Y2LimMin && pt.Y <= cs.Y2LimMax)
                        {
                            ds.SymbolStyle.DrawSymbol(g, cs.Point2DY2((PointF)ds.PointList[i]));
                        }
                    }
                }
            }
        }
Beispiel #55
0
        private void cLogo_Draw(Graphics g)
        {
            g.SetHighQuality();

            using (Matrix m = new Matrix())
            {
                m.RotateAt(45, new PointF(mX, mY));
                g.Transform = m;
            }

            using (Pen pen = new Pen(lineColor, 2))
            {
                for (int i = 0; i <= mX; i += step)
                {
                    g.DrawLine(pen, i, mY, mX, mY - i);     // Left top
                    g.DrawLine(pen, mX, i, mX + i, mY);     // Right top
                    g.DrawLine(pen, w - i, mY, mX, mY + i); // Right bottom
                    g.DrawLine(pen, mX, h - i, mX - i, mY); // Left bottom

                    /*
                     * g.DrawLine(pen, i, mY, mX, mY - i); // Left top
                     * g.DrawLine(pen, w - i, mY, mX, mY - i); // Right top
                     * g.DrawLine(pen, w - i, mY, mX, mY + i); // Right bottom
                     * g.DrawLine(pen, i, mY, mX, mY + i); // Left bottom
                     */

                    /*
                     * g.DrawLine(pen, mX, i, i, mY); // Left top
                     * g.DrawLine(pen, mX, i, w - i, mY); // Right top
                     * g.DrawLine(pen, mX, h - i, w - i, mY); // Right bottom
                     * g.DrawLine(pen, mX, h - i, i, mY); // Left bottom
                     */
                }

                //g.DrawLine(pen, mX, 0, mX, h);
            }

            if (!isPaused)
            {
                if (step + speed > maxStep)
                {
                    direction = -speed;
                }
                else if (step - speed < minStep)
                {
                    direction = speed;
                }

                step += direction;

                HSB hsb = lineColor;

                if (hsb.Hue >= 1)
                {
                    hsb.Hue = 0;
                }
                else
                {
                    hsb.Hue += 0.01;
                }

                lineColor = hsb;
            }
        }
        private void DrawTextRun(SvgTextContentElement element, ref Point ctp,
                                 WpfTextRun textRun, double rotate, WpfTextPlacement placement)
        {
            if (textRun == null || textRun.IsEmpty)
            {
                return;
            }

            string     text       = textRun.Text;
            double     emSize     = GetComputedFontSize(element);
            FontFamily fontFamily = GetTextFontFamily(element, emSize);

            FontStyle  fontStyle  = GetTextFontStyle(element);
            FontWeight fontWeight = GetTextFontWeight(element);

            FontStretch fontStretch = GetTextFontStretch(element);

            WpfTextStringFormat stringFormat = GetTextStringFormat(element);

            // Fix the use of Postscript fonts...
            WpfFontFamilyVisitor fontFamilyVisitor = _drawContext.FontFamilyVisitor;

            if (!String.IsNullOrEmpty(_actualFontName) && fontFamilyVisitor != null)
            {
                WpfFontFamilyInfo currentFamily = new WpfFontFamilyInfo(fontFamily, fontWeight,
                                                                        fontStyle, fontStretch);
                WpfFontFamilyInfo familyInfo = fontFamilyVisitor.Visit(_actualFontName,
                                                                       currentFamily, _drawContext);
                if (familyInfo != null && !familyInfo.IsEmpty)
                {
                    fontFamily  = familyInfo.Family;
                    fontWeight  = familyInfo.Weight;
                    fontStyle   = familyInfo.Style;
                    fontStretch = familyInfo.Stretch;
                }
            }

            WpfSvgPaint fillPaint = new WpfSvgPaint(_drawContext, element, "fill");
            Brush       textBrush = fillPaint.GetBrush();

            WpfSvgPaint strokePaint = new WpfSvgPaint(_drawContext, element, "stroke");
            Pen         textPen     = strokePaint.GetPen();

            if (textBrush == null && textPen == null)
            {
                return;
            }
            else if (textBrush == null)
            {
                // If here, then the pen is not null, and so the fill cannot be null.
                // We set this to transparent for stroke only text path...
                textBrush = Brushes.Transparent;
            }

            TextDecorationCollection textDecors = GetTextDecoration(element);
            TextAlignment            alignment  = stringFormat.Alignment;

            string letterSpacing = element.GetAttribute("letter-spacing");

            if (String.IsNullOrEmpty(letterSpacing))
            {
                FormattedText formattedText = new FormattedText(text,
                                                                textRun.IsLatin ? _drawContext.EnglishCultureInfo : _drawContext.CultureInfo,
                                                                stringFormat.Direction, new Typeface(fontFamily, fontStyle, fontWeight, fontStretch),
                                                                emSize, textBrush);

                formattedText.TextAlignment = stringFormat.Alignment;
                formattedText.Trimming      = stringFormat.Trimming;

                if (textDecors != null && textDecors.Count != 0)
                {
                    formattedText.SetTextDecorations(textDecors);
                }

                //float xCorrection = 0;
                //if (alignment == TextAlignment.Left)
                //    xCorrection = emSize * 1f / 6f;
                //else if (alignment == TextAlignment.Right)
                //    xCorrection = -emSize * 1f / 6f;

                double yCorrection = formattedText.Baseline;

                Point textPoint = new Point(ctp.X, ctp.Y - yCorrection);

                RotateTransform rotateAt = new RotateTransform(90, ctp.X, ctp.Y);
                _textContext.PushTransform(rotateAt);

                _textContext.DrawText(formattedText, textPoint);

                //float bboxWidth = (float)formattedText.Width;
                double bboxWidth = formattedText.WidthIncludingTrailingWhitespace;
                if (alignment == TextAlignment.Center)
                {
                    bboxWidth /= 2f;
                }
                else if (alignment == TextAlignment.Right)
                {
                    bboxWidth = 0;
                }

                //ctp.X += bboxWidth + emSize / 4;
                ctp.X += bboxWidth;

                if (rotateAt != null)
                {
                    _textContext.Pop();
                }
            }
            else
            {
                RotateTransform rotateAt = new RotateTransform(90, ctp.X, ctp.Y);
                _textContext.PushTransform(rotateAt);

                float spacing = Convert.ToSingle(letterSpacing);
                for (int i = 0; i < text.Length; i++)
                {
                    FormattedText formattedText = new FormattedText(new string(text[i], 1),
                                                                    textRun.IsLatin ? _drawContext.EnglishCultureInfo : _drawContext.CultureInfo,
                                                                    stringFormat.Direction,
                                                                    new Typeface(fontFamily, fontStyle, fontWeight, fontStretch),
                                                                    emSize, textBrush);

                    formattedText.Trimming      = stringFormat.Trimming;
                    formattedText.TextAlignment = stringFormat.Alignment;

                    if (textDecors != null && textDecors.Count != 0)
                    {
                        formattedText.SetTextDecorations(textDecors);
                    }

                    //float xCorrection = 0;
                    //if (alignment == TextAlignment.Left)
                    //    xCorrection = emSize * 1f / 6f;
                    //else if (alignment == TextAlignment.Right)
                    //    xCorrection = -emSize * 1f / 6f;

                    double yCorrection = formattedText.Baseline;

                    Point textPoint = new Point(ctp.X, ctp.Y - yCorrection);

                    _textContext.DrawText(formattedText, textPoint);

                    //float bboxWidth = (float)formattedText.Width;
                    double bboxWidth = formattedText.WidthIncludingTrailingWhitespace;
                    if (alignment == TextAlignment.Center)
                    {
                        bboxWidth /= 2f;
                    }
                    else if (alignment == TextAlignment.Right)
                    {
                        bboxWidth = 0;
                    }

                    //ctp.X += bboxWidth + emSize / 4 + spacing;
                    ctp.X += bboxWidth + spacing;
                }

                if (rotateAt != null)
                {
                    _textContext.Pop();
                }
            }
        }
Beispiel #57
0
        /// <summary>生成验证码图片
        /// </summary>
        /// <returns></returns>
        private Bitmap tempImage()
        {
            //创建验证码图片对象
            Bitmap image = new Bitmap(ImageWidth, ImageHeight);
            //创建绘布对象
            Graphics g = Graphics.FromImage(image);

            try
            {
                Font[] fonts =
                {
                    new Font(new FontFamily("Impact"),  RandomHelper.GetRndNext(FontSize - 2, FontSize), FontStyle.Bold),
                    new Font(new FontFamily("Kokila"),  RandomHelper.GetRndNext(FontSize - 3, FontSize), FontStyle.Bold),
                    //new Font(new FontFamily("Bell MT"), RandomHelp.GetRndNext(FontSize - 3, FontSize), FontStyle.Bold),
                    new Font(new FontFamily("MV Boli"), RandomHelper.GetRndNext(FontSize - 3, FontSize), FontStyle.Bold)
                };

                Color[] bgColors =
                {
                    Color.Snow,
                    Color.White,
                    Color.Linen,
                    Color.FromArgb(242, 251, 246),
                    Color.FromArgb(233, 240, 245),
                    Color.FromArgb(244, 244, 244),
                    Color.FromArgb(255, 228, 188)
                };

                Color[] colors =
                {
                    Color.FromArgb(24,  1, 58),
                    Color.Red,
                    Color.DarkRed,
                    Color.Black,
                    Color.RoyalBlue,
                    Color.FromArgb(57, 77, 14),
                    Color.FromArgb(85, 72, 64)
                };

                Color bgcolor = bgColors[RandomHelper.GetRndNext(0, bgColors.Length)];//背景色

                //生成随机生成器
                Random random = new Random();
                //清空图片背景色,画上背景干扰线
                g.Clear(bgcolor);
                for (int i = 0; i < NoiseLine; i++)
                {
                    int x1 = random.Next(image.Width);
                    int x2 = random.Next(image.Width);
                    int y1 = random.Next(image.Height);
                    int y2 = random.Next(image.Height);
                    g.DrawLine(new Pen(Color.FromArgb(random.Next())), x1, y1, x2, y2);
                }

                LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), colors[RandomHelper.GetRndNext(0, colors.Length)], colors[RandomHelper.GetRndNext(0, colors.Length)], 1.2f, true);

                int count = Code.Length;
                for (int i = 0; i < count; i++)
                {
                    int x = i * image.Width / count - i * RandomHelper.GetRndNext(2, 4);
                    g.DrawString(Code.Substring(i, 1), fonts[RandomHelper.GetRndNext(0, fonts.Length)], brush, RandomHelper.GetRndNext(-2, 1) + x, RandomHelper.GetRndNext(-3, -1));
                }


                //int count = Code.Length;
                //for (int i = 0; i < count; i++)
                //{
                //    //字体设定
                //    Font font = new Font("Arial", RandomHelp.GetRndNext(FontSize - 5, FontSize),
                //        (FontStyle.Bold | FontStyle.Italic));

                //    //创建画笔
                //    LinearGradientBrush brush =
                //        new LinearGradientBrush(
                //            new Rectangle( 1 + i * 10, 0, image.Width,
                //                image.Height),
                //            Color.Blue, Color.DarkRed, 2.8f, true);
                //    g.DrawString(Code.Substring(i, 1), font, brush, 5, 2);
                //}

                //画图片的前景干扰点
                for (int i = 0; i < NoisePoint; i++)
                {
                    int x = random.Next(image.Width);
                    int y = random.Next(image.Height);
                    image.SetPixel(x, y, Color.FromArgb(random.Next()));
                }

                //定义干扰线中间点位置
                int midX  = RandomHelper.GetRndNext(0, image.Width / 2);
                int midX2 = RandomHelper.GetRndNext(midX, image.Width);
                //定义画笔
                Pen pen = new Pen(colors[RandomHelper.GetRndNext(0, colors.Length)], 2);
                //画干扰线
                g.DrawLine(pen, 0, random.Next(image.Height), midX, random.Next(image.Height));
                g.DrawLine(pen, midX, random.Next(image.Height), midX2, random.Next(image.Height));
                g.DrawLine(pen, midX2, random.Next(image.Height), image.Width, random.Next(image.Height));

                //画多一条干扰线
                midX  = RandomHelper.GetRndNext(0, image.Width / 2);
                midX2 = RandomHelper.GetRndNext(midX, image.Width);
                //定义画笔
                pen = new Pen(colors[RandomHelper.GetRndNext(0, colors.Length)], 2);
                //画干扰线
                g.DrawLine(pen, 0, random.Next(image.Height), midX, random.Next(image.Height));
                g.DrawLine(pen, midX, random.Next(image.Height), midX2, random.Next(image.Height));
                g.DrawLine(pen, midX2, random.Next(image.Height), image.Width, random.Next(image.Height));

                //画图片的边框线
                g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
            }
            catch (Exception)
            {
                return(image);
            }

            return(image);
        }
Beispiel #58
0
        public static void RenderLineFont(char a, Canvas canvas, int offset)
        {
            Pen pen = new Pen(System.Drawing.Color.Black);

            switch (a)
            {
            case 'A':
                canvas.DrawLine(pen, new Point(1 + offset, 0 + offset), new Point(2 + offset, 2 + offset));
                canvas.DrawLine(pen, new Point(0 + offset, 2 + offset), new Point(1 + offset, 0 + offset));
                canvas.DrawLine(pen, new Point(0 + offset, 1 + offset), new Point(2 + offset, 1 + offset));
                break;

            case 'B':
                canvas.DrawLine(pen, new Point(0 + offset, 0 + offset), new Point(2 + offset, 0 + offset));
                canvas.DrawLine(pen, new Point(2 + offset, 0 + offset), new Point(2 + offset, 2 + offset));
                canvas.DrawLine(pen, new Point(0 + offset, 0 + offset), new Point(2 + offset, 0 + offset));
                canvas.DrawLine(pen, new Point(0 + offset, 1 + offset), new Point(2 + offset, 1 + offset));
                canvas.DrawLine(pen, new Point(0 + offset, 2 + offset), new Point(2 + offset, 2 + offset));
                break;

            case 'C':
                canvas.DrawLine(pen, new Point(0 + offset, 0 + offset), new Point(2 + offset, 0 + offset));
                canvas.DrawLine(pen, new Point(0 + offset, 0 + offset), new Point(2 + offset, 0 + offset));
                canvas.DrawLine(pen, new Point(0 + offset, 2 + offset), new Point(2 + offset, 2 + offset));
                break;

            case 'D':
                canvas.DrawLine(pen, new Point(0 + offset, 0 + offset), new Point(2 + offset, 0 + offset));
                canvas.DrawLine(pen, new Point(2 + offset, 0 + offset), new Point(2 + offset, 2 + offset));
                canvas.DrawLine(pen, new Point(0 + offset, 0 + offset), new Point(2 + offset, 0 + offset));
                canvas.DrawLine(pen, new Point(0 + offset, 2 + offset), new Point(2 + offset, 2 + offset));
                break;

            case 'E':
                canvas.DrawLine(pen, new Point(0 + offset, 0 + offset), new Point(2 + offset, 0 + offset));
                canvas.DrawLine(pen, new Point(0 + offset, 0 + offset), new Point(2 + offset, 0 + offset));
                canvas.DrawLine(pen, new Point(0 + offset, 1 + offset), new Point(2 + offset, 1 + offset));
                canvas.DrawLine(pen, new Point(0 + offset, 2 + offset), new Point(2 + offset, 2 + offset));
                break;

            case 'F':
                canvas.DrawLine(pen, new Point(0 + offset, 0 + offset), new Point(2 + offset, 0 + offset));
                canvas.DrawLine(pen, new Point(0 + offset, 0 + offset), new Point(2 + offset, 0 + offset));
                canvas.DrawLine(pen, new Point(0 + offset, 1 + offset), new Point(2 + offset, 1 + offset));
                break;

            case 'G':
                canvas.DrawLine(pen, new Point(0 + offset, 0 + offset), new Point(2 + offset, 0 + offset));
                canvas.DrawLine(pen, new Point(2 + offset, 1 + offset), new Point(2 + offset, 2 + offset));
                canvas.DrawLine(pen, new Point(0 + offset, 0 + offset), new Point(2 + offset, 0 + offset));
                canvas.DrawLine(pen, new Point(1 + offset, 1 + offset), new Point(2 + offset, 1 + offset));
                canvas.DrawLine(pen, new Point(0 + offset, 2 + offset), new Point(2 + offset, 2 + offset));
                break;

            case 'H':
                canvas.DrawLine(pen, new Point(0 + offset, 0 + offset), new Point(2 + offset, 0 + offset));
                canvas.DrawLine(pen, new Point(2 + offset, 0 + offset), new Point(2 + offset, 2 + offset));
                canvas.DrawLine(pen, new Point(0 + offset, 1 + offset), new Point(2 + offset, 1 + offset));
                break;

            case 'I':
                canvas.DrawLine(pen, new Point(0 + offset, 0 + offset), new Point(2 + offset, 0 + offset));
                canvas.DrawLine(pen, new Point(2 + offset, 0 + offset), new Point(2 + offset, 2 + offset));
                canvas.DrawLine(pen, new Point(0 + offset, 1 + offset), new Point(2 + offset, 1 + offset));
                break;

            case 'J':
                canvas.DrawLine(pen, new Point(0 + offset, 0 + offset), new Point(2 + offset, 0 + offset));
                canvas.DrawLine(pen, new Point(2 + offset, 0 + offset), new Point(2 + offset, 2 + offset));
                canvas.DrawLine(pen, new Point(0 + offset, 0 + offset), new Point(2 + offset, 0 + offset));
                canvas.DrawLine(pen, new Point(0 + offset, 2 + offset), new Point(2 + offset, 2 + offset));
                break;

            case 'K':
                break;

            case 'L':
                break;

            case 'N':
                break;

            case 'M':
                break;

            case 'O':
                break;

            case 'P':
                break;

            case 'Q':
                break;

            case 'R':
                break;

            case 'S':
                break;

            case 'T':
                break;

            case 'U':
                break;

            case 'V':
                break;

            case 'W':
                break;

            case 'Y':
                break;

            case 'X':
                break;

            case 'Z':
                break;
            }
        }
Beispiel #59
0
        protected override void OnPaint(PaintEventArgs pevent)
        {
            var g = pevent.Graphics;

            g.SmoothingMode     = SmoothingMode.AntiAlias;
            g.TextRenderingHint = TextRenderingHint.AntiAlias;

            // clear the control
            g.Clear(Parent.BackColor);

            var RADIOBUTTON_CENTER = boxOffset + RADIOBUTTON_SIZE_HALF;

            var animationProgress = animationManager.GetProgress();

            int   colorAlpha        = Enabled ? (int)(animationProgress * 255.0) : SkinManager.GetCheckBoxOffDisabledColor().A;
            int   backgroundAlpha   = Enabled ? (int)(SkinManager.GetCheckboxOffColor().A *(1.0 - animationProgress)) : SkinManager.GetCheckBoxOffDisabledColor().A;
            float animationSize     = (float)(animationProgress * 8f);
            float animationSizeHalf = animationSize / 2;

            animationSize = (float)(animationProgress * 9f);

            var brush = new SolidBrush(Color.FromArgb(colorAlpha, Enabled ? SkinManager.ColorScheme.AccentColor : SkinManager.GetCheckBoxOffDisabledColor()));
            var pen   = new Pen(brush.Color);

            // draw ripple animation
            if (Ripple && rippleAnimationManager.IsAnimating())
            {
                for (int i = 0; i < rippleAnimationManager.GetAnimationCount(); i++)
                {
                    var animationValue  = rippleAnimationManager.GetProgress(i);
                    var animationSource = new Point(RADIOBUTTON_CENTER, RADIOBUTTON_CENTER);
                    var rippleBrush     = new SolidBrush(Color.FromArgb((int)((animationValue * 40)), ((bool)rippleAnimationManager.GetData(i)[0]) ? Color.Black : brush.Color));
                    var rippleHeight    = (Height % 2 == 0) ? Height - 3 : Height - 2;
                    var rippleSize      = (rippleAnimationManager.GetDirection(i) == AnimationDirection.InOutIn) ? (int)(rippleHeight * (0.8d + (0.2d * animationValue))) : rippleHeight;
                    using (var path = DrawHelper.CreateRoundRect(animationSource.X - rippleSize / 2, animationSource.Y - rippleSize / 2, rippleSize, rippleSize, rippleSize / 2))
                    {
                        g.FillPath(rippleBrush, path);
                    }

                    rippleBrush.Dispose();
                }
            }

            // draw radiobutton circle
            Color uncheckedColor = DrawHelper.BlendColor(Parent.BackColor, Enabled ? SkinManager.GetCheckboxOffColor() : SkinManager.GetCheckBoxOffDisabledColor(), backgroundAlpha);

            using (var path = DrawHelper.CreateRoundRect(boxOffset, boxOffset, RADIOBUTTON_SIZE, RADIOBUTTON_SIZE, 9f))
            {
                g.FillPath(new SolidBrush(uncheckedColor), path);

                if (Enabled)
                {
                    g.FillPath(brush, path);
                }
            }

            g.FillEllipse(
                new SolidBrush(Parent.BackColor),
                RADIOBUTTON_OUTER_CIRCLE_WIDTH + boxOffset,
                RADIOBUTTON_OUTER_CIRCLE_WIDTH + boxOffset,
                RADIOBUTTON_INNER_CIRCLE_SIZE,
                RADIOBUTTON_INNER_CIRCLE_SIZE);

            if (Checked)
            {
                using (var path = DrawHelper.CreateRoundRect(RADIOBUTTON_CENTER - animationSizeHalf, RADIOBUTTON_CENTER - animationSizeHalf, animationSize, animationSize, 4f))
                {
                    g.FillPath(brush, path);
                }
            }
            SizeF stringSize = g.MeasureString(Text, SkinManager.ROBOTO_MEDIUM_10);

            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            g.DrawString(Text, SkinManager.ROBOTO_MEDIUM_10, Enabled ? SkinManager.GetPrimaryTextBrush() : SkinManager.GetDisabledOrHintBrush(), boxOffset + 22, Height / 2 - stringSize.Height / 2);

            brush.Dispose();
            pen.Dispose();
        }
        public void DrawLineonPdf(XGraphics graph, PointF P1, PointF P2, int stroke)
        {
            Pen blackPen = new Pen(System.Drawing.Color.Black, stroke);

            graph.DrawLine(blackPen, P1, P2);
        }