DrawString() public method

public DrawString ( string s, Font font, Brush brush, PointF point, StringFormat format = null ) : void
s string
font Font
brush Brush
point PointF
format StringFormat
return void
Beispiel #1
7
 private void DrawInput(Graphics g)
 {
     var point = GetPoint();
     g.FillEllipse(Brushes.Chartreuse, point.X, point.Y, 10, 10);
     g.DrawString(string.Format("Frequency: {0,7:####0.0}hz", _frequency), _font, Brushes.BlueViolet, 5f, 5f);
     g.DrawString(string.Format("Volume: {0:0.00}", _volume), _font, Brushes.BlueViolet, 5f, 20f);
 }
        public override void Draw(Graphics g, Pen p)
        {
            base.Draw(g, p);

            var r = this.RectangleF;

            var sText = g.MeasureString(this.ColouredPlace.ColorSetName, new Font("Arial", 8));
            g.FillRectangle(Brushes.Gray, r.Right, r.Top - sText.Height, sText.Width, sText.Height);

            g.DrawString(
                this.ColouredPlace.ColorSetName,
                new Font("Arial", 8),
                Brushes.Blue,
                r.Right,
                r.Top - sText.Height
            );

            var tokensString = this.ColouredPlace.Tokens.ToString();
            var f = new Font("", 7);
            sText = g.MeasureString(tokensString, f);

            g.FillRectangle(Brushes.Green, r.Right, r.Bottom, sText.Width, sText.Height);
            g.DrawString(
                tokensString,
                new Font("", 7),
                Brushes.Black,
                r.Right,
                r.Bottom
            );
        }
        public static void RepertoryImage(Graphics drawDestination)
        {
            StringFormat itemStringFormat = new StringFormat();
            RectangleF itemBox = new RectangleF(10, 30, 42, 10);
            RectangleF itemBox2 = new RectangleF(60, 48, 10, 10);
            itemStringFormat.Alignment = StringAlignment.Center;
            itemStringFormat.LineAlignment = StringAlignment.Far;
            drawDestination.DrawLine(Pens.LightGray,10,10,10,70);
            if (mMscStyle == MscStyle.SDL){
                PointF[] capPolygon = new PointF[3];
                capPolygon[0] = new PointF(61, 40);
                capPolygon[1] = new PointF(53, 44);
                capPolygon[2] = new PointF(53, 36);
                drawDestination.FillPolygon(Brushes.Black,capPolygon);
                drawDestination.DrawString("Lost",new Font("Arial",8),Brushes.Black,itemBox,itemStringFormat);
                drawDestination.DrawString("g",new Font("Arial",8),Brushes.Black,itemBox2,itemStringFormat);
                drawDestination.DrawLine(Pens.Black,10, 40, 60,40);
                drawDestination.FillEllipse(Brushes.Black, new RectangleF(60,35, 10,10));
            }
            else if(mMscStyle == MscStyle.UML2){

                drawDestination.DrawString("Lost",new Font("Arial",8),Brushes.Black,itemBox,itemStringFormat);
                drawDestination.DrawString("g",new Font("Arial",8),Brushes.Black,itemBox2,itemStringFormat);
                drawDestination.DrawLine(Pens.Black,10, 40, 60,40);
                drawDestination.DrawLine(Pens.Black,60, 40, 54,43);
                drawDestination.DrawLine(Pens.Black,60, 40, 54,37);
                drawDestination.FillEllipse(Brushes.Black, new RectangleF(60,35, 10,10));

            }
            itemStringFormat.Dispose();
        }
Beispiel #4
0
        /// <summary>
        /// The Draw function
        /// </summary>
        /// <param name="g"></param>
        public static void Draw(Graphics g)
        {
            //The Score
            g.DrawString("Score: " + score.ToString(), SystemFonts.DefaultFont, GameSettings.TextColor, PointF.Empty);

            //Lives
            g.DrawString("Lives:", SystemFonts.DefaultFont, GameSettings.TextColor, new PointF(0, SystemFonts.DefaultFont.Size + 5.0f));
            for (int i = 0; i < numberOfLives; i++)
            {
                g.FillEllipse(GameSettings.RegularBallColor, new RectangleF(i * 15, (SystemFonts.DefaultFont.Size + 5.0f) * 2.0f, 10.0f, 10.0f));
            }

            //Background playfield
            using (Brush b = new SolidBrush(GameSettings.BackGroundColor))
            {
                g.FillRectangle(b, Rectangle.Round(gameField));
            }

            //The bricks
            foreach (Brick brick in bricks)
            {
                if (brick != null)
                    brick.Draw(g);
            }

            //Player also draws the ball
            player.Draw(g);

            //And the borderline of the playfield
            Pen p = gameField.Contains(MouseAppPosition) ? Pens.Red : Pens.White;

            g.DrawRectangle(p, Rectangle.Round(gameField));
        }
Beispiel #5
0
        // Draw is fired with each paint event of the main form
        public void Draw(Graphics graphics, int frame, bool gameOver)
        {
            graphics.FillRectangle(Brushes.Black, formArea);

            stars.Draw(graphics);
            foreach (Invader invader in invaders)
                invader.Draw(graphics, frame);
            playerShip.Draw(graphics);
            foreach (Shot shot in playerShots)
                shot.Draw(graphics);
            foreach (Shot shot in invaderShots)
                shot.Draw(graphics);

            graphics.DrawString(("Score: " + score.ToString()),
                statsFont, Brushes.Yellow, scoreLocation);
            graphics.DrawString(("Lives: " + livesLeft.ToString()),
                statsFont, Brushes.Yellow, livesLocation);
            graphics.DrawString(("Wave: " + wave.ToString()),
                statsFont, Brushes.Yellow, waveLocation);
            if (gameOver)
            {
                graphics.DrawString("GAME OVER", messageFont, Brushes.Red,
                    (formArea.Width / 4), formArea.Height / 3);
            }
        }
 public static void RepertoryImage(Graphics drawDestination)
 {
     StringFormat itemStringFormat = new StringFormat();
     RectangleF itemBox = new RectangleF(5, 15, 30, 15);
     RectangleF itemBox2 = new RectangleF(5, 35, 70, 15);
     itemStringFormat.Alignment = StringAlignment.Near;
     itemStringFormat.LineAlignment = StringAlignment.Near;
     PointF[] statePolygon = new PointF[5];
     statePolygon[0] = new PointF(5,15);
     statePolygon[1] = new PointF(40,15);
     statePolygon[2] = new PointF(40,25);
     statePolygon[3] = new PointF(35,30);
     statePolygon[4] = new PointF(5,30);
     drawDestination.FillPolygon(Brushes.White,statePolygon);
     drawDestination.DrawPolygon(Pens.LightGray,statePolygon);
     drawDestination.DrawRectangle(Pens.LightGray,5,15,70,50);
     drawDestination.DrawString("frag",new Font("Arial",8,FontStyle.Regular),Brushes.LightGray,itemBox,itemStringFormat);
     Pen rPen = new Pen(Color.Black);
     float[] pattern = {4f,4f};
     rPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
     rPen.DashPattern = pattern;
     itemStringFormat.Alignment = StringAlignment.Center;
     drawDestination.DrawString("separator",new Font("Arial",8,FontStyle.Italic),Brushes.Black,itemBox2,itemStringFormat);
     drawDestination.DrawLine(rPen, 5, 50, 75, 50);
     rPen.Dispose();
     itemStringFormat.Dispose();
 }
        private static void DrawNeuron(this Network network, Neuron neuron, Graphics graphic)
        {
            Pen pen = new Pen(Color.Black);
            Point point = Translate(network, neuron);
            Size size = new Size(10, 10);
            Rectangle r = new Rectangle(point, size);

            Color color = Blend(Color.Gray, Color.Red, (neuron.Signal - 0.5));

            Brush brush = new SolidBrush(color);
            graphic.FillEllipse(brush, r);
            graphic.DrawEllipse(pen, r);

            // Draw signal text
            Font font = new Font(FontFamily.GenericSerif, 8);
            Brush fontbrush = new SolidBrush(Color.DarkBlue);
            point = point.Shift(0, 10);

            graphic.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
            graphic.DrawString(neuron.Signal.ToString("f2"), font, fontbrush, point);

            // Draw Error:
            point = point.Shift(0, 10);
            fontbrush = new SolidBrush(Color.Red);
            graphic.DrawString(neuron.ErrorGradient.ToString("f2"), font, fontbrush, point);
        }
Beispiel #8
0
        private static void ProcessLabelItem(LabelItem labelItem, Graphics g, PrintLabelSettings settings)
        {
            switch (labelItem.LabelType)
            {
                case LabelTypesEnum.Label:
                    g.DrawString(labelItem.LabelText,
                        new Font(labelItem.FontName ?? "Arial", labelItem.FontSize, (labelItem.IsBold ? FontStyle.Bold : FontStyle.Regular) | (labelItem.IsItalic ? FontStyle.Italic : FontStyle.Regular)),
                        Brushes.Black, labelItem.StartX, labelItem.StartY);
                    break;
                case LabelTypesEnum.BarCode:
                    var content = labelItem.LabelText;

                    var writer = new BarcodeWriter
                    {
                        Format = BarcodeFormat.CODE_128,
                        Options = new ZXing.QrCode.QrCodeEncodingOptions
                        {
                            ErrorCorrection = ZXing.QrCode.Internal.ErrorCorrectionLevel.H,
                            Width = settings.BarCodeMaxWidth,
                            Height = settings.BarCodeHeight,
                            PureBarcode = true,
                        }
                    };
                    var barCodeBmp = writer.Write(content);
                    g.DrawImageUnscaled(barCodeBmp, labelItem.StartX, labelItem.StartY);
                    break;
                case LabelTypesEnum.Stamp:
                    var pen = new Pen(Color.Black, 2);
                    g.DrawEllipse(pen, labelItem.StartX, labelItem.StartY, settings.StampDiameter, settings.StampDiameter);
                    g.DrawString(labelItem.LabelText,
                        new Font(labelItem.FontName ?? "Arial", labelItem.FontSize, (labelItem.IsBold ? FontStyle.Bold : FontStyle.Regular) | (labelItem.IsItalic ? FontStyle.Italic : FontStyle.Regular)),
                        Brushes.Black, labelItem.StartX + 2, labelItem.StartY + 11);
                    break;
            }
        }
Beispiel #9
0
		private static void DrawContent(Graphics g, Rectangle rect, string title, string body)
		{
			if (!string.IsNullOrEmpty(title))
			{
				using (Font titleFont = new Font(FontFamily.GenericSansSerif, 18.0f, FontStyle.Bold))
				{
					g.DrawString(title, titleFont, Brushes.Black, rect);

					//Update the rect to position the body text.
					SizeF titleSize = g.MeasureString(title, titleFont, rect.Width);
					int titleHeight = (int)titleSize.Height + 1;
					rect.Offset(0, titleHeight);
					rect.Height -= titleHeight;
				}
			}

			if (!string.IsNullOrEmpty(body))
			{
				using (Font bodyFont = new Font(FontFamily.GenericSerif, 12.0f, FontStyle.Regular))
				{
					rect.Inflate(-2, 0);
					g.DrawString(body, bodyFont, Brushes.Black, rect);
				}
			}
		}
Beispiel #10
0
		private void DrawContent(Graphics graphics, Rectangle rect)
		{
			using (LinearGradientBrush brush = new LinearGradientBrush(new Point(0, 0),
				new Point(rect.Width, rect.Height), Color.White, Color.LightGreen))
			{
				graphics.FillRectangle(brush, rect);
			}

			if (!string.IsNullOrEmpty(_title))
			{
				using (Font titleFont = new Font(FontFamily.GenericSansSerif, 18.0f, FontStyle.Bold))
				{
					graphics.DrawString(_title, titleFont, Brushes.Black, rect);

					// Update the rect to position the body text
					SizeF titleSize = graphics.MeasureString(_title, titleFont, rect.Width);
					int titleHeight = (int)titleSize.Height + 1;
					rect.Offset(0, titleHeight);
					rect.Height -= titleHeight;
				}
			}

			if (!string.IsNullOrEmpty(_description))
			{
				using (Font bodyFont = new Font(FontFamily.GenericSerif, 12.0f, FontStyle.Regular))
				{
					rect.Inflate(-2, 0);
					graphics.DrawString(_description, bodyFont, Brushes.Black, rect);
				}
			}
		}
Beispiel #11
0
        public override void Draw(Graphics g, int target)
        {
            Image head = PicLoader.Read("NPC", string.Format("{0}.PNG", Figue));
            int ty = Y + 50;
            int ty2 = ty;
            if (target == Id)
            {
                g.DrawImage(head, X - 5, ty - 5, Width*5/4, Width * 5 / 4);
                ty2 -= 2;
            }
            else
            {
                g.DrawImage(head, X, ty, Width, Width);
            }

            head.Dispose();

            Font font = new Font("΢ÈíÑźÚ", 12*1.33f, FontStyle.Bold, GraphicsUnit.Pixel);
            g.DrawString(Name, font, Brushes.Black, X + 3, Y + Height + 30);
            g.DrawString(Name, font, Brushes.White, X, Y + Height + 27);
            font.Dispose();

            if (taskFinishs.Count > 0)
            {
                Image img = PicLoader.Read("System", "MarkTaskEnd.PNG");
                g.DrawImage(img, X + 15, ty2 - 35, 21, 30);
                img.Dispose();
            }
            else if (taskAvails.Count > 0)
            {
                Image img = PicLoader.Read("System", "MarkTaskBegin.PNG");
                g.DrawImage(img, X + 15, ty2 - 35, 24, 30);
                img.Dispose();
            }
        }
Beispiel #12
0
 private static void DrawText(PointType type, TextDrawer p , Graphics g)
 {
     Font myFont = null;
     SolidBrush blackBrush = null;
     switch(type)
     {
         case PointType.CENTER:
             myFont = new Font("Verdana", 14);
             blackBrush = new SolidBrush(Color.Red);
             g.DrawString(p.text, myFont, blackBrush, p.x, p.y);
             break;
         case PointType.EDAGE:
             myFont = new Font("Verdana", 12);
             blackBrush = new SolidBrush(Color.Red);
             g.DrawString(p.text, myFont, blackBrush, p.x, p.y);
             break;
         case PointType.NORMAL:
             myFont = new Font("Courier New", 8);
             blackBrush = new SolidBrush(Color.Green);
             g.DrawString(p.text, myFont, blackBrush, p.x, p.y);
             break;
         case PointType.GROUP:
             myFont = new Font("Verdana", 12);
             blackBrush = new SolidBrush(Color.RoyalBlue);
             g.DrawString(p.text, myFont, blackBrush, p.x, p.y);
             break;
     }
 }
Beispiel #13
0
 public void Draw(Graphics g, int animationCell, bool gameOver)
 {
     g.FillRectangle(Brushes.Black, boundaries);
     stars.Draw(g);
     playerShip.Draw(g);
     foreach (Invader invader in invaders)
         invader.Draw(g, animationCell);
     foreach (Shot shot in playerShots)
         shot.Draw(g);
     foreach (Shot shot in invaderShots)
         shot.Draw(g);
     using (Font font = new Font("Arial", 24, FontStyle.Bold))
         g.DrawString(score.ToString(), font, Brushes.Red, boundaries.X + 20, boundaries.Y + 20);
     g.DrawImageUnscaled(Properties.Resources.player,
             new Point(boundaries.Right - 110, boundaries.Top + 10));
     using (Font font = new Font("Arial", 20))
         g.DrawString("X " + livesLeft, font, Brushes.Yellow, boundaries.Right - 50, boundaries.Top + 10);
     if (gameOver)
     {
         using (Font font = new Font("Arial", 40))
             g.DrawString("Game Over", font, Brushes.Purple,
                 (boundaries.Width / 3), boundaries.Height / 3);
         using (Font font = new Font("Arial", 20))
             g.DrawString("Press 'Q' to quit\nor 'S' to restart", font, Brushes.Purple,
                 boundaries.Width / 3 + 45, boundaries.Height / 3 + 50);
     }
 }
Beispiel #14
0
 public static void RepertoryImage(Graphics drawDestination)
 {
     StringFormat itemStringFormat = new StringFormat();
     RectangleF itemBox = new RectangleF(15, 30, 50, 20);
     itemStringFormat.Alignment = StringAlignment.Center;
     itemStringFormat.LineAlignment = StringAlignment.Center;
     drawDestination.DrawLine(Pens.LightGray,40,10,40,70);
     if (mMscStyle == MscStyle.SDL){
         PointF[] statePolygon = new PointF[6];
         statePolygon[0] = new PointF(5,40);
         statePolygon[1] = new PointF(15,30);
         statePolygon[2] = new PointF(65,30);
         statePolygon[3] = new PointF(75,40);
         statePolygon[4] = new PointF(65,50);
         statePolygon[5] = new PointF(15,50);
         drawDestination.FillPolygon(Brushes.White,statePolygon);
         drawDestination.DrawString("State",new Font("Arial",8),Brushes.Black,itemBox,itemStringFormat);
         drawDestination.DrawPolygon(Pens.Black,statePolygon);
     }
     else if(mMscStyle == MscStyle.UML2){
             drawDestination.FillRectangle(Brushes.White,itemBox);
             drawDestination.FillEllipse(Brushes.White,5,30,20,20);
             drawDestination.FillEllipse(Brushes.White,55,30,20,20);
             drawDestination.DrawLine(Pens.Black,15,30,65,30);
             drawDestination.DrawLine(Pens.Black,15,50,65,50);
             drawDestination.DrawArc(Pens.Black,5,30,20,20,90,180);
             drawDestination.DrawArc(Pens.Black,55,30,20,20,270,180);
             drawDestination.DrawString("State",new Font("Arial",8),Brushes.Black,itemBox,itemStringFormat);
     }
     itemStringFormat.Dispose();
 }
Beispiel #15
0
        protected override void drawSelf(Graphics g)
        {
            int yRect = 0;
            g.DrawRectangle(new Pen(Color.Black, 1), 0, 0, this.Size.Width - 1, this.Size.Height - 1);

            //Vẽ TableName
            string nameTable = table.name;
            g.DrawRectangle(new Pen(Color.Black, 1), 0, 0, this.Size.Width-1, ShapeSetting.heightPieceShape);
            g.FillRectangle(ShapeSetting.brushTableName,new Rectangle(1, 1, this.Size.Width-2, ShapeSetting.heightPieceShape-1));
            g.DrawString(nameTable, new Font("Arial", 10), ShapeSetting.brushText, new Rectangle(10, yRect, this.Size.Width-1, ShapeSetting.heightPieceShape));

            //Vẽ Attribute
            int maxLength = maxLengthText();
            foreach (Column c in table.columns)
            {
                yRect += 20;
                string strAttribute = "";
                strAttribute += c.Name.PadRight(maxLength);
                strAttribute += " " + c.DataType.PadRight(10);
                if (c.PrimaryKey)
                    strAttribute += "(pk)";
                if(c.ForeignKey)
                    strAttribute += "(fk)";
                g.DrawString(strAttribute, this.Font, ShapeSetting.brushText, new Rectangle(10, yRect, this.Size.Width - 1, ShapeSetting.heightPieceShape));
            }
        }
Beispiel #16
0
 public void _drawTabHeader(Graphics nGraphics, Font nFont, Rectangle nRectangle)
 {
     int width_ = nRectangle.Height - 2;
     switch (mSideTabStatus)
     {
         case SideTabStatus_.mNormal_:
             ControlPaint.DrawBorder3D(nGraphics, nRectangle, Border3DStyle.RaisedInner);
             nGraphics.DrawImage(mSideTabImage, nRectangle.X + 1, nRectangle.Y + 1, width_, width_);
             nGraphics.DrawString(mSideTabName, nFont, SystemBrushes.ControlText, new PointF(nRectangle.X + width_ + 2, nRectangle.Y + 2));
             break;
         case SideTabStatus_.mSelected_:
             ControlPaint.DrawBorder3D(nGraphics, nRectangle, Border3DStyle.Sunken);
             nGraphics.DrawImage(mSideTabImage, nRectangle.X + 1, nRectangle.Y + 1, width_, width_);
             nGraphics.DrawString(mSideTabName, nFont, SystemBrushes.ControlText, new PointF(nRectangle.X + width_ + 2, nRectangle.Y + 2));
             break;
         case SideTabStatus_.mDragged_:
             ControlPaint.DrawBorder3D(nGraphics, nRectangle, Border3DStyle.RaisedInner);
             nRectangle.X += 1;
             nRectangle.Y += 1;
             nRectangle.Width -= 2;
             nRectangle.Height -= 2;
             nGraphics.FillRectangle(SystemBrushes.ControlDarkDark, nRectangle);
             nGraphics.DrawString(mSideTabName, nFont, SystemBrushes.HighlightText, new PointF(nRectangle.X + width_ , nRectangle.Y));
             break;
     }
 }
Beispiel #17
0
        public override void Draw(Graphics g)
        {
            System.Drawing.Size st = g.MeasureString(Marker.ToolTipText, Font).ToSize();
             System.Drawing.Rectangle rect = new System.Drawing.Rectangle(Marker.ToolTipPosition.X, Marker.ToolTipPosition.Y - st.Height, st.Width + TextPadding.Width, st.Height + TextPadding.Height);
             rect.Offset(Offset.X, Offset.Y);

             using(GraphicsPath objGP = new GraphicsPath())
             {
            objGP.AddLine(rect.X + 2 * Radius, rect.Y + rect.Height, rect.X + Radius, rect.Y + rect.Height + Radius);
            objGP.AddLine(rect.X + Radius, rect.Y + rect.Height + Radius, rect.X + Radius, rect.Y + rect.Height);

            objGP.AddArc(rect.X, rect.Y + rect.Height - (Radius * 2), Radius * 2, Radius * 2, 90, 90);
            objGP.AddLine(rect.X, rect.Y + rect.Height - (Radius * 2), rect.X, rect.Y + Radius);
            objGP.AddArc(rect.X, rect.Y, Radius * 2, Radius * 2, 180, 90);
            objGP.AddLine(rect.X + Radius, rect.Y, rect.X + rect.Width - (Radius * 2), rect.Y);
            objGP.AddArc(rect.X + rect.Width - (Radius * 2), rect.Y, Radius * 2, Radius * 2, 270, 90);
            objGP.AddLine(rect.X + rect.Width, rect.Y + Radius, rect.X + rect.Width, rect.Y + rect.Height - (Radius * 2));
            objGP.AddArc(rect.X + rect.Width - (Radius * 2), rect.Y + rect.Height - (Radius * 2), Radius * 2, Radius * 2, 0, 90); // Corner

            objGP.CloseFigure();

            g.FillPath(Fill, objGP);
            g.DrawPath(Stroke, objGP);
             }

            #if !PocketPC
             g.DrawString(Marker.ToolTipText, Font, Brushes.Navy, rect, Format);
            #else
             g.DrawString(ToolTipText, ToolTipFont, TooltipForeground, rect, ToolTipFormat);
            #endif
        }
Beispiel #18
0
        public void Draw(Graphics g, bool enable)
        {
            Image back = PicLoader.Read("System", "ItemGrid.JPG");
            g.DrawImage(back, x+3, y+3, 32, 32);
            back.Dispose();

            if (itemPos >= 0)
            {
                Font font = new Font("Aril", 11*1.33f, FontStyle.Bold, GraphicsUnit.Pixel);
                if (enable)
                {
                    g.DrawImage(HItemBook.GetHItemImage(UserProfile.InfoBag.Items[itemPos].Type), x + 3, y + 3, 32, 32);
                }
                else
                {
                    Rectangle ret = new Rectangle(x + 3, y + 3, 32, 32);
                    g.DrawImage(HItemBook.GetHItemImage(UserProfile.InfoBag.Items[itemPos].Type), ret, 0, 0, 64, 64, GraphicsUnit.Pixel, HSImageAttributes.ToGray);
                }

                g.DrawString(UserProfile.InfoBag.Items[itemPos].Value.ToString(), font, Brushes.Black, x + 4, y + 4);
                g.DrawString(UserProfile.InfoBag.Items[itemPos].Value.ToString(), font, Brushes.White, x + 3, y + 3);

                if (percent>1)
                {
                    Brush brush = new SolidBrush(Color.FromArgb(200, Color.Black));
                    g.FillRectangle(brush, x, y, 35, 35*percent/100);
                    brush.Dispose();
                }

                font.Dispose();
            }
        }
        public override void Draw(Graphics gr, Point position, Range range)
        {
            var tb = range.tb;
            using (Brush brush = new SolidBrush(_pen.Color))
                foreach (var place in range)
                {
                    switch (tb[place].c)
                    {
                        case ' ':
                            var point = tb.PlaceToPoint(place);
                            point.Offset(tb.CharWidth/2, tb.CharHeight/2);
                            gr.DrawLine(_pen, point.X, point.Y, point.X + 1, point.Y);
                            break;

                        case '\0':
                            point = tb.PlaceToPoint(place);
                            gr.DrawString("~", tb.Font, brush, point.X, point.Y);
                            break;
                    }

                    if (tb[place.iLine].Count - 1 == place.iChar)
                    {
                        var point = tb.PlaceToPoint(place);
                        point.Offset(tb.CharWidth, 0);
                        gr.DrawString("¶", tb.Font, brush, point);
                    }
                }
        }
        private void DrawBarcodeText(ref Graphics g, string messagetext, int textlength, SolidBrush ForeBrush, int sfheight, bool texttostretch, int textalignment)
        {
            string s = "";
            messagetext = messagetext.Trim();
            StringFormat format = new StringFormat();
            format.Alignment = StringAlignment.Center;
            if (texttostretch)
            {
                for (int i = 0; i < messagetext.Length; i++)
                {
                    s = "" + messagetext[i];
                    Rectangle layoutRectangle = new Rectangle(this.leftmargin + ((i * textlength) / messagetext.Length), (this.topmargin + this.barheight) + this.textmargin, textlength / messagetext.Length, 2 * sfheight);
                    g.DrawString(s, this.txtFont, ForeBrush, layoutRectangle, format);
                }
            }
            else
            {
                Rectangle rectangle2 = new Rectangle(this.leftmargin, (this.topmargin + this.barheight) + this.textmargin, textlength, 2 * sfheight);
                switch (textalignment)
                {
                    case 0:
                        format.Alignment = StringAlignment.Near;
                        g.DrawString(messagetext, this.txtFont, ForeBrush, rectangle2, format);
                        return;

                    case 2:
                        format.Alignment = StringAlignment.Far;
                        g.DrawString(messagetext, this.txtFont, ForeBrush, rectangle2, format);
                        return;
                }
                format.Alignment = StringAlignment.Center;
                g.DrawString(messagetext, this.txtFont, ForeBrush, rectangle2, format);
            }
        }
        public override void DrawRect(System.Drawing.RectangleF dirtyRect)
        {
            Graphics g = new Graphics();

            g.Clear(Color.White);

            int width = 30;
            int height = 128;
            int y = 10;
            // Create opaque color maps with alpha = 255:
            ColorMap cm = new ColorMap();
            Font aFont = new Font("Arial", 20, FontStyle.Bold);
            g.DrawString("OPAQUE COLOR", aFont, Brushes.Black, 10, 60);
            DrawColorBar(g, 10, y, width, height, cm, "Spring");
            DrawColorBar(g, 10 + 40, y, width, height, cm, "Summer");
            DrawColorBar(g, 10 + 2 * 40, y, width, height, cm, "Autumn");
            DrawColorBar(g, 10 + 3 * 40, y, width, height, cm, "Winter");
            DrawColorBar(g, 10 + 4 * 40, y, width, height, cm, "Jet");
            DrawColorBar(g, 10 + 5 * 40, y, width, height, cm, "Gray");
            DrawColorBar(g, 10 + 6 * 40, y, width, height, cm, "Hot");
            DrawColorBar(g, 10 + 7 * 40, y, width, height, cm, "Cool");

            y = y + 150;
            // Create transparent color maps with alpha = 150:
            ColorMap cm1 = new ColorMap(64, 150);
            g.DrawString("TRANSPARENT COLOR", aFont, Brushes.Black, 10, 210);
            DrawColorBar(g, 10, y, width, height, cm1, "Spring");
            DrawColorBar(g, 10 + 40, y, width, height, cm1, "Summer");
            DrawColorBar(g, 10 + 2 * 40, y, width, height, cm1, "Autumn");
            DrawColorBar(g, 10 + 3 * 40, y, width, height, cm1, "Winter");
            DrawColorBar(g, 10 + 4 * 40, y, width, height, cm1, "Jet");
            DrawColorBar(g, 10 + 5 * 40, y, width, height, cm1, "Gray");
            DrawColorBar(g, 10 + 6 * 40, y, width, height, cm1, "Hot");
            DrawColorBar(g, 10 + 7 * 40, y, width, height, cm1, "Cool");
        }
 public static void FillRectangleWithNumeric(Graphics g, int x, int y ,int w, int h, string text, string upperText)
 {
     g.FillRectangle(ComputingHelper.getRandomBrush(), x, y ,w, h);
     g.DrawRectangle(Pens.Black, x, y, w, h);
     g.DrawString(text, SystemFonts.DefaultFont, Brushes.Black, x + w / 2, y + h / 2);
     g.DrawString(upperText, SystemFonts.DefaultFont, Brushes.Black, x, y );
 }
        public override void DrawRect(System.Drawing.RectangleF dirtyRect)
        {
            Graphics g = new Graphics();
            int offset = 20;

            // Invert matrix:
            Matrix m = new Matrix(1, 2, 3, 4, 0, 0);
            g.DrawString("Original Matrix:", this.Font, Brushes.Black, 10, 10);
            DrawMatrix(m, g, 10, 10 + offset);
            g.DrawString("Inverted Matrix:", this.Font, Brushes.Black, 10, 10 + 2*offset);
            m.Invert();
            DrawMatrix(m, g, 10, 10 + 3 * offset);

            // Matrix multiplication - MatrixOrder.Append:
            Matrix m1 = new Matrix(1, 2, 3, 4, 0, 1);
            Matrix m2 = new Matrix(0, 1, 2, 1, 0, 1);
            g.DrawString("Original Matrices:", this.Font, Brushes.Black, 10, 10 + 4 * offset);
            DrawMatrix(m1, g, 10, 10 + 5 * offset);
            DrawMatrix(m2, g, 10 + 130, 10 + 5 * offset);
            m1.Multiply(m2, MatrixOrder.Append);
            g.DrawString("Resultant Matrix - Append:", this.Font, Brushes.Black, 10, 10 + 6 * offset);
            DrawMatrix(m1, g, 10, 10 + 7 * offset);

            // Matrix multiplication - MatrixOrder.Prepend:
            m1 = new Matrix(1, 2, 3, 4, 0, 1);
            m1.Multiply(m2, MatrixOrder.Prepend);
            g.DrawString("Resultant Matrix - Prepend:", this.Font, Brushes.Black, 10, 10 + 8 * offset);
            DrawMatrix(m1, g, 10, 10 + 9 * offset);
        }
Beispiel #24
0
 /// <summary>
 /// Implement the display of the value's representation.</summary>
 /// <param name="g">The Graphics object</param>
 /// <param name="area">Rectangle delimiting area to paint</param>
 public override void PaintValue(Graphics g, Rectangle area)
 {
     if (ReadOnly)
         g.DrawString(Value, Theme.Font, Theme.ReadonlyBrush, area.Left + Theme.Padding.Left, area.Top); 
     else
         g.DrawString(Value, Theme.Font, Theme.TextBrush, area.Left + Theme.Padding.Left, area.Top); 
 }
        public void draw(Graphics g)
        {
            Bitmap t = SpaceInvaders.Properties.Resources.titleMenu;

            g.DrawImage(t,Game.gameSize.Width/2-t.Width/2, 1,t.Width,t.Height);

            g.DrawImage(SpaceInvaders.Properties.Resources.ship1,new Point(200,200));
            g.DrawImage(SpaceInvaders.Properties.Resources.ship2, new Point(500, 500));
            g.DrawImage(SpaceInvaders.Properties.Resources.ship3, new Point(400, 50));
            g.DrawImage(SpaceInvaders.Properties.Resources.ship4, new Point(100, 300));
            g.DrawImage(SpaceInvaders.Properties.Resources.ship5, new Point(40, 40));
            g.DrawImage(SpaceInvaders.Properties.Resources.ship6, new Point(50, 150));
            g.DrawImage(SpaceInvaders.Properties.Resources.ship7, new Point(500, 400));
            g.DrawImage(SpaceInvaders.Properties.Resources.ship8, new Point(100, 500));
            g.DrawImage(SpaceInvaders.Properties.Resources.ship9, new Point(300, 450));

            int x = Game.gameSize.Width / 2;
            int y = Game.gameSize.Height / 2 - (this.items.Count/2 * this.espace );
            int dy = 0;
            g.DrawString(">", Game.defaultFont, Game.blackBrush, x-50 , y + this.espace *this.currentChose );
            g.DrawString(items[this.currentChose].Info ,new  Font("Times New Roman", 12, FontStyle.Bold, GraphicsUnit.Pixel),Game.blackBrush, x - 50, y +30 + this.espace * this.currentChose);
            foreach (MenuItem mi in items) {
                g.DrawString(mi.Name, Game.defaultFont, Game.blackBrush,x,y + dy);

                dy += this.espace;

            }
        }
Beispiel #26
0
        private void PrintMix(DataRow row, DataRow[] rows, Graphics g)
        {
            int top = 3;
            Font font = new Font("����", 10);
            g.PageUnit = GraphicsUnit.Millimeter;

            g.DrawRectangle(Pens.Black, 0, 0, 105, 75);

            g.DrawString("���κ�           ����  ���  ����  ��̬  �ȼ�", font, Brushes.Black, 5, top);
            for (int i = 0; i < rows.Length; i++)
            {
                string s = string.Format("{0}{1}{2}{3}{4}{5}",
                    rows[i]["PRODUCTCODE"].ToString().PadRight(18, ' '),
                    rows[i]["ORIGINAL"].ToString().PadRight(4, ' '),
                    rows[i]["YEARS"].ToString().PadRight(6, ' '),
                    rows[i]["QUANTITY"].ToString().PadRight(4, ' '),
                    rows[i]["STYLE"].ToString().PadRight(4, ' '),
                    rows[i]["GRADE"]);
                g.DrawString(s, font, Brushes.Black, 5, top + (i + 1) * 3);
            }

            g.DrawString("����:" + row["SCHEDULENO"].ToString(), font, Brushes.Black, 5, top + 20);
            //g.DrawString("ģ��:" + row["BATCHUNIT"].ToString(), font, Brushes.Black, 40, top + 20);
            g.DrawString("����:" + row["SCHEDULEDATE"].ToString(), font, Brushes.Black, 75, top + 20);

            string barcode = row["BARCODE"].ToString();
            Image myimg = GenCode128.Code128Rendering.MakeBarcodeImage(barcode, 1, true);
            g.DrawImage(myimg, new Rectangle(2, top + 25, 100, 40));

            font = new Font("����", 10);
            g.DrawString(barcode, font, Brushes.Black, 20, 69);
        }
Beispiel #27
0
    protected override void _DrawItem(Graphics g, int index, int y)
    {
      //base._DrawItem(g,  index,  y);      return;

      //this._Broker.LoadItem(index);
      _Broker.Index = index;
      BookItem item = _Broker.Current;
      int x = 4;
      g.DrawRectangle(this._PenBorder, x, y, _Width - 2 * x, this._ItemHeight);
      g.FillRectangle(Brushes.Khaki, x + 1, y + 1, _Width - 2 * x-1, this._ItemHeight-1);

      x += 3;
      g.DrawString(item.Author, this._FontAutor , Brushes.Black, x, y);

      SizeF size = g.MeasureString(item.Author, this._FontAutor);
      x += (int)size.Width + 20;
      g.DrawString(item.Title, this._FontTitle, Brushes.Blue, x, y);

      size = g.MeasureString(item.Author, this._FontTitle);
      if (index == this._SelectedIndex)
      {
        g.FillEllipse(Brushes.WhiteSmoke, _Width - 35, y + 5, 20, 20);
        g.DrawEllipse(this._PenBorder, _Width - 35, y + 5, 20, 20);
      }
    }
        internal void ShowInformation(Graphics graphics)
        {
            Rectangle rectOutline = new Rectangle((int)(_gameState.TotalWindowArea.Width/2-_gameState.GameArea.Width/2+2),
                                                  (int)(_gameState.TotalWindowArea.Height/2 + _gameState.GameArea.Height/2 - _gameState.GameArea.Height/3),
                                                  150,
                                                  40);
            graphics.DrawRectangle(new Pen(new SolidBrush(Color.Black)), rectOutline);

            Rectangle rectBackground = new Rectangle(rectOutline.X + 1, rectOutline.Y + 1,
                                                     rectOutline.Width - 1, rectOutline.Height - 1);
            graphics.FillRectangle(new SolidBrush(Color.Gray), rectBackground);

            //Spell Name
            if (this.hidden != true)
            {
                graphics.DrawString(spellName, new Font("Arial", 8, FontStyle.Bold), new SolidBrush(Color.BlanchedAlmond),
                                   rectBackground.X, rectBackground.Y + 5);
            }
            else
                graphics.DrawString("???", new Font("Arial", 8, FontStyle.Bold), new SolidBrush(Color.BlanchedAlmond),
                                   rectBackground.X, rectBackground.Y + 5);
            //Spell Cost
            graphics.DrawString(Spell.GetManaCost().ToString(), new Font("Arial", 8), new SolidBrush(Color.BlanchedAlmond),
                                rectBackground.X, rectBackground.Y + 20);
        }
Beispiel #29
0
        public void Gen(List<BiliInterfaceInfo> infos)
        {
            Log.Info("【主榜】开始生成" + infos.Count + "个图片");

            for (int i = 0; i < infos.Count; i++)
            {
                image = Properties.Resources.zhubang;
                g = Graphics.FromImage(image);
                g.SmoothingMode = SmoothingMode.AntiAlias;

                ////
                Log.Info("正在生成 - " + infos[i].AVNUM);

                g.DrawString(infos[i].title, f, b, 350, 1000);
                g.DrawString(infos[i].AVNUM, f, b, 375, 900);
                g.DrawString(infos[i].created_at.Substring(0, infos[i].created_at.IndexOf(" ")), f, b, 900, 900);
                g.DrawString("UP:" + infos[i].author, f, b, 330, 800);

                Pen pp = new Pen(Color.Yellow, 3.5f);
                GraphicsPath pth = new GraphicsPath();
                pth.AddString(infos[i].Fpaiming.ToString("D2"), new FontFamily("微软雅黑"), (int)FontStyle.Bold, 180, new Point(1750, 0), sf);
                g.FillPath(new SolidBrush(Color.White), pth);
                g.DrawPath(pp, pth);

                AddKongxin(infos[i].Fdefen.ToString(), 160, 960, 70);
                AddKongxin(infos[i].play.ToString(), 1625, 500, 70);
                AddKongxin(infos[i].review.ToString(), 1820, 330, 50);
                AddKongxin(infos[i].coins.ToString(), 1810, 710, 50);
                AddKongxin(infos[i].favorites.ToString(), 1600, 825, 60);

                /*
                g.DrawString(infos[i].Fpaiming.ToString(), new Font("微软雅黑", 60, FontStyle.Bold), b, 110, nn - 30);

                g.DrawString(infos[i].AVNUM.Substring(2), f, b, 725, nn);
                g.DrawString(infos[i].Fdefen.ToString(), f, b, 1160, nn);
                if (infos[i].author.Length <= 6)
                {
                    g.DrawString(infos[i].author, f, b, new RectangleF(1518, nn, 320, 320));
                    //g.DrawString(infos[i].up, f, b, 1518, nn);
                }
                else
                {
                    g.DrawString(infos[i].author, f, b, new RectangleF(1518, nn, 320, 320));
                    //g.DrawString(infos[i].up.Substring(0, 6), f, b, 1518, nn);
                    //g.DrawString(infos[i].up.Substring(6), f, b, 1518, nn + 74);
                }

                g.DrawString(infos[i].created_at, f, b, 880, nn + 148);
                */

                ////

                string url = Environment.CurrentDirectory + @"\pic\Rank" + infos[i].Fpaiming + ".png";
                Log.Info("保存图片 " + url);
                image.Save(url);
            }

            Log.Info("主榜图片批量生成完成");
        }
Beispiel #30
0
    /// <summary>
    /// 在图片上增加文字水印
    /// </summary>
    /// <param name="Path">原服务器图片路径</param>
    /// <param name="Path_sy">生成的带文字水印的图片路径</param>
    public static void AddWater(string Path, string Path_sy)
    {
        string addText = "51aspx.com";

        System.Drawing.Image    image = System.Drawing.Image.FromFile(Path);
        System.Drawing.Graphics g     = System.Drawing.Graphics.FromImage(image);
        g.DrawImage(image, 0, 0, image.Width, image.Height);
        System.Drawing.Font  f = new System.Drawing.Font("Verdana", 60);
        System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.Green);

        g.DrawString(addText, f, b, 35, 35);
        g.Dispose();

        image.Save(Path_sy);
        image.Dispose();
    }
Beispiel #31
0
    private void OutputImage()
    {
        Response.ContentType = "image/png";
        Response.AddHeader("Content-Disposition", "attachment:filename=icon2011111802.png");
        string fullpath = HttpContext.Current.Server.MapPath("~/images/icon2011111802.png");

        using (System.Drawing.Bitmap bitmaip = new System.Drawing.Bitmap(fullpath))
        {
            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmaip))
            {
                //add watermark to the image

                g.DrawString("pngExample", new System.Drawing.Font("宋体", 14f), System.Drawing.Brushes.YellowGreen, bitmaip.Width, bitmaip.Height);
            }
            bitmaip.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
        }
    }
Beispiel #32
0
    /// <summary>
    /// 在图片上添加文字水印
    /// </summary>
    /// <param name="path">要添加水印的图片路径</param>
    /// <param name="syPath">生成的水印图片存放的位置</param>
    public static void AddWaterWord(Stream path, string syPath,float x,float y,string syWord)
    {
       
        System.Drawing.Image image = System.Drawing.Image.FromStream(path);

        //新建一个画板
        System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(image);
        graphic.DrawImage(image, 0, 0, image.Width, image.Height);

        //设置字体
        System.Drawing.Font f = new System.Drawing.Font("PingFang SC", 28);

        //设置字体颜色
        System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.Black);

        graphic.DrawString(syWord, f, b, x, y);
        graphic.Dispose();

        //保存文字水印图片
        image.Save(syPath);
        image.Dispose();

    }
    public void AutoImage(string strCompanyName)
    {
        Int16 swidth = Convert.ToInt16(strCompanyName.Length * 13);

        System.Drawing.Bitmap   objBMP      = new System.Drawing.Bitmap(swidth, 30);
        System.Drawing.Graphics objGraphics = System.Drawing.Graphics.FromImage(objBMP);
        objGraphics.Clear(System.Drawing.Color.White);
        objGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
        //' Configure font to use for text
        System.Drawing.Font objFont = new System.Drawing.Font("Arial", 15, System.Drawing.FontStyle.Bold);

        string randomStr = strCompanyName;

        int[] myIntArray = new int[6];
        int   x;

        //That is to create the random # and add it to our string
        //Random autoRand = new Random();
        //for (x = 0; x < 6; x++)
        //{
        //    myIntArray[x] = System.Convert.ToInt32(autoRand.Next(0, 9));
        //    randomStr += (myIntArray[x].ToString());
        //}
        //This is to add the string to session cookie, to be compared later


        //' Write out the text
        objGraphics.DrawString(strCompanyName, objFont, System.Drawing.Brushes.Black, 3, 3);

        //' Set the content type and return the image
        //Response.ContentType = "image/GIF";
        File.Delete(HttpContext.Current.Server.MapPath("~\\provider\\LogoImages\\Default.jpg"));
        objBMP.Save(HttpContext.Current.Server.MapPath("~\\provider\\LogoImages\\Default.jpg"), objBMP.RawFormat);
        objFont.Dispose();
        objGraphics.Dispose();
        objBMP.Dispose();
    }
    private byte[] RenderFontTextToBitmapArray(int width, int height, System.Drawing.Font font, string textToRender, System.Drawing.Brush brush)
    {
        System.Drawing.Bitmap     bmp   = new System.Drawing.Bitmap(width, height);
        System.Drawing.RectangleF rectf = new System.Drawing.RectangleF(0, 0, bmp.Width, bmp.Height);
        System.Drawing.Graphics   g     = System.Drawing.Graphics.FromImage(bmp);
        g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
        g.PixelOffsetMode   = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
        g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
        System.Drawing.StringFormat format = new System.Drawing.StringFormat()
        {
            Alignment     = System.Drawing.StringAlignment.Center,
            LineAlignment = System.Drawing.StringAlignment.Center
        };

        g.DrawString(textToRender, font, brush, rectf, format);

        g.Flush();
        using (MemoryStream ms = new MemoryStream())
        {
            bmp.Save(ms, bmp.RawFormat);
            return(ms.ToArray());
        }
    }
Beispiel #35
0
 protected void TitleDraw(System.Drawing.Graphics g)
 {
     g.DrawString("ジャンプアクション3 Jump Action3", mFont, mSBWhite, 15, 20);
     g.DrawString("PRESS ANY KEY", mFont, mSBWhite, 40, 40);
 }
Beispiel #36
0
        public override void DrawAppointment(System.Drawing.Graphics g, System.Drawing.Rectangle rect, Calendar.Appointment appointment, bool isSelected, System.Drawing.Rectangle gripRect)
        {
            if (appointment == null)
            {
                throw new ArgumentNullException("appointment");
            }

            if (g == null)
            {
                throw new ArgumentNullException("g");
            }

            /*
             * Logic for drawing the appointment:
             * 1) Do something messy with the colours
             *
             * 2) Determine background pattern
             * 2.1) App is locked -> HatchBrush
             * 2.2) Normal app -> Nothing
             *
             * 3) Draw the background of appointment
             *
             * 4) Draw the edges of appointment
             * 4.1) If app is selected -> just draw the selection rectangle
             * 4.2) If not -> draw the gripper, border (if required) and shadows
             */

            if (rect.Width != 0 && rect.Height != 0)
            {
                rect.Width--;

                using (StringFormat format = new StringFormat())
                {
                    format.Alignment     = StringAlignment.Near;
                    format.LineAlignment = StringAlignment.Near;

                    // Draw the background of the appointment
                    if (isSelected)
                    {
                        g.FillRectangle(System.Drawing.Brushes.White, rect);
                        ExplorerSelection.DrawBackground(g, rect);
                        ExplorerSelection.DrawBackground(g, rect);
                    }
                    else
                    {
                        using (SolidBrush brush = new SolidBrush(appointment.FillColor))
                            g.FillRectangle(brush, rect);
                    }

                    // Draw gripper bar
                    gripRect = rect;
                    gripRect.Inflate(-2, -2);
                    gripRect.Width = 5;
                    gripRect.Height--;

                    using (SolidBrush brush = new SolidBrush(appointment.BarColor))
                        g.FillRectangle(brush, gripRect);

                    // Draw gripper border
                    using (Pen m_Pen = new Pen(ColorUtil.DarkerDrawing(appointment.BarColor, 0.5f), 1))
                        g.DrawRectangle(m_Pen, gripRect);

                    //  Draw appointment border if needed
                    if (!isSelected && appointment.DrawBorder)
                    {
                        using (Pen pen = new Pen(appointment.BorderColor, 1))
                            g.DrawRectangle(pen, rect.Left, rect.Top, rect.Width - 1, rect.Height - 1);
                    }

                    // draw appointment text
                    rect.X = gripRect.Right /* + 2*/;
                    rect.Y++;

                    g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

                    Color textColor = (isSelected ? ColorUtil.DarkerDrawing(appointment.TextColor, 0.5f) : appointment.TextColor);

                    using (SolidBrush brush = new SolidBrush(textColor))
                        g.DrawString(appointment.Title, this.BaseFont, brush, rect, format);

                    g.TextRenderingHint = TextRenderingHint.SystemDefault;
                }
            }
        }
        internal void Draw(Box box)
        {
            System.Drawing.Graphics g = Graphics;

            if (box is Pack)
            {
                Pack pack = box as Pack;
                pack.Draw(this);
            }
            else
            {
                Vector3D[] points = box.Points;

                Face[] faces = box.Faces;
                for (int i = 0; i < 6; ++i)
                {
                    // Face
                    Face face = faces[i];
                    // face normal
                    Vector3D normal = face.Normal;
                    // visible ?
                    if (!faces[i].IsVisible(_vTarget - _vCameraPos))
                    {
                        continue;
                    }
                    // color
                    faces[i].ColorFill = box.Colors[i];
                    double cosA  = System.Math.Abs(Vector3D.DotProduct(faces[i].Normal, VLight));
                    Color  color = Color.FromArgb((int)(faces[i].ColorFill.R * cosA), (int)(faces[i].ColorFill.G * cosA), (int)(faces[i].ColorFill.B * cosA));
                    // points
                    Vector3D[] points3D = faces[i].Points;
                    Point[]    pt       = TransformPoint(GetCurrentTransformation(), points3D);
                    //  draw solid face
                    Brush brush = new SolidBrush(color);
                    g.FillPolygon(brush, pt);
                    // draw textures
                    if (null != face.Textures && ShowTextures)
                    {
                        foreach (Texture texture in face.Textures)
                        {
                            Point[] ptsImage = TransformPoint(GetCurrentTransformation(), box.PointsImage(i, texture));
                            Point[] pts      = new Point[3];
                            pts[0] = ptsImage[3];
                            pts[1] = ptsImage[2];
                            pts[2] = ptsImage[0];
                            g.DrawImage(texture.Bitmap, pts);
                        }
                    }
                    // draw path
                    Brush brushPath    = new SolidBrush(faces[i].ColorPath);
                    Pen   penPathThick = new Pen(brushPath, box.IsBundle ? 2.0f : 1.5f);
                    int   ptCount      = pt.Length;
                    for (int j = 1; j < ptCount; ++j)
                    {
                        g.DrawLine(penPathThick, pt[j - 1], pt[j]);
                    }
                    g.DrawLine(penPathThick, pt[ptCount - 1], pt[0]);
                    // draw bundle lines
                    if (box.IsBundle && i < 4)
                    {
                        Pen penPathThin = new Pen(brushPath, 1.5f);
                        int noSlice     = Math.Min(box.BundleFlats, 4);
                        for (int iSlice = 0; iSlice < noSlice - 1; ++iSlice)
                        {
                            Vector3D[] ptSlice = new Vector3D[2];
                            ptSlice[0] = points3D[0] + ((double)(iSlice + 1) / (double)noSlice) * (points3D[3] - points3D[0]);
                            ptSlice[1] = points3D[1] + ((double)(iSlice + 1) / (double)noSlice) * (points3D[2] - points3D[1]);

                            Point[] pt2D = TransformPoint(GetCurrentTransformation(), ptSlice);
                            g.DrawLine(penPathThin, pt2D[0], pt2D[1]);
                        }
                    }
                }

                // draw box tape
                if (box.ShowTape && faces[5].IsVisible(_vTarget - _vCameraPos))
                {
                    // get color
                    double cosA  = System.Math.Abs(Vector3D.DotProduct(faces[5].Normal, VLight));
                    Color  color = Color.FromArgb((int)(box.TapeColor.R * cosA), (int)(box.TapeColor.G * cosA), (int)(box.TapeColor.B * cosA));
                    // instantiate brush
                    Brush brushTape = new SolidBrush(color);
                    // get tape points
                    Point[] pts = TransformPoint(GetCurrentTransformation(), box.TapePoints);
                    // fill polygon
                    g.FillPolygon(brushTape, pts);
                    // draw path
                    Brush brushPath    = new SolidBrush(faces[5].ColorPath);
                    Pen   penPathThick = new Pen(brushPath, 1.5f);
                    int   ptCount      = pts.Length;
                    for (int j = 1; j < ptCount; ++j)
                    {
                        g.DrawLine(penPathThick, pts[j - 1], pts[j]);
                    }
                    g.DrawLine(penPathThick, pts[ptCount - 1], pts[0]);
                }
            }
            if (_showBoxIds)
            {
                // draw box id
                Point ptId = TransformPoint(GetCurrentTransformation(), box.TopFace.Center);
                g.DrawString(
                    box.PickId.ToString()
                    , new Font("Arial", 8.0f)
                    , Brushes.Black
                    , new Rectangle(ptId.X - 15, ptId.Y - 10, 30, 20)
                    , StringFormat.GenericDefault);
                g.DrawString(
                    _boxDrawingCounter.ToString()
                    , new Font("Arial", 8.0f)
                    , Brushes.Red
                    , new Rectangle(ptId.X + 5, ptId.Y - 10, 30, 20)
                    , StringFormat.GenericDefault);
            }
            ++_boxDrawingCounter;
        }
Beispiel #38
0
 protected void GameOverDraw(System.Drawing.Graphics g)
 {
     g.DrawString("GAME OVER", mFont, mSBWhite, 40, 40);
 }
Beispiel #39
0
        /// 〈summary>
        /// 在图片上增加文字水印
        /// 〈/summary>
        /// 〈param name="oldimage">原图片位置〈/param>
        /// 〈param name="Path_sy">生成的带文字水印的图片路径〈/param>
        protected static string MakeWaterTxt(string Oldimage, string NewPath, string NewName, WaterConfig mx)
        {
            try
            {
                NewPath = ServerPath + NewPath + "/";
                if (!File.Exists(NewPath))   //如果路径不存在,则创建
                {
                    System.IO.Directory.CreateDirectory(NewPath);
                }
                System.Drawing.Image    image = System.Drawing.Image.FromFile(Oldimage);
                System.Drawing.Graphics g     = System.Drawing.Graphics.FromImage(image);
                g.DrawImage(image, 0, 0, image.Width, image.Height);

                System.Drawing.FontStyle s = System.Drawing.FontStyle.Regular;
                switch (mx.WM_FontForm)
                {
                case "Bold":
                    s = System.Drawing.FontStyle.Bold;
                    break;

                case "Underline":
                    s = System.Drawing.FontStyle.Underline;
                    break;

                case "Italic":
                    s = System.Drawing.FontStyle.Italic;
                    break;

                case "Strikeout":
                    s = System.Drawing.FontStyle.Strikeout;
                    break;
                }
                System.Drawing.Font  f = new System.Drawing.Font(mx.WM_FontForm, Convert.ToInt32(mx.WM_FontSize), s);   //字体
                System.Drawing.Color c = System.Drawing.Color.FromName(mx.WM_FontColor);
                System.Drawing.Brush b = new System.Drawing.SolidBrush(c);

                if (mx.WM_Height == "0" || mx.WM_Width == "0")
                {
                    mx.WM_Height = "100";
                    mx.WM_Width  = "200";
                }
                Rectangle rf = new System.Drawing.Rectangle(image.Width - Convert.ToInt32(mx.WM_PlaceX), image.Height - Convert.ToInt32(mx.WM_PlaceY), Convert.ToInt32(mx.WM_Width), Convert.ToInt32(mx.WM_Height));
                switch (mx.WM_Location)
                {
                case "LeftTop":
                    rf = new System.Drawing.Rectangle(Convert.ToInt32(mx.WM_PlaceX), Convert.ToInt32(mx.WM_PlaceY), Convert.ToInt32(mx.WM_Width), Convert.ToInt32(mx.WM_Height));
                    break;

                case "LeftBottom":
                    rf = new System.Drawing.Rectangle(Convert.ToInt32(mx.WM_PlaceX), image.Height - Convert.ToInt32(mx.WM_PlaceY), Convert.ToInt32(mx.WM_Width), Convert.ToInt32(mx.WM_Height));
                    break;

                case "RightTop":
                    rf = new System.Drawing.Rectangle(image.Width - Convert.ToInt32(mx.WM_PlaceX), Convert.ToInt32(mx.WM_PlaceY), Convert.ToInt32(mx.WM_Width), Convert.ToInt32(mx.WM_Height));
                    break;
                    //case "RightBottom":
                    //    rf = new System.Drawing.Rectangle(image.Width - Convert.ToInt32(mx.WM_PlaceX), image.Height - Convert.ToInt32(mx.WM_PlaceY), Convert.ToInt32(mx.WM_Width), Convert.ToInt32(mx.WM_Height));
                    //    break;
                }
                g.DrawString(mx.WM_Text, f, b, rf);    //字体位置20X20
                //g.DrawString(mx.WM_Text, f, b, Convert.ToInt32(mx.WM_PlaceX), Convert.ToInt32(mx.WM_PlaceY));    //字体位置20X20
                g.Dispose();
                if (File.Exists(NewPath + NewName))//检查同名文件,如存在,删除
                {
                    File.Delete(NewPath + NewName);
                }
                image.Save(NewPath + NewName);
                image.Dispose();
                return("OK");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Beispiel #40
0
        /// <summary>
        /// 功能:返回验证码图片
        /// </summary>
        /// <returns></returns>
        public ActionResult ValidateImg()
        {
            Color color1 = new Color();
            //---------产生随机6位字符串
            Random ran = new Random();

            char[] c  = new char[62];
            char[] ou = new char[6];
            int    n  = 0;

            for (int i = 65; i < 91; i++)
            {
                c[n] = (char)i;
                n++;
            }
            for (int j = 97; j < 123; j++)
            {
                c[n] = (char)j;
                n++;
            }
            for (int k = 48; k < 58; k++)
            {
                c[n] = (char)k;
                n++;
            }
            foreach (char ch in c)
            {
                Console.WriteLine(ch);
            }
            string outcode = "";

            for (int h = 0; h < 6; h++)
            {
                ou[h]    = c[ran.Next(62)];
                outcode += ou[h].ToString();
            }
            //
            Session["ValidateImgCode"] = outcode;

            //1.创建一个新的图片,大小为(输入的字符串的长度*12),22
            System.Drawing.Bitmap bmap = new System.Drawing.Bitmap(outcode.Length * 18, 25);

            //2.定义画图面板,基于创建的新图片来创建
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmap);

            //3.由于默认的画图面板背景是黑色,所有使用clear方法把背景清除,同时把背景颜色设置为白色
            g.Clear(System.Drawing.Color.White);

            // 画图片的背景噪音线
            for (int i = 0; i < 25; i++)
            {
                int x1 = ran.Next(bmap.Width);
                int x2 = ran.Next(bmap.Width);
                int y1 = ran.Next(bmap.Height);
                int y2 = ran.Next(bmap.Height);
                g.DrawLine(new Pen(color1), x1, y1, x2, y2);
            }

            // 画图片的前景噪音线
            for (int i = 0; i < 100; i++)
            {
                int x = ran.Next(bmap.Width);
                int y = ran.Next(bmap.Height);
                bmap.SetPixel(x, y, Color.FromArgb(ran.Next()));
            }

            //4.使用DrawString 方法把要输出的字符串输出到画板上。输出的字符从参数(outcode)内获得。
            Font font = new Font("Arial", 14, FontStyle.Bold | FontStyle.Italic);
            LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, bmap.Width, bmap.Height), Color.Blue, Color.DarkRed, 1.2f, true);

            g.DrawString(outcode, font, brush, 0, 0);

            //5.定义一个内存流,把新创建的图片保存到内存流内,这样就不用保存到磁盘上,提高了速度。
            System.IO.MemoryStream ms = new System.IO.MemoryStream();

            //6.把新创建的图片保存到内存流中,格式为jpeg的类型
            bmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);

            //7.输出这张图片,由于此页面的 ContentType="image/jpeg" 所以会输出图片到客户端。同时输出是以字节输出,所以要把内存流转换为字节序列,使用ToArray()方法。
            Response.BinaryWrite(ms.ToArray());
            return(View());
        }
Beispiel #41
0
        //used to fire an event to retrieve formatting info
        //and then draw the cell with this formatting info
        protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight)
        {
            DataGridFormatCellEventArgs e = null;

            bool callBaseClass = true;

            //fire the formatting event
            if (SetCellFormat != null)
            {
                int col = this.DataGridTableStyle.GridColumnStyles.IndexOf(this);
                e = new DataGridFormatCellEventArgs(rowNum, col, this.GetColumnValueAtRow(source, rowNum));
                SetCellFormat(this, e);

                if (e.BackBrush != null)
                {
                    backBrush = e.BackBrush;
                }

                //if these properties set, then must call drawstring
                if (e.ForeBrush != null || e.TextFont != null)
                {
                    if (e.ForeBrush == null)
                    {
                        e.ForeBrush = foreBrush;
                    }
                    if (e.TextFont == null)
                    {
                        e.TextFont = this.DataGridTableStyle.DataGrid.Font;
                    }
                    g.FillRectangle(backBrush, bounds);
                    Region    saveRegion = g.Clip;
                    Rectangle rect       = new Rectangle(bounds.X, bounds.Y, bounds.Width, bounds.Height);
                    using (Region newRegion = new Region(rect))
                    {
                        g.Clip = newRegion;
                        int charWidth = (int)Math.Ceiling(g.MeasureString("c", e.TextFont, 20, StringFormat.GenericTypographic).Width);

                        string s        = this.GetColumnValueAtRow(source, rowNum).ToString();
                        int    maxChars = Math.Min(s.Length, (bounds.Width / charWidth));

                        try
                        {
                            g.DrawString(s.Substring(0, maxChars), e.TextFont, e.ForeBrush, bounds.X, bounds.Y + 2);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message.ToString());
                        }                         //empty catch
                        finally
                        {
                            g.Clip = saveRegion;
                        }
                    }
                    callBaseClass = false;
                }

                if (!e.UseBaseClassDrawing)
                {
                    callBaseClass = false;
                }
            }
            if (callBaseClass)
            {
                base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight);
            }

            //clean up
            if (e != null)
            {
                if (e.BackBrushDispose)
                {
                    e.BackBrush.Dispose();
                }
                if (e.ForeBrushDispose)
                {
                    e.ForeBrush.Dispose();
                }
                if (e.TextFontDispose)
                {
                    e.TextFont.Dispose();
                }
            }
        }
Beispiel #42
0
        internal static pTexture CreateText(string text, float size, Vector2 restrictBounds, Color color, ShadowType shadow, bool bold, bool italic, bool underline, TextAlignment alignment, bool forceAa, out Vector2 measured, out RectangleF[] characterRegions, Color background, Color border, int borderWidth, bool measureOnly, bool getCharacterRegions, FontFace fontFace, Vector4 cornerBounds, Vector2 padding, pTexture lastTexture = null, int startIndex = 0, int length = -1)
        {
            characterRegions = null;
            if (text == null)
            {
                measured = Vector2.Zero;
                return(null);
            }

            if (ConfigManager.dDisableTextRendering)
            {
                measured = new Vector2(text.Length * size, size);
                return(null);
            }

#if DEBUG
            if (!text.Contains(@"NativeText"))
            {
                int  limit_per_second = osu.GameModes.Play.Player.Playing ? 5 : 58;
                bool newSecond        = GameBase.Time / 1000 != currentSecond;

                drawCount++;
                if (drawCount == limit_per_second)
                {
                    Debug.Print(@"NativeText: High number of text refreshes per second.");
                }

                if (newSecond)
                {
                    currentSecond = GameBase.Time / 1000;
                    drawCount     = 0;
                }
            }
#endif

            //This lock ensures we are only using the shared GDI+ object (FromHwnd) in one place at a time.
            lock (createTextLock)
            {
                try
                {
                    using (System.Drawing.Graphics graphics = System.Drawing.Graphics.FromHwnd(IntPtr.Zero))
                        using (StringFormat sf = new StringFormat())
                        {
                            if (dpiRatio == 0)
                            {
                                dpiRatio = 96 / graphics.DpiX;
                            }

                            size *= dpiRatio;

                            GameBase.PerformanceMonitor.ReportCount(CounterType.NativeText);

                            graphics.TextRenderingHint = TextRenderingHint.AntiAlias;

                            SizeF measuredSize;

                            string face = GetFontFace(fontFace);

                            if (face.StartsWith(@"Aller"))
                            {
                                //if we are using the default osu! font, allow specific language overrides based on simple detection.
                                string fontFaceOverride = getLanguageSpeicificFont(text);
                                if (fontFaceOverride != null)
                                {
                                    face = fontFaceOverride;
                                }
                            }

                            if (startIndex != 0 || length > 0)
                            {
                                text = text.Substring(startIndex, length);
                            }
                            else if (length == -1)
                            {
                                length = text.Length;
                            }


                            if (size < 20 && face.EndsWith(@" Light"))
                            {
                                face = face.Replace(@" Light", string.Empty);
                            }

                            FontStyle fs = FontStyle.Regular;
                            if (bold)
                            {
                                if (face.EndsWith(@" Light"))
                                {
                                    face = face.Replace(@" Light", string.Empty);
                                }
                                fs |= FontStyle.Bold;
                            }

                            if (italic)
                            {
                                fs |= FontStyle.Italic;
                            }

                            if (underline)
                            {
                                fs |= FontStyle.Underline;
                            }

                            switch (alignment)
                            {
                            case TextAlignment.Left:
                            case TextAlignment.LeftFixed:
                                sf.Alignment = StringAlignment.Near;
                                break;

                            case TextAlignment.Centre:
                                sf.Alignment = StringAlignment.Center;
                                break;

                            case TextAlignment.Right:
                                sf.Alignment = StringAlignment.Far;
                                break;
                            }

                            if (!OsuMain.IsWine && face.StartsWith(@"Aller"))
                            {
                                for (char c = '0'; c <= '9'; c++)
                                {
                                    text = text.Replace(c, (char)(c + (0xf83c - '0')));
                                }
                            }

                            Font f = GetFont(face, size * ScaleModifier, fs);
                            if (ScaleModifier != 1)
                            {
                                restrictBounds *= ScaleModifier;
                            }

                            try
                            {
                                if (text.Length == 0)
                                {
                                    text = " ";
                                }
                                measuredSize = restrictBounds != Vector2.Zero
                                                ? graphics.MeasureString(text, f, new SizeF(restrictBounds.X, restrictBounds.Y), sf)
                                                : graphics.MeasureString(text, f);
                            }
                            catch (InvalidOperationException)
                            {
                                measured = Vector2.Zero;
                                return(null);
                            }

                            int width  = (int)(measuredSize.Width + 1);
                            int height = (int)(measuredSize.Height + 1);

                            if (restrictBounds.Y != 0)
                            {
                                height = (int)restrictBounds.Y;
                            }

                            if (restrictBounds.X != 0 && (alignment != TextAlignment.Left || background.A > 0))
                            {
                                width = (int)restrictBounds.X;
                            }

                            if (padding != Vector2.Zero && restrictBounds == Vector2.Zero)
                            {
                                width  += (int)(padding.X * 2);
                                height += (int)(padding.Y * 2);
                            }

                            measured = new Vector2(width, height);
                            float offset = Math.Max(0.5f, Math.Min(1f, (size * ScaleModifier) / 14));

                            if (getCharacterRegions)
                            {
                                characterRegions = new RectangleF[text.Length];

                                // SetMeasurableCharacterRanges only accepts a maximum of 32 intervals to be queried, so we as the library user are
                                // forced to split the string into 32 character long chunks and perform MeasureCharacterRanges on each.
                                int numIntervals = (text.Length / 32) + 1;
                                for (int i = 0; i < numIntervals; ++i)
                                {
                                    int offsetIndex = i * 32;
                                    int end         = Math.Min(text.Length - offsetIndex, 32);

                                    CharacterRange[] characterRanges = new CharacterRange[end];
                                    for (int j = 0; j < end; ++j)
                                    {
                                        characterRanges[j] = new CharacterRange(j + offsetIndex, 1);
                                    }

                                    sf.SetMeasurableCharacterRanges(characterRanges);
                                    Region[] regions = graphics.MeasureCharacterRanges(
                                        text,
                                        f,
                                        new RectangleF(
                                            padding.X,
                                            padding.Y,
                                            restrictBounds.X == 0 ? Single.PositiveInfinity : restrictBounds.X,
                                            restrictBounds.Y == 0 ? Single.PositiveInfinity : restrictBounds.Y),
                                        sf);

                                    for (int j = 0; j < end; ++j)
                                    {
                                        Region region = regions[j] as Region;
                                        characterRegions[j + offsetIndex] = region.GetBounds(graphics);
                                    }
                                }
                            }

                            if (measureOnly)
                            {
                                int startSpace = 0;
                                int endSpace   = 0;

                                int i = 0;
                                while (i < text.Length && text[i++] == ' ')
                                {
                                    startSpace++;
                                }
                                int j = text.Length - 1;
                                while (j >= i && text[j--] == ' ')
                                {
                                    endSpace++;
                                }
                                if (startSpace == text.Length)
                                {
                                    endSpace += startSpace;
                                }

                                measured = new Vector2(width + (endSpace * 5.145f * size / 12), height);
                                return(null);
                            }

                            using (Bitmap b = new Bitmap(width, height, PixelFormat.Format32bppArgb))
                                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(b))
                                {
                                    //Quality settings
                                    g.TextRenderingHint = graphics.TextRenderingHint;
                                    g.SmoothingMode     = SmoothingMode.HighQuality;
                                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;

                                    if (background.A > 0)
                                    {
                                        if (cornerBounds != Vector4.Zero)
                                        {
                                            fillRoundedRectangle(g, new Rectangle(0, 0, width, height), new SolidBrush(OsuMathHelper.CConvert(background)), cornerBounds);

                                            if (borderWidth > 0)
                                            {
                                                drawRoundedRectangle(g,
                                                                     new Rectangle(0, 0, width - (int)Math.Ceiling(borderWidth / 2f), height - (int)Math.Ceiling(borderWidth / 2f)),
                                                                     new Pen(OsuMathHelper.CConvert(border), borderWidth),
                                                                     cornerBounds);
                                            }
                                        }
                                        else
                                        {
                                            g.Clear(OsuMathHelper.CConvert(background));
                                            if (borderWidth > 0)
                                            {
                                                g.DrawRectangle(new Pen(OsuMathHelper.CConvert(border), borderWidth),
                                                                new Rectangle(borderWidth / 2, borderWidth / 2, width - borderWidth, height - borderWidth));
                                            }
                                        }
                                    }
                                    else
                                    {
                                        g.Clear(System.Drawing.Color.FromArgb(1, color.R, color.G, color.B));
                                    }


                                    using (Brush brush = new SolidBrush(OsuMathHelper.CConvert(color)))
                                    {
                                        if (restrictBounds != Vector2.Zero)
                                        {
                                            restrictBounds.X -= padding.X * 2;
                                            restrictBounds.Y -= padding.Y * 2;

                                            switch (shadow)
                                            {
                                            case ShadowType.Normal:
                                                g.DrawString(text, f, shadowBrush, new RectangleF(padding.X - offset, offset + padding.Y, restrictBounds.X, restrictBounds.Y), sf);
                                                g.DrawString(text, f, shadowBrush, new RectangleF(padding.X + offset, offset + padding.Y, restrictBounds.X, restrictBounds.Y), sf);
                                                break;

                                            case ShadowType.Border:
                                                Brush borderBrush = greyBrush;
                                                if (background.A == 0 && borderWidth == 1 && border.A > 0)
                                                {
                                                    borderBrush = new SolidBrush(OsuMathHelper.CConvert(border));
                                                }

                                                g.DrawString(text, f, borderBrush, new RectangleF(padding.X + offset, padding.Y + offset, restrictBounds.X, restrictBounds.Y), sf);
                                                g.DrawString(text, f, borderBrush, new RectangleF(padding.X + offset, padding.Y - offset, restrictBounds.X, restrictBounds.Y), sf);
                                                g.DrawString(text, f, borderBrush, new RectangleF(padding.X - offset, padding.Y + offset, restrictBounds.X, restrictBounds.Y), sf);
                                                g.DrawString(text, f, borderBrush, new RectangleF(padding.X - offset, padding.Y - offset, restrictBounds.X, restrictBounds.Y), sf);
                                                break;
                                            }

                                            g.DrawString(text, f, brush, new RectangleF(padding.X, padding.Y, restrictBounds.X, restrictBounds.Y), sf);
                                        }
                                        else
                                        {
                                            switch (shadow)
                                            {
                                            case ShadowType.Normal:
                                                g.DrawString(text, f, shadowBrush, padding.X - offset, padding.Y + offset);
                                                g.DrawString(text, f, shadowBrush, padding.X + offset, padding.Y + offset);
                                                break;

                                            case ShadowType.Border:
                                                Brush borderBrush = greyBrush;
                                                if (background.A == 0 && borderWidth == 1 && border.A > 0)
                                                {
                                                    borderBrush = new SolidBrush(OsuMathHelper.CConvert(border));
                                                }

                                                g.DrawString(text, f, borderBrush, padding.X + offset, padding.Y + offset);
                                                g.DrawString(text, f, borderBrush, padding.X - offset, padding.Y + offset);
                                                g.DrawString(text, f, borderBrush, padding.X + offset, padding.Y - offset);
                                                g.DrawString(text, f, borderBrush, padding.X - offset, padding.Y - offset);
                                                break;
                                            }

                                            g.DrawString(text, f, brush, padding.X, padding.Y);
                                        }
                                    }

                                    //if (lastTexture == null || lastTexture.isDisposed)
                                    {
                                        lastTexture            = pTexture.FromBitmap(b);
                                        lastTexture.Disposable = true;
                                    }

                                    /*else
                                     * {
                                     *  lastTexture.Width = b.Width;
                                     *  lastTexture.Height = b.Height;
                                     *  lastTexture.SetData(b);
                                     * }*/

                                    return(lastTexture);
                                }
                        }
                }
                catch (Exception e)
                {
                    measured = Vector2.Zero;
                    return(null);
                }
            }
        }
    //图片上传
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        ClearMethod();
        HttpPostedFile hpf = uploadImage.PostedFile;

        //取得文件名,不含路径
        char[]   splitChar     = { '\\' };
        string[] FilenameArray = hpf.FileName.Split(splitChar);
        string   Filename      = FilenameArray[FilenameArray.Length - 1].ToLower();

        //将用户输入的水印文字处理
        //string sMessage = lineStr(TextBox3.Text.Trim().ToString(), 20);

        if (hpf.FileName.Length < 1)
        {
            panelAttention.Visible = true;
            lbAttention.Text       = "请选择你要上传的图片文件";
            return;
        }
        if (hpf.ContentType != "image/jpeg" && hpf.ContentType != "image/gif")
        {
            panelAttention.Visible = true;
            lbAttention.Text       = "只允许上传JPEG GIF文件";
            return;
        }
        else
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append(DateTime.Now.Year.ToString());
            sb.Append(DateTime.Now.Month.ToString());
            sb.Append(DateTime.Now.Day.ToString());
            sb.Append(DateTime.Now.Hour.ToString());
            sb.Append(DateTime.Now.Minute.ToString());
            sb.Append(DateTime.Now.Second.ToString());

            if (Filename.ToLower().EndsWith("gif"))
            {
                sb.Append(".gif");
            }
            else if (Filename.ToLower().EndsWith("jpg"))
            {
                sb.Append(".jpg");
            }
            else if (Filename.ToLower().EndsWith("jpeg"))
            {
                sb.Append(".jpeg");
            }
            Filename = sb.ToString();

            //保存图片到服务器上
            try
            {
                hpf.SaveAs(Server.MapPath("~") + "/images/onsale/wear/big_" + Filename);
            }
            catch (Exception ee)
            {
                panelAttention.Visible = true;
                lbAttention.Text       = "上传图片失败,原因:" + ee.Message;
                return;
            }

            //生成缩略图
            //原始图片名称
            string originalFilename = hpf.FileName;
            //生成高质量图片名称
            string strFile = Server.MapPath("~") + "/images/onsale/wear/small/small_" + Filename;

            //从文件获取图片对象
            System.Drawing.Image image = System.Drawing.Image.FromStream(hpf.InputStream, true);

            Double        Width = Double.Parse(TextBox1.Text.Trim());
            Double        Height = Double.Parse(TextBox2.Text.Trim());
            System.Double newWidth, newHeight;
            if (image.Width > image.Height)
            {
                newWidth  = Width;
                newHeight = image.Height * (newWidth / image.Width);
            }
            else
            {
                newHeight = Height;
                newWidth  = image.Width * (newHeight / image.Height);
            }
            if (newWidth > Width)
            {
                newWidth = Width;
            }
            if (newHeight > Height)
            {
                newHeight = Height;
            }
            System.Drawing.Size     size   = new System.Drawing.Size((int)newWidth, (int)newHeight); //设置图片的宽度和高度
            System.Drawing.Image    bitmap = new System.Drawing.Bitmap(size.Width, size.Height);     //新建bmp图片
            System.Drawing.Graphics g      = System.Drawing.Graphics.FromImage(bitmap);              //新建画板
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;                   //制定高质量插值法
            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;                //设置高质量、低速度呈现平滑程度
            g.Clear(System.Drawing.Color.White);                                                     //清空画布
            //在制定位置画图
            g.DrawImage(image, new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), new System.Drawing.Rectangle(0, 0, image.Width, image.Height), System.Drawing.GraphicsUnit.Pixel);


            //文字水印
            System.Drawing.Graphics testGrahpics = System.Drawing.Graphics.FromImage(bitmap);
            System.Drawing.Font     font         = new System.Drawing.Font("宋体", 10);
            System.Drawing.Brush    brush        = new System.Drawing.SolidBrush(System.Drawing.Color.Black);

            //分行
            string sInput = TextBox3.Text.Trim().ToString(); //获取输入的水印文字
            int    coloum = Convert.ToInt32(TextBox4.Text);  //获取每行的字符数
            //利用循环,来依次输出
            for (int i = 0, j = 0; i < sInput.Length; i += coloum, j++)
            {
                //若要修改水印文字在照片上的位置,可将20修改成你想要的任何值
                if (j != sInput.Length / coloum)
                {
                    string s = sInput.Substring(i, coloum);
                    testGrahpics.DrawString(s, font, brush, 20, 20 * (i / coloum + 1));
                }
                else
                {
                    string s = sInput.Substring(i, sInput.Length % coloum);
                    testGrahpics.DrawString(s, font, brush, 20, 20 * (j + 1));
                }
            }
            testGrahpics.Dispose();
            //保存缩略图c
            try
            {
                bitmap.Save(strFile, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            catch (Exception ex)
            {
                paneInfo.Visible = true;
                lbInfo.Text      = "保存缩略图失败" + ex.Message;
            }
            //释放资源
            g.Dispose();
            bitmap.Dispose();
            image.Dispose();
        }

        Entity.PicturesItem pic = new Entity.PicturesItem();
        pic.setItemID(int.Parse(lbItemId.Text));
        // pic.setIntImageID(int.Parse(lbImageID.Text));
        pic.setBigImg("images/onsale/wear/big_" + Filename);
        pic.setSmallImg("images/onsale/wear/small/small_" + Filename);
        pic.setAlt("");

        switch (btnSubmit.Text)
        {
        case "新增":    //新增模式
            if (picture.InserItemsPic(pic))
            {
                panelSuccess.Visible = true;
                lbSuccess.Text       = "新增图片成功!";
            }
            else
            {
                panelError.Visible = true;
                lbError.Text       = "新增图片失败!";
            }
            break;

        case "修改":    //修改模式
            //int.Parse(lbImageID.Text), int.Parse(lbItemId.Text), "images/onsale/wear/big_" + Filename, "images/onsale/wear/small/small_" + Filename, ""
            if (picture.UpdatePicByID(pic))
            {
                panelSuccess.Visible = true;
                lbSuccess.Text       = "修改图片成功!";
            }
            else
            {
                panelError.Visible = true;
                lbError.Text       = "修改图片失败!";
            }
            break;
        }
    }
Beispiel #44
0
        /// <summary>This method will paint the group title.</summary>
        /// <param name="g">The paint event graphics object.</param>
        private void PaintGroupText(System.Drawing.Graphics g)
        {
            //Check if string has something-------------
            if (this.GroupTitle == string.Empty)
            {
                return;
            }
            //------------------------------------------

            //Set Graphics smoothing mode to Anit-Alias--
            g.SmoothingMode = SmoothingMode.AntiAlias;
            //-------------------------------------------

            //Declare Variables------------------
            SizeF stringSize  = g.MeasureString(this.GroupTitle, this.Font);
            Size  stringSize2 = stringSize.ToSize();


            if (this.GroupImage != null)
            {
                stringSize2.Width += 18;
            }
            //int ArcWidth = this.RoundCorners;
            //int ArcHeight = this.RoundCorners;
            int arcWidth  = this.HeaderRoundCorners;
            int arcHeight = this.HeaderRoundCorners;
            //int intX1 = 0;
            //int intX2 = 0;

            //int ArcX1 = 10;
            //int ArcX2 = (StringSize2.Width + 34) - (ArcWidth + 1);
            int ArcX1 = 20;
            int ArcX2 = (stringSize2.Width + 34) - (arcWidth + 1);
            int ArcY1 = 2;
            int ArcY2 = 22 - (arcHeight + 1);

            //Add by WZW 2008-12-16 增加GroupTitleBox对齐方式 ===Start
            int intMidX           = this.Size.Width / 2;
            int intMidX1          = (ArcX2 - ArcX1) / 2;
            int CustomStringWidth = (this.GroupImage != null) ? 44 : 28;

            _vXTrans = intMidX - intMidX1 - ArcX1;//X坐标平移距离
            int intTitleTextSpace = CustomStringWidth - ArcX1;

            //中间对齐
            if (this._vGroupBoxAlignMode == GroupBoxAlignMode.Center)
            {
                ArcX1             = intMidX - intMidX1;
                ArcX2             = intMidX + intMidX1;
                CustomStringWidth = ArcX1 + intTitleTextSpace;
            }
            else if (this._vGroupBoxAlignMode == GroupBoxAlignMode.Right)
            {
                ArcX1             = intMidX + intMidX - ArcX2;
                ArcX2             = ArcX1 + intMidX1 + intMidX1;
                CustomStringWidth = ArcX1 + intTitleTextSpace;
            }
            //标题与左边线距离
            ArcX1 -= this.TitleLeftSpace;
            ArcX2 -= this.TitleLeftSpace;

            //Add by WZW 2008-12-16 增加GroupTitleBox对齐方式 ===End
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            System.Drawing.Brush BorderBrush           = new SolidBrush(this.BorderColor);
            System.Drawing.Pen   BorderPen             = new Pen(BorderBrush, this.BorderThickness);
            System.Drawing.Drawing2D.LinearGradientBrush BackgroundGradientBrush = null;
            System.Drawing.Brush                  BackgroundBrush = (this.PaintGroupBox) ? new SolidBrush(this.CustomGroupBoxColor) : new SolidBrush(this.BackgroundColor);
            System.Drawing.SolidBrush             TextColorBrush  = new SolidBrush(this.ForeColor);
            System.Drawing.SolidBrush             ShadowBrush     = null;
            System.Drawing.Drawing2D.GraphicsPath ShadowPath      = null;
            //-----------------------------------

            //Check if shadow is needed----------
            if (this.ShadowControl)
            {
                ShadowBrush = new SolidBrush(this.ShadowColor);
                ShadowPath  = new System.Drawing.Drawing2D.GraphicsPath();
                ShadowPath.AddArc(ArcX1 + (this.ShadowThickness - 1), ArcY1 + (this.ShadowThickness - 1), arcWidth, arcHeight, 180, GroupBoxConstants.SweepAngle); // Top Left
                ShadowPath.AddArc(ArcX2 + (this.ShadowThickness - 1), ArcY1 + (this.ShadowThickness - 1), arcWidth, arcHeight, 270, GroupBoxConstants.SweepAngle); //Top Right
                ShadowPath.AddArc(ArcX2 + (this.ShadowThickness - 1), ArcY2 + (this.ShadowThickness - 1), arcWidth, arcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right
                ShadowPath.AddArc(ArcX1 + (this.ShadowThickness - 1), ArcY2 + (this.ShadowThickness - 1), arcWidth, arcHeight, 90, GroupBoxConstants.SweepAngle);  //Bottom Left
                ShadowPath.CloseAllFigures();

                //Paint Rounded Rectangle------------
                g.FillPath(new SolidBrush(Color.Transparent), ShadowPath);
                //g.FillPath(ShadowBrush, ShadowPath);
                //-----------------------------------
            }
            //-----------------------------------
            //Edit BY WZW 2008-12-16
            //是否显示标题边框------
            if (this._vShowTileRectangle)
            {
                //创建title边框路径
                path.AddArc(ArcX1, ArcY1, arcWidth, arcHeight, 180, GroupBoxConstants.SweepAngle); // Top Left
                path.AddArc(ArcX2, ArcY1, arcWidth, arcHeight, 270, GroupBoxConstants.SweepAngle); //Top Right
                path.AddArc(ArcX2, ArcY2, arcWidth, arcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right
                path.AddArc(ArcX1, ArcY2, arcWidth, arcHeight, 90, GroupBoxConstants.SweepAngle);  //Bottom Left
                path.CloseAllFigures();
                //画Title边框
                g.DrawPath(BorderPen, path);
            }

            //-----------------------------------

            //Check if Gradient Mode is enabled--
            if (this.PaintGroupBox)
            {
                //Paint Rounded Rectangle------------
                g.FillPath(BackgroundBrush, path);
                //-----------------------------------
            }
            else
            {
                if (this.BackgroundGradientMode == GroupBoxGradientMode.None)
                {
                    //Paint Rounded Rectangle------------
                    g.FillPath(BackgroundBrush, path);
                    //-----------------------------------
                }
                else
                {
                    BackgroundGradientBrush = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), this.BackgroundColor, this.BackgroundGradientColor, (LinearGradientMode)this.BackgroundGradientMode);

                    //Paint Rounded Rectangle------------
                    g.FillPath(BackgroundGradientBrush, path);
                    //-----------------------------------
                }
            }
            //-----------------------------------

            //绘制title文字-------------------------
            //int CustomStringWidth = (this.GroupImage != null) ? 44 : 28;
            //if(this.GroupImage!=null)
            //{
            //    CustomStringWidth += 2;
            //}

            //g.DrawString(this.GroupTitle, this.Font, TextColorBrush, CustomStringWidth, 5);

            // g.DrawString(this.GroupTitle, this.Font, TextColorBrush, CustomStringWidth-this.TitleLeftSpace-2, 5);
            g.DrawString(this.GroupTitle, this.Font, TextColorBrush, CustomStringWidth - this.TitleLeftSpace, 5);
            //-----------------------------------

            //Draw GroupImage if there is one----
            if (this.GroupImage != null)
            {
                //因增加了标题对齐功能,需修改X坐标值 By  WZW 2008-12-17
                g.DrawImage(this.GroupImage, ArcX1 + 5, 4, 16, 16);
            }

            //释放资源------------
            if (path != null)
            {
                path.Dispose();
            }
            if (BorderBrush != null)
            {
                BorderBrush.Dispose();
            }
            if (BorderPen != null)
            {
                BorderPen.Dispose();
            }
            if (BackgroundGradientBrush != null)
            {
                BackgroundGradientBrush.Dispose();
            }
            if (BackgroundBrush != null)
            {
                BackgroundBrush.Dispose();
            }
            if (TextColorBrush != null)
            {
                TextColorBrush.Dispose();
            }
            if (ShadowBrush != null)
            {
                ShadowBrush.Dispose();
            }
            if (ShadowPath != null)
            {
                ShadowPath.Dispose();
            }
        }
Beispiel #45
0
 public void drawString()
 {
     graphicsObj2.DrawString("Game over, press ENTER to play again", new Font("Arial", 22), myBrush, new Point(10, WINHEIGHT / 2));
 }
Beispiel #46
0
    public ArrayList batUpload()
    {
        //string shopName = "";
        //string strSQL = "select shopName from T_Shop_User where shopid=(select ProviderInfo from T_Goods_info where goodsid='" + goodsId + "' and Datafrom='ShopSeller');select memberName from T_member_info where memberId=(select ProviderInfo from T_Goods_info where goodsid='" + goodsId + "' and Datafrom='PersonSeller');";

        //DataSet ds = adohelper.ExecuteSqlDataset(strSQL);
        //if (ds == null || ds.Tables.Count < 2)
        //    return null;

        //if (ds.Tables[0].Rows.Count > 0)
        //    shopName = ds.Tables[0].Rows[0][0].ToString();
        //else
        //    shopName = ds.Tables[1].Rows[0][0].ToString();

        ArrayList list      = new ArrayList();
        AdoHelper adohelper = AdoHelper.CreateHelper(StarTech.Util.AppConfig.DBInstance);
        //搜集表单中的file元素
        HttpFileCollection files = Request.Files;

        //遍历file元素
        for (int i = 0; i < files.Count; i++)
        {
            HttpPostedFile       postedFile = files[i];
            HtmlInputCheckBox [] ck         = { Checkbox1, Checkbox2, Checkbox3, Checkbox4 };
            if (postedFile.FileName != "")
            {
                //文件大小
                int fileSize = postedFile.ContentLength / 1024;
                if (fileSize == 0)
                {
                    fileSize = 1;
                }

                //提取文件名
                string oldFileName = Path.GetFileName(postedFile.FileName);

                //提取文件扩展名
                string oldFileExt = Path.GetExtension(oldFileName);

                //重命名文件
                string newFileName = Guid.NewGuid().ToString() + oldFileExt;

                //设置保存目录
                string webDirectory  = "/upload/goodsadmin/" + DateTime.Now.ToString("yyyyMMdd") + "/";
                string saveDirectory = Server.MapPath(webDirectory);
                if (!Directory.Exists(saveDirectory))
                {
                    Directory.CreateDirectory(saveDirectory);
                }

                //设置保存路径
                string savePath = saveDirectory + newFileName;
                //保存
                postedFile.SaveAs(savePath);

                string savePath2    = savePath;
                string newFileName2 = newFileName;
                if (ck[i].Checked)
                {
                    //System.Drawing.Image nowImg = System.Drawing.Image.FromFile(savePath);
                    System.Drawing.Bitmap nowImg2 = new System.Drawing.Bitmap(savePath);
                    System.Drawing.Bitmap nowImg  = new System.Drawing.Bitmap(nowImg2.Width, nowImg2.Height);

                    float x = nowImg.Width - 50;
                    float y = nowImg.Height - 30;

                    System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(nowImg);
                    g.DrawImage(nowImg2, 0, 0);
                    System.Drawing.Font  f = new System.Drawing.Font("华文彩云", 12);
                    System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
                    g.DrawString("才通天下微信公号", f, b, x, y);
                    f = new System.Drawing.Font("华文琥珀", 12);
                    b = new System.Drawing.SolidBrush(System.Drawing.Color.White);
                    g.DrawString("才通天下微信公号·", f, b, x, y);
                    f.Dispose();
                    b.Dispose();
                    g.Dispose();
                    nowImg2.Dispose();
                    //savePath2 = webDirectory + newFileName.Replace(oldFileExt, "" + oldFileExt);
                    string nGuid = Guid.NewGuid().ToString();
                    nGuid        = nGuid.Replace(nGuid[new Random().Next(1, 9)], nGuid[new Random().Next(10, 15)]);
                    newFileName2 = nGuid + oldFileExt;
                    savePath2    = webDirectory + newFileName2;
                    MemoryStream ms = new MemoryStream();
                    nowImg.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                    byte[] imgData = ms.ToArray();
                    File.Delete(savePath);
                    FileStream fs = new FileStream(savePath, FileMode.Create, FileAccess.ReadWrite);
                    if (fs != null)
                    {
                        fs.Write(imgData, 0, imgData.Length);
                        fs.Close();
                    }
                    nowImg.Dispose();
                }



                //缩略图
                MakeSmallPic(Server.MapPath(webDirectory + newFileName), Server.MapPath(webDirectory + newFileName.Replace(oldFileExt, ".jpg")));
                string goodsSmallPic = webDirectory + newFileName.Replace(oldFileExt, "" + oldFileExt);

                list.Add(oldFileName + "|" + fileSize + "|" + goodsSmallPic);
            }
        }
        return(list);
    }
Beispiel #47
0
        private void DrawScreen(System.Drawing.Graphics gfx)
        {
            PolynomialDegreeLabel.Visible = Menu_Project1.Checked;
            PolynomialDegreeValue.Visible = Menu_Project1.Checked;


            // to prevent unecessary drawing
            if (pts_.Count == 0)
            {
                return;
            }

            // pens used for drawing elements of the display
            System.Drawing.Pen polyPen   = new Pen(Color.Gray, 1.0f);
            System.Drawing.Pen shellPen  = new Pen(Color.Blue, 0.5f);
            System.Drawing.Pen splinePen = new Pen(Color.Red, 1.5f);

            if (Menu_Shell.Checked)
            {
                // draw the shell
                DrawShell(gfx, shellPen, pts_, tVal_);
            }

            if (Menu_Polyline.Checked)
            {
                // draw the control poly
                for (int i = 1; i < pts_.Count; ++i)
                {
                    gfx.DrawLine(polyPen, pts_[i - 1].P(), pts_[i].P());
                }
            }

            if (Menu_Points.Checked)
            {
                // draw the control points
                foreach (Point2D pt in pts_)
                {
                    gfx.DrawEllipse(polyPen, pt.x - 2.0F, pt.y - 2.0F, 4.0F, 4.0F);
                }
            }

            // you can change these variables at will; i have just chosen there
            //  to be six sample points for every point placed on the screen
            float steps = pts_.Count * 6;
            float alpha = 1 / steps;

            ///////////////////////////////////////////////////////////////////////////////
            // Drawing code for algorithms goes in here                                  //
            ///////////////////////////////////////////////////////////////////////////////

            //Project # checked
            if (Menu_Project1.Checked)
            {
                //Tweak these
                //Start with degree # of points
                //Initial degree:  1
                //Initial coef vals (have d+1 coef):  all 1's
                //Drag points up and down--coef corresponds to y val, do NOT change x val
                //Curve should move along with the coef. on its own given the stuff below
                //Up degree, change coef. / Bernstein poly all over again


                // DeCastlejau algorithm
                if (Menu_DeCast.Checked)
                {
                    Point2D current_left;
                    Point2D current_right = new Point2D(DeCastlejau(0));

                    for (float t = alpha; t < 1; t += alpha)
                    {
                        current_left  = current_right;
                        current_right = DeCastlejau(t);
                        gfx.DrawLine(splinePen, current_left.P(), current_right.P());
                    }

                    gfx.DrawLine(splinePen, current_right.P(), DeCastlejau(1).P());
                }

                // Bernstein polynomial
                if (Menu_Bern.Checked)
                {
                    Point2D current_left;
                    Point2D current_right = new Point2D(Bernstein(0));

                    for (float t = alpha; t < 1; t += alpha)
                    {
                        current_left  = current_right;
                        current_right = Bernstein(t);
                        gfx.DrawLine(splinePen, current_left.P(), current_right.P());
                    }

                    gfx.DrawLine(splinePen, current_right.P(), Bernstein(1).P());
                }
            }

            if (Menu_Project2.Checked)
            {
            }

            if (Menu_Project3.Checked)
            {
            }

            if (Menu_Project4.Checked)
            {
            }

            if (Menu_Project5.Checked)
            {
            }

            if (Menu_Project6.Checked)
            {
            }

            if (Menu_Project7.Checked)
            {
            }

            if (Menu_Project8.Checked)
            {
            }



            // DeCastlejau algorithm
            if (Menu_DeCast.Checked)
            {
                Point2D current_left;
                Point2D current_right = new Point2D(DeCastlejau(0));

                //Loop to connect 'major' points w/ coef. attached
                for (float t = alpha; t < 1; t += alpha)
                {
                    current_left  = current_right;
                    current_right = DeCastlejau(t);
                    gfx.DrawLine(splinePen, current_left.P(), current_right.P());
                }

                gfx.DrawLine(splinePen, current_right.P(), DeCastlejau(1).P());
            }

            // Bernstein polynomial
            if (Menu_Bern.Checked)
            {
                Point2D current_left;
                Point2D current_right = new Point2D(Bernstein(0));



                for (float t = alpha; t < 1; t += alpha)
                {
                    current_left = current_right;



                    current_right = Bernstein(t);



                    gfx.DrawLine(splinePen, current_left.P(), current_right.P());
                }


                //Do NOT want Bernstein(1), as this will make the (1-t) term always 0--cancels everything else out!
                //Instead, use something very close to 1
                gfx.DrawLine(splinePen, current_right.P(), Bernstein(1).P());
            }

            // Midpoint algorithm
            if (Menu_Midpoint.Checked)
            {
                DrawMidpoint(gfx, splinePen, pts_);
            }

            // polygon interpolation
            if (Menu_Inter_Poly.Checked)
            {
                Point2D current_left;
                Point2D current_right = new Point2D(PolyInterpolate(0));

                for (float t = alpha; t < pts_.Count; t += alpha)
                {
                    current_left  = current_right;
                    current_right = PolyInterpolate(t);
                    gfx.DrawLine(splinePen, current_left.P(), current_right.P());
                }

                gfx.DrawLine(splinePen, current_right.P(), PolyInterpolate(pts_.Count).P());
            }

            // spline interpolation
            if (Menu_Inter_Splines.Checked)
            {
                Point2D current_left;
                Point2D current_right = new Point2D(SplineInterpolate(0));

                for (float t = alpha; t < pts_.Count; t += alpha)
                // for(int t=0;t<pts_.Count;t++)
                {
                    current_left  = current_right;
                    current_right = SplineInterpolate(t);
                    gfx.DrawLine(splinePen, current_left.P(), current_right.P());
                }

                gfx.DrawLine(splinePen, current_right.P(), SplineInterpolate(pts_.Count).P());
            }

            // deboor
            if (Menu_DeBoor.Checked && pts_.Count >= 2)
            {
                Point2D current_left;
                Point2D current_right = new Point2D(DeBoorAlgthm(knot_[degree_]));

                float lastT = knot_[knot_.Count - degree_ - 1] - alpha;
                for (float t = alpha; t < lastT; t += alpha)
                {
                    current_left  = current_right;
                    current_right = DeBoorAlgthm(t);
                    gfx.DrawLine(splinePen, current_left.P(), current_right.P());
                }

                gfx.DrawLine(splinePen, current_right.P(), DeBoorAlgthm(lastT).P());
            }

            ///////////////////////////////////////////////////////////////////////////////
            // Drawing code end                                                          //
            ///////////////////////////////////////////////////////////////////////////////


            // Heads up Display drawing code

            Font arial = new Font("Arial", 12);

            if (Menu_DeCast.Checked)
            {
                gfx.DrawString("DeCasteljau", arial, Brushes.Black, 0, 30);
            }
            else if (Menu_Midpoint.Checked)
            {
                gfx.DrawString("Midpoint", arial, Brushes.Black, 0, 30);
            }
            else if (Menu_Bern.Checked)
            {
                gfx.DrawString("Bernstein", arial, Brushes.Black, 0, 30);
            }
            else if (Menu_DeBoor.Checked)
            {
                gfx.DrawString("DeBoor", arial, Brushes.Black, 0, 30);
            }

            gfx.DrawString("t-value: " + tVal_.ToString("F"), arial, Brushes.Black, 500, 30);

            gfx.DrawString("t-step: " + alpha.ToString("F6"), arial, Brushes.Black, 600, 30);

            gfx.DrawString(pts_.Count.ToString(), arial, Brushes.Black, 750, 30);
        }
Beispiel #48
0
        /// <summary>
        /// 图片等比缩放
        /// </summary>
        /// <remarks>谭光洪 2015-05-09</remarks>
        /// <param name="fromFile">原图Stream对象</param>
        /// <param name="savePath">缩略图存放地址</param>
        /// <param name="targetWidth">指定的最大宽度</param>
        /// <param name="targetHeight">指定的最大高度</param>
        /// <param name="watermarkText">水印文字(为""表示不使用水印)</param>
        /// <param name="watermarkImage">水印图片路径(为""表示不使用水印)</param>
        public static void ZoomAuto(System.IO.Stream fromFile, string savePath, System.Double targetWidth, System.Double targetHeight, string watermarkText, string watermarkImage)
        {
            //创建目录
            string dir = Path.GetDirectoryName(savePath);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            //原始图片(获取原始图片创建对象,并使用流中嵌入的颜色管理信息)
            System.Drawing.Image initImage = System.Drawing.Image.FromStream(fromFile, true);

            //原图宽高均小于模版,不作处理,直接保存
            if (initImage.Width <= targetWidth && initImage.Height <= targetHeight)
            {
                //文字水印
                if (watermarkText != "")
                {
                    using (System.Drawing.Graphics gWater = System.Drawing.Graphics.FromImage(initImage))
                    {
                        System.Drawing.Font  fontWater  = new Font("黑体", 10);
                        System.Drawing.Brush brushWater = new SolidBrush(Color.White);
                        gWater.DrawString(watermarkText, fontWater, brushWater, 10, 10);
                        gWater.Dispose();
                    }
                }

                //透明图片水印
                if (watermarkImage != "")
                {
                    if (File.Exists(watermarkImage))
                    {
                        //获取水印图片
                        using (System.Drawing.Image wrImage = System.Drawing.Image.FromFile(watermarkImage))
                        {
                            //水印绘制条件:原始图片宽高均大于或等于水印图片
                            if (initImage.Width >= wrImage.Width && initImage.Height >= wrImage.Height)
                            {
                                Graphics gWater = Graphics.FromImage(initImage);

                                //透明属性
                                ImageAttributes imgAttributes = new ImageAttributes();
                                ColorMap        colorMap      = new ColorMap();
                                colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);
                                colorMap.NewColor = Color.FromArgb(0, 0, 0, 0);
                                ColorMap[] remapTable = { colorMap };
                                imgAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);

                                float[][] colorMatrixElements =
                                {
                                    new float[] { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f },
                                    new float[] { 0.0f, 1.0f, 0.0f, 0.0f, 0.0f },
                                    new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f },
                                    new float[] { 0.0f, 0.0f, 0.0f, 0.5f, 0.0f },//透明度:0.5
                                    new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }
                                };

                                ColorMatrix wmColorMatrix = new ColorMatrix(colorMatrixElements);
                                imgAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
                                gWater.DrawImage(wrImage, new Rectangle(initImage.Width - wrImage.Width, initImage.Height - wrImage.Height, wrImage.Width, wrImage.Height), 0, 0, wrImage.Width, wrImage.Height, GraphicsUnit.Pixel, imgAttributes);

                                gWater.Dispose();
                            }
                            wrImage.Dispose();
                        }
                    }
                }

                //保存
                initImage.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            else
            {
                //缩略图宽、高计算
                double newWidth  = initImage.Width;
                double newHeight = initImage.Height;

                //宽大于高或宽等于高(横图或正方)
                if (initImage.Width > initImage.Height || initImage.Width == initImage.Height)
                {
                    //如果宽大于模版
                    if (initImage.Width > targetWidth)
                    {
                        //宽按模版,高按比例缩放
                        newWidth  = targetWidth;
                        newHeight = initImage.Height * (targetWidth / initImage.Width);
                    }
                }
                //高大于宽(竖图)
                else
                {
                    //如果高大于模版
                    if (initImage.Height > targetHeight)
                    {
                        //高按模版,宽按比例缩放
                        newHeight = targetHeight;
                        newWidth  = initImage.Width * (targetHeight / initImage.Height);
                    }
                }

                //生成新图
                //新建一个bmp图片
                System.Drawing.Image newImage = new System.Drawing.Bitmap((int)newWidth, (int)newHeight);
                //新建一个画板
                System.Drawing.Graphics newG = System.Drawing.Graphics.FromImage(newImage);

                //设置质量
                newG.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                newG.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                //置背景色
                newG.Clear(Color.White);
                //画图
                newG.DrawImage(initImage, new System.Drawing.Rectangle(0, 0, newImage.Width, newImage.Height), new System.Drawing.Rectangle(0, 0, initImage.Width, initImage.Height), System.Drawing.GraphicsUnit.Pixel);

                //文字水印
                if (watermarkText != "")
                {
                    using (System.Drawing.Graphics gWater = System.Drawing.Graphics.FromImage(newImage))
                    {
                        System.Drawing.Font  fontWater  = new Font("宋体", 10);
                        System.Drawing.Brush brushWater = new SolidBrush(Color.White);
                        gWater.DrawString(watermarkText, fontWater, brushWater, 10, 10);
                        gWater.Dispose();
                    }
                }

                //透明图片水印
                if (watermarkImage != "")
                {
                    if (File.Exists(watermarkImage))
                    {
                        //获取水印图片
                        using (System.Drawing.Image wrImage = System.Drawing.Image.FromFile(watermarkImage))
                        {
                            //水印绘制条件:原始图片宽高均大于或等于水印图片
                            if (newImage.Width >= wrImage.Width && newImage.Height >= wrImage.Height)
                            {
                                Graphics gWater = Graphics.FromImage(newImage);

                                //透明属性
                                ImageAttributes imgAttributes = new ImageAttributes();
                                ColorMap        colorMap      = new ColorMap();
                                colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);
                                colorMap.NewColor = Color.FromArgb(0, 0, 0, 0);
                                ColorMap[] remapTable = { colorMap };
                                imgAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);

                                float[][] colorMatrixElements =
                                {
                                    new float[] { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f },
                                    new float[] { 0.0f, 1.0f, 0.0f, 0.0f, 0.0f },
                                    new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f },
                                    new float[] { 0.0f, 0.0f, 0.0f, 0.5f, 0.0f },//透明度:0.5
                                    new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }
                                };

                                ColorMatrix wmColorMatrix = new ColorMatrix(colorMatrixElements);
                                imgAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
                                gWater.DrawImage(wrImage, new Rectangle(newImage.Width - wrImage.Width, newImage.Height - wrImage.Height, wrImage.Width, wrImage.Height), 0, 0, wrImage.Width, wrImage.Height, GraphicsUnit.Pixel, imgAttributes);
                                gWater.Dispose();
                            }
                            wrImage.Dispose();
                        }
                    }
                }

                //保存缩略图
                newImage.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);

                //释放资源
                newG.Dispose();
                newImage.Dispose();
                initImage.Dispose();
            }
        }
    private void CreateCheckCodeImage(string checkCode)
    {
        if (checkCode == null || checkCode.Trim() == String.Empty)
        {
            return;
        }

        System.Drawing.Bitmap   image = new System.Drawing.Bitmap((int)Math.Ceiling((checkCode.Length * 15.0 + 40)), 23);
        System.Drawing.Graphics g     = System.Drawing.Graphics.FromImage(image);

        try
        {
            //生成随机生成器
            Random random = new Random();

            //清空图片背景色
            g.Clear(System.Drawing.Color.White);

            //画图片的背景噪音线
            for (int i = 0; i < 25; 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 System.Drawing.Pen(System.Drawing.Color.Silver), x1, y1, x2, y2);
            }

            System.Drawing.Font font = new System.Drawing.Font("Arial", 14, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic));
            System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new System.Drawing.Rectangle(0, 0, image.Width, image.Height), System.Drawing.Color.Blue, System.Drawing.Color.DarkRed, 1.2f, true);

            int cySpace = 16;
            for (int i = 0; i < validateCodeCount; i++)
            {
                g.DrawString(checkCode.Substring(i, 1), font, brush, (i + 1) * cySpace, 1);
            }

            //画图片的前景噪音点
            for (int i = 0; i < 100; i++)
            {
                int x = random.Next(image.Width);
                int y = random.Next(image.Height);

                image.SetPixel(x, y, System.Drawing.Color.FromArgb(random.Next()));
            }

            //画图片的边框线
            g.DrawRectangle(new System.Drawing.Pen(System.Drawing.Color.Silver), 0, 0, image.Width - 1, image.Height - 1);

            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
            Response.ClearContent();
            Response.ContentType = "image/Gif";
            Response.BinaryWrite(ms.ToArray());
        }
        finally
        {
            g.Dispose();
            image.Dispose();
        }
    }
        /// <summary>
        /// 生成水印图
        /// </summary>
        /// <param name="originalImagePath">源图绝对路径</param>
        /// <param name="watermarkType">水印类型:文字水印,图片水印</param>
        /// <param name="watermarkImage">水印图绝对路径</param>
        /// <param name="watermarkText">水印文字</param>
        /// <param name="fontSize">字体大小</param>
        /// <param name="fontColor">字体颜色</param>
        /// <param name="fontFamily">字体</param>
        /// <param name="watermarkPosition">水印位置</param>
        /// <param name="alpha">透明度</param>
        /// <param name="watermarkFilePath">水印图片保存路径,不填写则自动创建</param>
        /// <returns></returns>
        public static string AddWatermark(string originalImagePath, string watermarkType, string watermarkImage
                                          , string watermarkText, int fontSize, string fontColor, string fontFamily, WatermarkPosition watermarkPosition, float alpha, string watermarkFilePath = "")
        {
            Image img = Image.FromFile(originalImagePath);
            // 封装 GDI+ 位图,此位图由图形图像及其属性的像素数据组成。
            Bitmap bmPhoto = new Bitmap(img.Width, img.Height, PixelFormat.Format32bppRgb);

            // 设定分辨率
            bmPhoto.SetResolution(72, 72);
            System.Drawing.Graphics g = Graphics.FromImage(bmPhoto);
            //设置高质量插值法
            g.InterpolationMode = InterpolationMode.High;
            //消除锯齿
            g.SmoothingMode = SmoothingMode.AntiAlias;
            //g.SmoothingMode = SmoothingMode.HighQuality;
            g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel);

            //文件扩展名
            string strExt = Path.GetExtension(originalImagePath);

            //生成的水印图文件名
            if (watermarkFilePath.IsNullOrEmpty())
            {
                watermarkFilePath = originalImagePath.Replace(strExt, "_watermark" + strExt);
            }

            ImageAttributes imageAttributes = new ImageAttributes();
            ColorMap        colorMap        = new ColorMap();

            colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);
            colorMap.NewColor = Color.FromArgb(0, 0, 0, 0);
            ColorMap[] remapTable = { colorMap };
            imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);

            float[][] colorMatrixElements =
            {
                new float[] { 1.0f, 0.0f, 0.0f,  0.0f, 0.0f },
                new float[] { 0.0f, 1.0f, 0.0f,  0.0f, 0.0f },
                new float[] { 0.0f, 0.0f, 1.0f,  0.0f, 0.0f },
                new float[] { 0.0f, 0.0f, 0.0f, alpha, 0.0f },                                    //水印透明度
                new float[] { 0.0f, 0.0f, 0.0f,  0.0f, 1.0f }
            };
            ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);

            imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

            //水印所在位置
            int xpos = 0;
            int ypos = 0;

            int intWatermarkWidth  = 0;
            int intWatermarkHeight = 0;

            Image watermark = null;

            if (watermarkType.Equals("图片水印") && File.Exists(watermarkImage))
            {
                //加载水印图片
                watermark          = new Bitmap(watermarkImage);
                intWatermarkWidth  = watermark.Width;
                intWatermarkHeight = watermark.Height;
            }
            else if (watermarkType.Equals("文字水印") && watermarkText.Trim().Length > 0)
            {
                SizeF size = g.MeasureString(watermarkText, new Font(new FontFamily(fontFamily), fontSize));
                intWatermarkWidth  = (int)size.Width;
                intWatermarkHeight = (int)size.Height;
            }

            switch (watermarkPosition)
            {
            case WatermarkPosition.TopLeft:
                xpos = (int)(img.Width * (float).01);
                ypos = (int)(img.Height * (float).01);
                break;

            case WatermarkPosition.TopCenter:
                xpos = (int)((img.Width * (float).50) - (intWatermarkWidth / 2));
                ypos = (int)(img.Height * (float).01);
                break;

            case WatermarkPosition.TopRight:
                xpos = (int)((img.Width * (float).99) - (intWatermarkWidth));
                ypos = (int)(img.Height * (float).01);
                break;

            case WatermarkPosition.MiddleLeft:
                xpos = (int)(img.Width * (float).01);
                ypos = (int)((img.Height * (float).50) - (intWatermarkHeight / 2));
                break;

            case WatermarkPosition.MiddleCenter:
                xpos = (int)((img.Width * (float).50) - (intWatermarkWidth / 2));
                ypos = (int)((img.Height * (float).50) - (intWatermarkHeight / 2));
                break;

            case WatermarkPosition.MiddleRight:
                xpos = (int)((img.Width * (float).99) - (intWatermarkWidth));
                ypos = (int)((img.Height * (float).50) - (intWatermarkHeight / 2));
                break;

            case WatermarkPosition.BottomLeft:
                xpos = (int)(img.Width * (float).01);
                ypos = (int)((img.Height * (float).99) - intWatermarkHeight);
                break;

            case WatermarkPosition.BottomCenter:
                xpos = (int)((img.Width * (float).50) - (intWatermarkWidth / 2));
                ypos = (int)((img.Height * (float).99) - intWatermarkHeight);
                break;

            case WatermarkPosition.BottomRight:
                xpos = (int)((img.Width * (float).99) - (intWatermarkWidth));
                ypos = (int)((img.Height * (float).99) - intWatermarkHeight);
                break;
            }

            if (watermark != null) //在原图上画图片水印
            {
                g.DrawImage(watermark, new Rectangle(xpos, ypos, intWatermarkWidth, intWatermarkHeight), 0, 0, intWatermarkWidth, intWatermarkHeight, GraphicsUnit.Pixel, imageAttributes);
            }
            else
            {
                //在原图上画文本水印
                Font       font     = new Font(fontFamily, fontSize);                       //文字字体
                Color      fColor   = ColorTranslator.FromHtml(fontColor);
                Color      txtColor = Color.FromArgb(Convert.ToInt32(alpha * 255), fColor); //文字颜色
                SolidBrush brush    = new SolidBrush(txtColor);
                g.DrawString(watermarkText, font, brush, xpos, ypos);
            }

            ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
            ImageCodecInfo   ici    = null;

            foreach (ImageCodecInfo codec in codecs)
            {
                if (codec.MimeType.IndexOf("jpeg") > -1)
                {
                    ici = codec;
                }
            }
            EncoderParameters encoderParams = new EncoderParameters();

            long[] qualityParam = new long[1];
            qualityParam[0] = 80; //图片质量

            EncoderParameter encoderParam = new EncoderParameter(Encoder.Quality, qualityParam);

            encoderParams.Param[0] = encoderParam;

            if (ici != null)
            {
                bmPhoto.Save(watermarkFilePath, ici, encoderParams);
            }
            else
            {
                bmPhoto.Save(watermarkFilePath);
            }

            g.Dispose();
            img.Dispose();
            if (watermark != null)
            {
                watermark.Dispose();
            }
            imageAttributes.Dispose();

            return(watermarkFilePath);
        }
        public override void DrawDayHeader(System.Drawing.Graphics g, System.Drawing.Rectangle rect, DateTime date)
        {
            StringFormat m_Format = new StringFormat();

            m_Format.Alignment     = StringAlignment.Center;
            m_Format.FormatFlags   = StringFormatFlags.NoWrap;
            m_Format.LineAlignment = StringAlignment.Center;

            StringFormat m_Formatdd = new StringFormat();

            m_Formatdd.Alignment     = StringAlignment.Near;
            m_Formatdd.FormatFlags   = StringFormatFlags.NoWrap;
            m_Formatdd.LineAlignment = StringAlignment.Center;

            using (SolidBrush brush = new SolidBrush(this.BackColor))
                g.FillRectangle(brush, rect);

            using (Pen aPen = new Pen(Color.FromArgb(205, 219, 238)))
                g.DrawLine(aPen, rect.Left, rect.Top + (int)rect.Height / 2, rect.Right, rect.Top + (int)rect.Height / 2);

            using (Pen aPen = new Pen(Color.FromArgb(141, 174, 217)))
                g.DrawRectangle(aPen, rect);

            Rectangle topPart = new Rectangle(rect.Left + 1, rect.Top + 1, rect.Width - 2, (int)(rect.Height / 2) - 1);
            Rectangle lowPart = new Rectangle(rect.Left + 1, rect.Top + (int)(rect.Height / 2) + 1, rect.Width - 1, (int)(rect.Height / 2) - 1);

            using (LinearGradientBrush aGB = new LinearGradientBrush(topPart, Color.FromArgb(228, 236, 246), Color.FromArgb(214, 226, 241), LinearGradientMode.Vertical))
                g.FillRectangle(aGB, topPart);

            using (LinearGradientBrush aGB = new LinearGradientBrush(lowPart, Color.FromArgb(194, 212, 235), Color.FromArgb(208, 222, 239), LinearGradientMode.Vertical))
                g.FillRectangle(aGB, lowPart);

            if (date.Date.Equals(DateTime.Now.Date))
            {
                topPart.Inflate((int)(-topPart.Width / 4 + 1), 1); //top left orange area
                topPart.Offset(rect.Left - topPart.Left + 1, 1);
                topPart.Inflate(1, 0);
                using (LinearGradientBrush aGB = new LinearGradientBrush(topPart, Color.FromArgb(247, 207, 114), Color.FromArgb(251, 230, 148), LinearGradientMode.Horizontal))
                {
                    topPart.Inflate(-1, 0);
                    g.FillRectangle(aGB, topPart);
                }

                topPart.Offset(rect.Right - topPart.Right, 0);        //top right orange
                topPart.Inflate(1, 0);
                using (LinearGradientBrush aGB = new LinearGradientBrush(topPart, Color.FromArgb(251, 230, 148), Color.FromArgb(247, 207, 114), LinearGradientMode.Horizontal))
                {
                    topPart.Inflate(-1, 0);
                    g.FillRectangle(aGB, topPart);
                }

                using (Pen aPen = new Pen(Color.FromArgb(128, 240, 154, 30))) //center line
                    g.DrawLine(aPen, rect.Left, topPart.Bottom - 1, rect.Right, topPart.Bottom - 1);

                topPart.Inflate(0, -1);
                topPart.Offset(0, topPart.Height + 1); //lower right
                using (LinearGradientBrush aGB = new LinearGradientBrush(topPart, Color.FromArgb(240, 157, 33), Color.FromArgb(250, 226, 142), LinearGradientMode.BackwardDiagonal))
                    g.FillRectangle(aGB, topPart);

                topPart.Offset(rect.Left - topPart.Left + 1, 0); //lower left
                using (LinearGradientBrush aGB = new LinearGradientBrush(topPart, Color.FromArgb(240, 157, 33), Color.FromArgb(250, 226, 142), LinearGradientMode.ForwardDiagonal))
                    g.FillRectangle(aGB, topPart);
                using (Pen aPen = new Pen(Color.FromArgb(238, 147, 17)))
                    g.DrawRectangle(aPen, rect);
            }

            g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

            //get short dayabbr. if narrow dayrect
            string sTodaysName = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(date.DayOfWeek);

            if (rect.Width < 105)
            {
                sTodaysName = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetAbbreviatedDayName(date.DayOfWeek);
            }

            rect.Offset(2, 1);

            using (Font fntDay = new Font("Segoe UI", 8))
                g.DrawString(sTodaysName, fntDay, SystemBrushes.WindowText, rect, m_Format);

            rect.Offset(-2, -1);

            using (Font fntDayDate = new Font("Segoe UI", 9, FontStyle.Bold))
                g.DrawString(date.ToString(" d"), fntDayDate, SystemBrushes.WindowText, rect, m_Formatdd);
        }
Beispiel #52
0
        private void Draw(System.Drawing.Graphics g, int area, int pageIndex, int cur_top)
        {
            Helper.ReadXml r = new Helper.ReadXml(xml);

            int offset_y = 0;

            if (area == 1)
            {
                offset_y -= barHeight;
            }
            else if (area == 2)
            {
                offset_y -= ah + 2 * barHeight;
            }
            else if (area == 3)
            {
                offset_y -= ah + bh + barHeight * 3;
            }
            else if (area == 4)
            {
                offset_y -= ah + bh + ch + barHeight * 4;
            }
            else if (area == 5)
            {
                offset_y -= ah + bh + ch + dh + barHeight * 5;
            }
            if (area == 5)
            {
                cur_top = pageHeight - eh;
            }
            foreach (Helper.ReadXml r2 in r.ReadList("PrintObject1"))
            {
                int left = Convert.ToInt16(r2.Read("Left"));
                int top  = Convert.ToInt16(r2.Read("Top"));
                top += offset_y + cur_top;
                int           Width         = Convert.ToInt16(r2.Read("Width"));
                int           Height        = Convert.ToInt16(r2.Read("Height"));
                string        context       = r2.Read("Context");
                int           Align         = Convert.ToInt16(r2.Read("Align"));
                var           sf            = Helper.Conv.AlignToStringFormat(Align);
                FontConverter fc            = new FontConverter();
                var           font          = (Font)fc.ConvertFromString(r2.Read("Font"));
                var           color         = Color.FromArgb(Convert.ToInt32(r2.Read("Color")));
                int           Area          = Convert.ToInt16(r2.Read("Area"));
                int           _BorderLeft   = Convert.ToInt16(r2.Read("BorderLeft"));
                int           _BorderRight  = Convert.ToInt16(r2.Read("BorderRight"));
                int           _BorderTop    = Convert.ToInt16(r2.Read("BorderTop"));
                int           _BorderBottom = Convert.ToInt16(r2.Read("BorderBottom"));
                Rectangle     rec           = new Rectangle(left, top, Width, Height);

                if (Area == area)
                {
                    g.DrawString(context, font, new SolidBrush(color), rec, sf);
                    if (_BorderLeft == 1)
                    {
                        g.DrawLine(Pens.Black, left, top, left, top + Height);
                    }
                    if (_BorderRight == 1)
                    {
                        g.DrawLine(Pens.Black, left + Width, top, left + Width, top + Height);
                    }
                    if (_BorderTop == 1)
                    {
                        g.DrawLine(Pens.Black, left, top, left + Width, top);
                    }
                    if (_BorderBottom == 1)
                    {
                        g.DrawLine(Pens.Black, left, top + Height, left + Width, top + Height);
                    }
                }
            }
            foreach (Helper.ReadXml r2 in r.ReadList("PrintObject2"))
            {
                int left = Convert.ToInt16(r2.Read("Left"));
                int top  = Convert.ToInt16(r2.Read("Top"));
                top += offset_y + cur_top;
                int           Width         = Convert.ToInt16(r2.Read("Width"));
                int           Height        = Convert.ToInt16(r2.Read("Height"));
                string        Field         = r2.Read("Field");
                string        Format        = r2.Read("Format");
                int           Align         = Convert.ToInt16(r2.Read("Align"));
                var           sf            = Helper.Conv.AlignToStringFormat(Align);
                FontConverter fc            = new FontConverter();
                var           font          = (Font)fc.ConvertFromString(r2.Read("Font"));
                var           color         = Color.FromArgb(Convert.ToInt32(r2.Read("Color")));
                int           Area          = Convert.ToInt16(r2.Read("Area"));
                int           _BorderLeft   = Convert.ToInt16(r2.Read("BorderLeft"));
                int           _BorderRight  = Convert.ToInt16(r2.Read("BorderRight"));
                int           _BorderTop    = Convert.ToInt16(r2.Read("BorderTop"));
                int           _BorderBottom = Convert.ToInt16(r2.Read("BorderBottom"));
                Rectangle     rec           = new Rectangle(left, top, Width, Height);

                if (Area == area)
                {
                    if (tbmain.Rows.Count != 0)
                    {
                        if (tbmain.Columns.Contains(Field) == true)
                        {
                            DataRow    row = tbmain.Rows[0];
                            DataColumn col = tbmain.Columns[Field];

                            if (tbmain.Columns[Field].DataType == typeof(byte[]))
                            {
                                System.IO.MemoryStream ms = new System.IO.MemoryStream((byte[])row[Field]);
                                Image img = Image.FromStream(ms);
                                g.DrawImage(img, rec);
                                continue;
                            }
                            string context = "";
                            if (Format == "")
                            {
                                context = row[Field].ToString();
                            }
                            else if (Format == "大写金额")
                            {
                                context = Helper.Conv.DaXie2(row[Field].ToString());
                            }
                            else
                            {
                                if (col.DataType == typeof(decimal))
                                {
                                    context = Helper.Conv.ToDecimal(row[Field]).ToString(Format);
                                }
                                else if (col.DataType == typeof(Int16))
                                {
                                    context = Helper.Conv.ToInt16(row[Field]).ToString(Format);
                                }
                                else if (col.DataType == typeof(Int32))
                                {
                                    context = Helper.Conv.ToInt32(row[Field]).ToString(Format);
                                }
                                else if (col.DataType == typeof(DateTime))
                                {
                                    context = Helper.Conv.ToDateTime(row[Field]).ToString(Format);
                                }
                                else
                                {
                                    context = row[Field].ToString();
                                }
                            }

                            g.DrawString(context, font, new SolidBrush(color), rec, sf);
                            if (_BorderLeft == 1)
                            {
                                g.DrawLine(Pens.Black, left, top, left, top + Height);
                            }
                            if (_BorderRight == 1)
                            {
                                g.DrawLine(Pens.Black, left + Width, top, left + Width, top + Height);
                            }
                            if (_BorderTop == 1)
                            {
                                g.DrawLine(Pens.Black, left, top, left + Width, top);
                            }
                            if (_BorderBottom == 1)
                            {
                                g.DrawLine(Pens.Black, left, top + Height, left + Width, top + Height);
                            }
                        }
                    }
                }
            }
            foreach (Helper.ReadXml r2 in r.ReadList("PrintObject3"))
            {
                int left = Convert.ToInt16(r2.Read("Left"));
                int top  = Convert.ToInt16(r2.Read("Top"));
                top += offset_y + cur_top;
                int           Width         = Convert.ToInt16(r2.Read("Width"));
                int           Height        = Convert.ToInt16(r2.Read("Height"));
                string        Field         = r2.Read("Field");
                string        Format        = r2.Read("Format");
                int           Align         = Convert.ToInt16(r2.Read("Align"));
                var           sf            = Helper.Conv.AlignToStringFormat(Align);
                FontConverter fc            = new FontConverter();
                var           font          = (Font)fc.ConvertFromString(r2.Read("Font"));
                var           color         = Color.FromArgb(Convert.ToInt32(r2.Read("Color")));
                int           Area          = Convert.ToInt16(r2.Read("Area"));
                int           _BorderLeft   = Convert.ToInt16(r2.Read("BorderLeft"));
                int           _BorderRight  = Convert.ToInt16(r2.Read("BorderRight"));
                int           _BorderTop    = Convert.ToInt16(r2.Read("BorderTop"));
                int           _BorderBottom = Convert.ToInt16(r2.Read("BorderBottom"));
                Rectangle     rec           = new Rectangle(left, top, Width, Height);

                if (Area == area)
                {
                    if (tbdetail.Rows.Count != 0)
                    {
                        if (tbdetail.Columns.Contains(Field) == true)
                        {
                            var     col     = tbdetail.Columns[Field];
                            string  context = "";
                            decimal val     = 0;
                            foreach (DataRow row in tbdetail.Rows)
                            {
                                val += Helper.Conv.ToDecimal(row[Field].ToString());
                            }
                            if (Format == "")
                            {
                                context = val.ToString();
                            }
                            else if (Format == "大写金额")
                            {
                                context = Helper.Conv.DaXie2(val.ToString("0.00"));
                            }
                            else
                            {
                                if (col.DataType == typeof(decimal))
                                {
                                    context = val.ToString(Format);
                                }
                                else if (col.DataType == typeof(Int16))
                                {
                                    context = Helper.Conv.ToInt16(val).ToString(Format);
                                }
                                else if (col.DataType == typeof(Int32))
                                {
                                    context = Helper.Conv.ToInt32(val).ToString(Format);
                                }
                                else if (col.DataType == typeof(DateTime))
                                {
                                    context = Helper.Conv.ToDateTime(val).ToString(Format);
                                }
                                else
                                {
                                    context = val.ToString();
                                }
                            }

                            g.DrawString(context, font, new SolidBrush(color), rec, sf);
                            if (_BorderLeft == 1)
                            {
                                g.DrawLine(Pens.Black, left, top, left, top + Height);
                            }
                            if (_BorderRight == 1)
                            {
                                g.DrawLine(Pens.Black, left + Width, top, left + Width, top + Height);
                            }
                            if (_BorderTop == 1)
                            {
                                g.DrawLine(Pens.Black, left, top, left + Width, top);
                            }
                            if (_BorderBottom == 1)
                            {
                                g.DrawLine(Pens.Black, left, top + Height, left + Width, top + Height);
                            }
                        }
                    }
                }
            }
            foreach (Helper.ReadXml r2 in r.ReadList("PrintObject4"))
            {
                int left = Convert.ToInt16(r2.Read("Left"));
                int top  = Convert.ToInt16(r2.Read("Top"));
                top += offset_y + cur_top;
                int Width  = Convert.ToInt16(r2.Read("Width"));
                int Height = Convert.ToInt16(r2.Read("Height"));
                var color  = Color.FromArgb(Convert.ToInt32(r2.Read("Color")));
                int Area   = Convert.ToInt16(r2.Read("Area"));
                if (Area == area)
                {
                    g.DrawLine(new Pen(color), left + Width / 2, top, left + Width / 2, top + Height);
                }
            }
            foreach (Helper.ReadXml r2 in r.ReadList("PrintObject5"))
            {
                int left = Convert.ToInt16(r2.Read("Left"));
                int top  = Convert.ToInt16(r2.Read("Top"));
                top += offset_y + cur_top;
                int Width  = Convert.ToInt16(r2.Read("Width"));
                int Height = Convert.ToInt16(r2.Read("Height"));
                var color  = Color.FromArgb(Convert.ToInt32(r2.Read("Color")));
                int Area   = Convert.ToInt16(r2.Read("Area"));
                if (Area == area)
                {
                    g.DrawLine(new Pen(color), left, top + Height / 2, left + Width, top + Height / 2);
                }
            }
            foreach (Helper.ReadXml r2 in r.ReadList("PrintObject6"))
            {
                int left = Convert.ToInt16(r2.Read("Left"));
                int top  = Convert.ToInt16(r2.Read("Top"));
                top += offset_y + cur_top;
                int       Width  = Convert.ToInt16(r2.Read("Width"));
                int       Height = Convert.ToInt16(r2.Read("Height"));
                var       img    = Helper.Conv.StringToImage(r2.Read("Image"));
                int       Area   = Convert.ToInt16(r2.Read("Area"));
                Rectangle rec    = new Rectangle(left, top, Width, Height);
                if (Area == area)
                {
                    g.DrawImage(img, rec);
                }
            }
            foreach (Helper.ReadXml r2 in r.ReadList("PrintObject7"))
            {
                int left = Convert.ToInt16(r2.Read("Left"));
                int top  = Convert.ToInt16(r2.Read("Top"));

                top += offset_y + cur_top;
                int Width  = Convert.ToInt16(r2.Read("Width"));
                int Height = Convert.ToInt16(r2.Read("Height"));

                int           Align         = Convert.ToInt16(r2.Read("Align"));
                var           sf            = Helper.Conv.AlignToStringFormat(Align);
                FontConverter fc            = new FontConverter();
                var           font          = (Font)fc.ConvertFromString(r2.Read("Font"));
                var           color         = Color.FromArgb(Convert.ToInt32(r2.Read("Color")));
                int           Area          = Convert.ToInt16(r2.Read("Area"));
                int           _BorderLeft   = Convert.ToInt16(r2.Read("BorderLeft"));
                int           _BorderRight  = Convert.ToInt16(r2.Read("BorderRight"));
                int           _BorderTop    = Convert.ToInt16(r2.Read("BorderTop"));
                int           _BorderBottom = Convert.ToInt16(r2.Read("BorderBottom"));
                Rectangle     rec           = new Rectangle(left, top, Width, Height);

                if (Area == area)
                {
                    string context = "第N页,共M页".Replace("N", pageIndex.ToString())
                                     .Replace("M", PageCount.ToString());
                    g.DrawString(context, font, new SolidBrush(color), rec, sf);
                    if (_BorderLeft == 1)
                    {
                        g.DrawLine(Pens.Black, left, top, left, top + Height);
                    }
                    if (_BorderRight == 1)
                    {
                        g.DrawLine(Pens.Black, left + Width, top, left + Width, top + Height);
                    }
                    if (_BorderTop == 1)
                    {
                        g.DrawLine(Pens.Black, left, top, left + Width, top);
                    }
                    if (_BorderBottom == 1)
                    {
                        g.DrawLine(Pens.Black, left, top + Height, left + Width, top + Height);
                    }
                }
            }
            foreach (Helper.ReadXml r2 in r.ReadList("PrintObject8"))
            {
                int left = Convert.ToInt16(r2.Read("Left"));
                int top  = Convert.ToInt16(r2.Read("Top"));
                top += offset_y + cur_top;
                int           Width         = Convert.ToInt16(r2.Read("Width"));
                int           Height        = Convert.ToInt16(r2.Read("Height"));
                string        format        = r2.Read("Format");
                int           Align         = Convert.ToInt16(r2.Read("Align"));
                var           sf            = Helper.Conv.AlignToStringFormat(Align);
                FontConverter fc            = new FontConverter();
                var           font          = (Font)fc.ConvertFromString(r2.Read("Font"));
                var           color         = Color.FromArgb(Convert.ToInt32(r2.Read("Color")));
                int           Area          = Convert.ToInt16(r2.Read("Area"));
                int           _BorderLeft   = Convert.ToInt16(r2.Read("BorderLeft"));
                int           _BorderRight  = Convert.ToInt16(r2.Read("BorderRight"));
                int           _BorderTop    = Convert.ToInt16(r2.Read("BorderTop"));
                int           _BorderBottom = Convert.ToInt16(r2.Read("BorderBottom"));
                Rectangle     rec           = new Rectangle(left, top, Width, Height);

                if (Area == area)
                {
                    string context = "";
                    if (format == "")
                    {
                        context = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    }
                    else
                    {
                        context = System.DateTime.Now.ToString(format);
                    }
                    g.DrawString(context, font, new SolidBrush(color), rec, sf);
                    if (_BorderLeft == 1)
                    {
                        g.DrawLine(Pens.Black, left, top, left, top + Height);
                    }
                    if (_BorderRight == 1)
                    {
                        g.DrawLine(Pens.Black, left + Width, top, left + Width, top + Height);
                    }
                    if (_BorderTop == 1)
                    {
                        g.DrawLine(Pens.Black, left, top, left + Width, top);
                    }
                    if (_BorderBottom == 1)
                    {
                        g.DrawLine(Pens.Black, left, top + Height, left + Width, top + Height);
                    }
                }
            }
        }
        public override void DrawAppointment(System.Drawing.Graphics g, System.Drawing.Rectangle rect, Appointment appointment, bool isSelected, int gripWidth)
        {
            StringFormat m_Format = new StringFormat();

            m_Format.Alignment     = StringAlignment.Near;
            m_Format.LineAlignment = StringAlignment.Near;

            Color start = InterpolateColors(appointment.Color, Color.White, 0.4f);
            Color end   = InterpolateColors(appointment.Color, Color.FromArgb(191, 210, 234), 0.7f);

            if ((appointment.Locked))
            {
                // Draw back
                using (Brush m_Brush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.LargeConfetti, Color.Blue, appointment.Color))
                    g.FillRectangle(m_Brush, rect);

                // little transparent
                start = Color.FromArgb(230, start);
                end   = Color.FromArgb(180, end);

                GraphicsPath path = new GraphicsPath();
                path.AddRectangle(rect);

                using (LinearGradientBrush aGB = new LinearGradientBrush(rect, start, end, LinearGradientMode.Vertical))
                    g.FillRectangle(aGB, rect);
            }
            else
            {
                // Draw back
                using (LinearGradientBrush aGB = new LinearGradientBrush(rect, start, end, LinearGradientMode.Vertical))
                    g.FillRectangle(aGB, rect);
            }

            if (isSelected)
            {
                Rectangle m_BorderRectangle = rect;

                using (Pen m_Pen = new Pen(appointment.BorderColor, 4))
                    g.DrawRectangle(m_Pen, rect);

                m_BorderRectangle.Inflate(2, 2);

                using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                    g.DrawRectangle(m_Pen, m_BorderRectangle);

                m_BorderRectangle.Inflate(-4, -4);

                using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                    g.DrawRectangle(m_Pen, m_BorderRectangle);
            }
            else
            {
                // Draw gripper
                Rectangle m_GripRectangle = rect;

                m_GripRectangle.Width = gripWidth + 1;

                start = InterpolateColors(appointment.BorderColor, appointment.Color, 0.2f);
                end   = InterpolateColors(appointment.BorderColor, Color.White, 0.6f);

                using (LinearGradientBrush aGB = new LinearGradientBrush(rect, start, end, LinearGradientMode.Vertical))
                    g.FillRectangle(aGB, m_GripRectangle);

                using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1))
                    g.DrawRectangle(m_Pen, rect);

                // Draw shadow lines
                int xLeft   = rect.X + 6;
                int xRight  = rect.Right + 1;
                int yTop    = rect.Y + 1;
                int yButton = rect.Bottom + 1;

                for (int i = 0; i < 5; i++)
                {
                    using (Pen shadow_Pen = new Pen(Color.FromArgb(70 - 12 * i, Color.Black)))
                    {
                        g.DrawLine(shadow_Pen, xLeft + i, yButton + i, xRight + i - 1, yButton + i); //horisontal lines
                        g.DrawLine(shadow_Pen, xRight + i, yTop + i, xRight + i, yButton + i);       //vertical
                    }
                }
            }

            rect.X += gripWidth;
            g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            g.DrawString(appointment.Title, this.BaseFont, SystemBrushes.WindowText, rect, m_Format);
            g.TextRenderingHint = TextRenderingHint.SystemDefault;
        }
 public void DrawString(string text, Font font, Color foreground, Point location)
 {
     _currentBrush.Color = ColorToGdiColor(foreground);
     _graphics.DrawString(text, ToGdiFont(font), _currentBrush, (float)location.X, (float)location.Y);
 }
        void IDrawDetail.Draw(System.Drawing.Graphics g, string styleXml, System.Data.DataTable tbdetail, int pageIndex)
        {
            //
            ReadXml r       = new ReadXml(styleXml);
            var     tbstyle = new DataTable();

            tbstyle.Columns.Add("colname");
            tbstyle.Columns.Add("colbyname");
            tbstyle.Columns.Add("width", typeof(int));
            tbstyle.Columns.Add("align");
            tbstyle.Columns.Add("format");
            foreach (Helper.ReadXml r2 in r.ReadList("PrintObject3/Column"))
            {
                if (r2.Read("Display") == "1")
                {
                    var row = tbstyle.NewRow();
                    tbstyle.Rows.Add(row);
                    row["colname"]   = r2.Read("ColName");
                    row["colbyname"] = r2.Read("ColByname");
                    row["width"]     = Convert.ToInt16(r2.Read("Width"));
                    row["align"]     = r2.Read("Align");
                    row["format"]    = r2.Read("Format");
                }
            }
            //
            int           left             = Convert.ToInt16(r.Read("PrintObject3/Left"));
            int           top              = Convert.ToInt16(r.Read("PrintObject3/Top"));
            int           Width            = Convert.ToInt16(r.Read("PrintObject3/Width"));
            int           Height           = Convert.ToInt16(r.Read("PrintObject3/Height"));
            int           columnHeight     = Convert.ToInt16(r.Read("PrintObject3/ColumnHeight"));
            int           rowHeight        = Convert.ToInt16(r.Read("PrintObject3/RowHeight"));
            FontConverter fc               = new FontConverter();
            var           font             = (Font)fc.ConvertFromString(r.Read("PrintObject3/Font"));
            var           color            = Color.FromArgb(Convert.ToInt32(r.Read("PrintObject3/Color")));
            int           AutoRow          = Convert.ToInt16(r.Read("PrintObject3/AutoRow"));
            int           SmallTotal       = Helper.Conv.ToInt16(r.Read("PrintObject3/SmallTotal"));
            string        SmallTotalFields = r.Read("PrintObject3/SmallTotalFields");

            //

            int width2 = 0;
            int width3 = 0;

            foreach (DataRow row in tbstyle.Rows)
            {
                if (row["colname"].ToString() == "#")
                {
                    width3 = Conv.ToInt16(row["width"]);
                }
                else
                {
                    width2 += Conv.ToInt16(row["width"]);
                }
            }

            int num = 0;

            foreach (DataColumn col in tbdetail.Columns)
            {
                if (col.ColumnName.StartsWith("#") == true)
                {
                    num++;
                }
            }
            int addwidth = num * width3;

            if (Width - width2 > 0)
            {
                addwidth = addwidth - (Width - width2);
            }
            decimal rate = 1;

            if (addwidth > 0)
            {
                rate = (decimal)(width2 - addwidth) / (decimal)width2;
            }

            DataRow specRow = null;

            foreach (DataRow row in tbstyle.Rows)
            {
                if (row["colname"].ToString() == "#")
                {
                    specRow = row;
                }
                else
                {
                    row["width"] = (int)(Conv.ToDecimal(row["width"]) * rate);
                }
            }
            //

            foreach (DataColumn col in tbdetail.Columns)
            {
                if (col.ColumnName.StartsWith("#") == true)
                {
                    DataRow row = tbstyle.NewRow();
                    row.ItemArray    = specRow.ItemArray;
                    row["colname"]   = col.ColumnName;
                    row["colbyname"] = col.ColumnName.Substring(1);
                    var specRowIndex = tbstyle.Rows.IndexOf(specRow);
                    tbstyle.Rows.InsertAt(row, specRowIndex);
                }
            }
            if (specRow != null)
            {
                tbstyle.Rows.Remove(specRow);
            }
            //
            int pageRowCount = 0;

            if (SmallTotal == 1)
            {
                pageRowCount = (Height - columnHeight - rowHeight) / rowHeight;
            }
            else
            {
                pageRowCount = (Height - columnHeight) / rowHeight;
            }
            var tb = Helper.Conv.Paging(tbdetail, pageRowCount, pageIndex);

            if (AutoRow == 1)
            {
                for (int j = tb.Rows.Count - 1; j < pageRowCount; j++)
                {
                    tb.Rows.Add(tb.NewRow());
                }
            }
            if (SmallTotal == 1)
            {
                DataRow row = tb.NewRow();
                foreach (string field in SmallTotalFields.Split(','))
                {
                    if (field == "#")
                    {
                        foreach (DataColumn col in tbdetail.Columns)
                        {
                            if (col.ColumnName.StartsWith("#") == true)
                            {
                                row[col.ColumnName] = tb.Compute("sum([" + col.ColumnName + "])", "");
                            }
                        }
                    }
                    else
                    {
                        if (tbdetail.Columns.Contains(field) == true)
                        {
                            row[field] = tb.Compute("sum([" + field + "])", "");
                        }
                    }
                }
                row["i"] = "小计";
                tb.Rows.Add(row);
            }

            //
            int l = left;
            int t = top;

            for (int i = 0; i < tbstyle.Rows.Count; i++)
            {
                DataRow row       = tbstyle.Rows[i];
                string  colname   = row["colname"].ToString();
                string  colbyname = row["colbyname"].ToString();
                int     colwidth  = Convert.ToInt16(row["width"].ToString());
                int     align     = Convert.ToInt16(row["align"].ToString());
                var     sf        = Helper.Conv.AlignToStringFormat(22);
                string  format    = row["format"].ToString();

                Rectangle rec = new Rectangle(l, t, colwidth, columnHeight);
                g.DrawString(colbyname, font, new SolidBrush(color), rec, sf);
                g.DrawRectangle(Pens.Black, rec);
                if (l >= Width)
                {
                    break;
                }
                l += colwidth;
            }
            //
            l = left;
            t = top + columnHeight;

            for (int i = 0; i < tbstyle.Rows.Count; i++)
            {
                DataRow dr = tbstyle.Rows[i];

                string     Field     = dr["colname"].ToString();
                string     colbyname = dr["colbyname"].ToString();
                int        colwidth  = Convert.ToInt16(dr["width"].ToString());
                int        align     = Convert.ToInt16(dr["align"].ToString());
                var        sf        = Helper.Conv.AlignToStringFormat(align);
                string     Format    = dr["format"].ToString();
                DataColumn col       = tbdetail.Columns[Field];
                foreach (DataRow row in tb.Rows)
                {
                    Rectangle rec     = new Rectangle(l, t, colwidth, columnHeight);
                    string    context = "";
                    if (Format == "")
                    {
                        context = row[Field].ToString();
                    }
                    else if (Format == "大写金额")
                    {
                        context = Helper.Conv.DaXie2(row[Field].ToString());
                    }
                    else
                    {
                        if (col.DataType == typeof(decimal))
                        {
                            context = Helper.Conv.ToDecimal(row[Field]).ToString(Format);
                        }
                        else if (col.DataType == typeof(Int16))
                        {
                            context = Helper.Conv.ToInt16(row[Field]).ToString(Format);
                        }
                        else if (col.DataType == typeof(Int32))
                        {
                            context = Helper.Conv.ToInt32(row[Field]).ToString(Format);
                        }
                        else if (col.DataType == typeof(DateTime))
                        {
                            context = Helper.Conv.ToDateTime(row[Field]).ToString(Format);
                        }
                        else
                        {
                            context = row[Field].ToString();
                        }
                    }

                    int sum = 0;
                    foreach (DataColumn c in tb.Columns)
                    {
                        if (row[c.ColumnName] == null || string.IsNullOrEmpty(row[c.ColumnName].ToString()))
                        {
                            sum++;
                        }
                    }

                    if (sum > tbdetail.Columns.Count / 2)
                    {
                        context = "";
                    }

                    g.DrawString(context, font, new SolidBrush(color), rec, sf);
                    g.DrawRectangle(Pens.Black, rec);
                    t += rowHeight;
                }
                if (l >= Width)
                {
                    break;
                }
                l += colwidth;
                t  = top + columnHeight;
            }
            //
        }
        protected override void Render(GH_Canvas canvas, System.Drawing.Graphics graphics, GH_CanvasChannel channel)
        {
            base.Render(canvas, graphics, channel);

            if (channel == GH_CanvasChannel.Objects)
            {
                //We need to draw everything outselves.

                Color myColour = UI.Colour.GsaDarkBlue;
                Brush myBrush  = new SolidBrush(myColour);

                //Text boxes
                Brush activeFillBrush  = myBrush;
                Brush passiveFillBrush = Brushes.LightGray;
                Color borderColour     = myColour;
                Color passiveBorder    = Color.DarkGray;
                Brush annoText         = Brushes.Black;

                Font font = GH_FontServer.Standard;
                int  s    = 8;
                if (Grasshopper.CentralSettings.CanvasFullNames)
                {
                    s    = 10;
                    font = GH_FontServer.Standard;
                }

                // adjust fontsize to high resolution displays
                font = new Font(font.FontFamily, font.Size / GH_GraphicsUtil.UiScale, FontStyle.Regular);

                //draw the component
                base.RenderComponentCapsule(canvas, graphics, true, true, true, true, true, true);

                Pen pen = new Pen(borderColour);

                graphics.DrawString(SpacerTxt1, GH_FontServer.Small, annoText, SpacerBounds1, GH_TextRenderingConstants.CenterCenter);
                graphics.DrawLine(pen, SpacerBounds1.X, SpacerBounds1.Y + SpacerBounds1.Height / 2, SpacerBounds1.X + (SpacerBounds1.Width - GH_FontServer.StringWidth(SpacerTxt1, GH_FontServer.Small)) / 2 - 4, SpacerBounds1.Y + SpacerBounds1.Height / 2);
                graphics.DrawLine(pen, SpacerBounds1.X + (SpacerBounds1.Width - GH_FontServer.StringWidth(SpacerTxt1, GH_FontServer.Small)) / 2 + GH_FontServer.StringWidth(SpacerTxt1, GH_FontServer.Small) + 4, SpacerBounds1.Y + SpacerBounds1.Height / 2, SpacerBounds1.X + SpacerBounds1.Width, SpacerBounds1.Y + SpacerBounds1.Height / 2);

                graphics.DrawString("x", font, annoText, xTxtBounds1, GH_TextRenderingConstants.CenterCenter);
                ButtonsUI.CheckBox.DrawCheckButton(graphics, new PointF(xBounds1.X + xBounds1.Width / 2, xBounds1.Y + xBounds1.Height / 2), x1, activeFillBrush, borderColour, passiveFillBrush, passiveBorder, s);

                graphics.DrawString("y", font, annoText, yTxtBounds1, GH_TextRenderingConstants.CenterCenter);
                ButtonsUI.CheckBox.DrawCheckButton(graphics, new PointF(yBounds1.X + yBounds1.Width / 2, yBounds1.Y + yBounds1.Height / 2), y1, activeFillBrush, borderColour, passiveFillBrush, passiveBorder, s);

                graphics.DrawString("z", font, annoText, zTxtBounds1, GH_TextRenderingConstants.CenterCenter);
                ButtonsUI.CheckBox.DrawCheckButton(graphics, new PointF(zBounds1.X + zBounds1.Width / 2, zBounds1.Y + zBounds1.Height / 2), z1, activeFillBrush, borderColour, passiveFillBrush, passiveBorder, s);

                graphics.DrawString("xx", font, annoText, xxTxtBounds1, GH_TextRenderingConstants.CenterCenter);
                ButtonsUI.CheckBox.DrawCheckButton(graphics, new PointF(xxBounds1.X + xxBounds1.Width / 2, xxBounds1.Y + xxBounds1.Height / 2), xx1, activeFillBrush, borderColour, passiveFillBrush, passiveBorder, s);

                graphics.DrawString("yy", font, annoText, yyTxtBounds1, GH_TextRenderingConstants.CenterCenter);
                ButtonsUI.CheckBox.DrawCheckButton(graphics, new PointF(yyBounds1.X + yyBounds1.Width / 2, yyBounds1.Y + yyBounds1.Height / 2), yy1, activeFillBrush, borderColour, passiveFillBrush, passiveBorder, s);

                graphics.DrawString("zz", font, annoText, zzTxtBounds1, GH_TextRenderingConstants.CenterCenter);
                ButtonsUI.CheckBox.DrawCheckButton(graphics, new PointF(zzBounds1.X + zzBounds1.Width / 2, zzBounds1.Y + zzBounds1.Height / 2), zz1, activeFillBrush, borderColour, passiveFillBrush, passiveBorder, s);

                graphics.DrawString(SpacerTxt2, GH_FontServer.Small, annoText, SpacerBounds2, GH_TextRenderingConstants.CenterCenter);
                graphics.DrawLine(pen, SpacerBounds2.X, SpacerBounds2.Y + SpacerBounds2.Height / 2, SpacerBounds2.X + (SpacerBounds2.Width - GH_FontServer.StringWidth(SpacerTxt2, GH_FontServer.Small)) / 2 - 4, SpacerBounds2.Y + SpacerBounds2.Height / 2);
                graphics.DrawLine(pen, SpacerBounds2.X + (SpacerBounds2.Width - GH_FontServer.StringWidth(SpacerTxt2, GH_FontServer.Small)) / 2 + GH_FontServer.StringWidth(SpacerTxt2, GH_FontServer.Small) + 4, SpacerBounds2.Y + SpacerBounds2.Height / 2, SpacerBounds2.X + SpacerBounds2.Width, SpacerBounds2.Y + SpacerBounds2.Height / 2);

                graphics.DrawString("x", font, annoText, xTxtBounds2, GH_TextRenderingConstants.CenterCenter);
                ButtonsUI.CheckBox.DrawCheckButton(graphics, new PointF(xBounds2.X + xBounds2.Width / 2, xBounds2.Y + xBounds2.Height / 2), x2, activeFillBrush, borderColour, passiveFillBrush, passiveBorder, s);

                graphics.DrawString("y", font, annoText, yTxtBounds2, GH_TextRenderingConstants.CenterCenter);
                ButtonsUI.CheckBox.DrawCheckButton(graphics, new PointF(yBounds2.X + yBounds2.Width / 2, yBounds2.Y + yBounds2.Height / 2), y2, activeFillBrush, borderColour, passiveFillBrush, passiveBorder, s);

                graphics.DrawString("z", font, annoText, zTxtBounds2, GH_TextRenderingConstants.CenterCenter);
                ButtonsUI.CheckBox.DrawCheckButton(graphics, new PointF(zBounds2.X + zBounds2.Width / 2, zBounds2.Y + zBounds2.Height / 2), z2, activeFillBrush, borderColour, passiveFillBrush, passiveBorder, s);

                graphics.DrawString("xx", font, annoText, xxTxtBounds2, GH_TextRenderingConstants.CenterCenter);
                ButtonsUI.CheckBox.DrawCheckButton(graphics, new PointF(xxBounds2.X + xxBounds2.Width / 2, xxBounds2.Y + xxBounds2.Height / 2), xx2, activeFillBrush, borderColour, passiveFillBrush, passiveBorder, s);

                graphics.DrawString("yy", font, annoText, yyTxtBounds2, GH_TextRenderingConstants.CenterCenter);
                ButtonsUI.CheckBox.DrawCheckButton(graphics, new PointF(yyBounds2.X + yyBounds2.Width / 2, yyBounds2.Y + yyBounds2.Height / 2), yy2, activeFillBrush, borderColour, passiveFillBrush, passiveBorder, s);

                graphics.DrawString("zz", font, annoText, zzTxtBounds2, GH_TextRenderingConstants.CenterCenter);
                ButtonsUI.CheckBox.DrawCheckButton(graphics, new PointF(zzBounds2.X + zzBounds2.Width / 2, zzBounds2.Y + zzBounds2.Height / 2), zz2, activeFillBrush, borderColour, passiveFillBrush, passiveBorder, s);
            }
        }
        protected virtual void DrawGlyph(System.Drawing.Graphics graphics, ButtonViewInfo viewInfo)
        {
            Brush brush = GetGlyphBrush(viewInfo);

            graphics.DrawString(viewInfo.Owner.Text, viewInfo.DefaultFont, brush, viewInfo.TextBounds);
        }
Beispiel #58
0
 protected void StageClearDraw(System.Drawing.Graphics g)
 {
     g.DrawString("STAGE CLEAR!", mFont, mSBWhite, 40, 40);
 }
Beispiel #59
0
        public override void draw(System.Drawing.Graphics gr, int x, int y)
        {
            bool draw_text;
            int  box_width;

            // determine whether or not to draw the text
            if ((this.scale <= .4) || (this.head_heightOrig < 10))
            {
                draw_text = false;
            }
            else
            {
                draw_text = Component.text_visible;
            }

            X = x;
            Y = y;

            height_of_text = Convert.ToInt32((gr.MeasureString(
                                                  "Yes", PensBrushes.default_times)).Height);

            width_of_text = Convert.ToInt32((gr.MeasureString(
                                                 this.Text + "XX", PensBrushes.default_times)).Width);

            gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            System.Drawing.Pen pen_color;
            if (this.selected)
            {
                pen_color = PensBrushes.red_pen;
            }
            else if (this.running)
            {
                pen_color = PensBrushes.chartreuse_pen;
            }
            else
            {
                pen_color = PensBrushes.blue_pen;
            }
            if (this.drawing_text_width > W)
            {
                box_width = this.drawing_text_width;
            }
            else
            {
                box_width = W;
            }
            if (this.has_breakpoint)
            {
                StopSign.Draw(gr, x - box_width / 2 - W / 6 - 2, y, W / 6);
            }

            // draw box if not USMA or not call
            if (this.kind != Kind_Of.Call || !Component.USMA_mode)
            {
                gr.DrawRectangle(pen_color, x - box_width / 2,
                                 y, box_width, H);
            }
            else
            {
                // top line
                gr.DrawLine(pen_color,
                            x - box_width / 2, y,
                            x + box_width / 2, y);
                // left line
                gr.DrawLine(pen_color,
                            x - box_width / 2, y,
                            x - box_width / 2, y + 3 * H / 4);
                // right line
                gr.DrawLine(pen_color,
                            x + box_width / 2, y,
                            x + box_width / 2, y + 3 * H / 4);
                // left bottom
                gr.DrawLine(pen_color,
                            x - box_width / 2, y + 3 * H / 4,
                            x, y + H);
                // right bottom
                gr.DrawLine(pen_color,
                            x, y + H,
                            x + box_width / 2, y + 3 * H / 4);
            }

            if (this.kind == Kind_Of.Call && !Component.USMA_mode)
            {
                gr.DrawLine(pen_color,
                            x + box_width / 2, y + 5 * H / 12,
                            x + box_width / 2 + W / 8, y + 5 * H / 12);
                gr.DrawLine(pen_color,
                            x + box_width / 2 + W / 8, y + 5 * H / 12,
                            x + box_width / 2 + W / 8, y + H / 4);
                gr.DrawLine(pen_color,
                            x + box_width / 2 + W / 8, y + H / 4,
                            x + box_width / 2 + 2 * W / 8, y + H / 2);
                gr.DrawLine(pen_color,
                            x + box_width / 2, y + 7 * H / 12,
                            x + box_width / 2 + W / 8, y + 7 * H / 12);
                gr.DrawLine(pen_color,
                            x + box_width / 2 + W / 8, y + 7 * H / 12,
                            x + box_width / 2 + W / 8, y + 3 * H / 4);
                gr.DrawLine(pen_color,
                            x + box_width / 2 + W / 8, y + 3 * H / 4,
                            x + box_width / 2 + 2 * W / 8, y + H / 2);
            }


            if ((draw_text) && (this.Text.Length > 0))
            {
                if (Component.full_text)
                {
                    // we get rect from footprint
                    if (drawing_text_width > W)
                    {
                        rect = new System.Drawing.Rectangle(x - drawing_text_width / 2, Y + (H * 1) / 32, drawing_text_width, this.height_of_text * 3);
                    }
                    else
                    {
                        rect = new System.Drawing.Rectangle(x - this.width_of_text / 2, Y + (H * 6) / 16, this.width_of_text, this.height_of_text);
                    }
                }
                else
                {
                    rect = new System.Drawing.Rectangle(x - W / 2, Y + (H * 6) / 16, W, this.height_of_text);
                }

                if (this.Text == "Error")
                {
                    gr.DrawString(this.Text, PensBrushes.default_times, PensBrushes.redbrush, rect, PensBrushes.centered_stringFormat);
                }
                else
                {
                    gr.DrawString(this.getDrawText(),
                                  PensBrushes.default_times,
                                  PensBrushes.blackbrush,
                                  rect, PensBrushes.centered_stringFormat);
                }
            }

            if (this.Successor != null)
            {
                // color for connector line
                System.Drawing.Pen pen;

                if (this.selected)
                {
                    pen = PensBrushes.red_pen;
                }
                else
                {
                    pen = PensBrushes.blue_pen;
                }
                gr.DrawLine(pen, x, y + H, x, y + H + CL);                        // draw connector line to successor
                gr.DrawLine(pen, x, y + H + CL, x - CL / 4, y + H + CL - CL / 4); // draw left side of arrow
                gr.DrawLine(pen, x, y + H + CL, x + CL / 4, y + H + CL - CL / 4); // draw right side of arrow

                Successor.scale = this.scale;
                Successor.draw(gr, x, y + H + CL);
            }

            if (draw_text)
            {
                base.draw(gr, x, y);
            }
        }
 public static void RepertoryImage(Graphics drawDestination, ItemPos position)
 {
     StringFormat itemStringFormat = new StringFormat();
     if (position == ItemPos.Left){
         drawDestination.DrawLine(Pens.DarkGray,70,10,70,70);
         RectangleF itemBox = new RectangleF(15, 12, 60, 14);
         itemStringFormat.Alignment = StringAlignment.Near;
         itemStringFormat.LineAlignment = StringAlignment.Near;
         drawDestination.DrawLine(Pens.Black,15,30,70,30);
         drawDestination.DrawLine(Pens.Black,11,26,19,34);
         drawDestination.DrawLine(Pens.Black,11,34,19,26);
         drawDestination.DrawString("StopTimer",new Font("Arial",8),Brushes.Black,itemBox,itemStringFormat);
     }
     else if (position == ItemPos.Right){
         drawDestination.DrawLine(Pens.DarkGray,10,10,10,70);
         RectangleF itemBox = new RectangleF(11, 12, 60, 14);
         itemStringFormat.Alignment = StringAlignment.Near;
         itemStringFormat.LineAlignment = StringAlignment.Near;
         drawDestination.DrawLine(Pens.Black,10,30,65,30);
         drawDestination.DrawLine(Pens.Black,61,26,69,34);
         drawDestination.DrawLine(Pens.Black,61,34,69,26);
         drawDestination.DrawString("StopTimer",new Font("Arial",8),Brushes.Black,itemBox,itemStringFormat);
     }
     itemStringFormat.Dispose();
 }