当前位置: 首页>>代码示例>>C#>>正文


C# Rectangle类代码示例

本文整理汇总了C#中Rectangle的典型用法代码示例。如果您正苦于以下问题:C# Rectangle类的具体用法?C# Rectangle怎么用?C# Rectangle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Rectangle类属于命名空间,在下文中一共展示了Rectangle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawRectangle

 /// <summary>Draws the given rectangle.</summary>
 /// <param name="r">The rectangle to draw.</param>
 /// <param name="col">The color to draw the rectangle in.</param>
 /// <param name="bw">The border width to draw the rectangle with. (shadow to botom-right)</param>
 public static void DrawRectangle(Rectangle r, SpriteBatch spriteBatch, Color col, int bw = 2)
 {
     spriteBatch.Draw(pixel, new Rectangle(r.Left, r.Top, bw, r.Height), col); // Left
     spriteBatch.Draw(pixel, new Rectangle(r.Right, r.Top, bw, r.Height), col); // Right
     spriteBatch.Draw(pixel, new Rectangle(r.Left, r.Top, r.Width, bw), col); // Top
     spriteBatch.Draw(pixel, new Rectangle(r.Left, r.Bottom, r.Width, bw), col); // Bottom
 }
开发者ID:alikimoko,项目名称:Practicum3.Platformer,代码行数:11,代码来源:DrawingHelper.cs

示例2: Main

	public static void Main(string[] args)
	{	
		Graphics.DrawImageAbort imageCallback;
		Bitmap outbmp = new Bitmap (300, 300);				
		Bitmap bmp = new Bitmap("../../Test/System.Drawing/bitmaps/almogaver24bits.bmp");
		Graphics dc = Graphics.FromImage (outbmp);        
		
		ImageAttributes imageAttr = new ImageAttributes();
		
		/* Simple image drawing */		
		dc.DrawImage(bmp, 0,0);				
				
		/* Drawing using points */
		PointF ulCorner = new PointF(150.0F, 0.0F);
		PointF urCorner = new PointF(350.0F, 0.0F);
		PointF llCorner = new PointF(200.0F, 150.0F);
		RectangleF srcRect = new Rectangle (0,0,100,100);		
		PointF[] destPara = {ulCorner, urCorner, llCorner};	
		imageCallback =  new Graphics.DrawImageAbort(DrawImageCallback);		
		dc.DrawImage (bmp, destPara, srcRect, GraphicsUnit.Pixel, imageAttr, imageCallback);
	
		/* Using rectangles */	
		RectangleF destRect = new Rectangle (10,200,100,100);
		RectangleF srcRect2 = new Rectangle (50,50,100,100);		
		dc.DrawImage (bmp, destRect, srcRect2, GraphicsUnit.Pixel);		
		
		/* Simple image drawing with with scaling*/		
		dc.DrawImage(bmp, 200,200, 75, 75);				
		
		outbmp.Save("drawimage.bmp", ImageFormat.Bmp);				
		
	}
开发者ID:nlhepler,项目名称:mono,代码行数:32,代码来源:drawimage.cs

示例3: Render

        public override void Render(Sprite sprite)
        {
            Rectangle rect = new Rectangle(0, 0, 1280, 720);
            if (currentFrame >= frames.Length)
            {
                if (delay > 1.25f)
                {
                    sprite.Draw(frames[frames.Length - 1], rect, ColorValue.White);
                    ColorValue color = ColorValue.White;
                    color.A = (byte)(byte.MaxValue * (1 - MathEx.Saturate((delay - 1.25f) / 1.25f)));
                    sprite.Draw(blackBg, rect, color);
                }
                else
                {
                    ColorValue color = ColorValue.White;
                    color.A = (byte)(byte.MaxValue * MathEx.Saturate(delay / 1.25f));
                    sprite.Draw(blackBg, rect, color);
                }


                delay -= 0.04f;
            }
            else
            {
                sprite.Draw(frames[currentFrame], rect, ColorValue.White);
            }
        }
开发者ID:yuri410,项目名称:lrvbsvnicg,代码行数:27,代码来源:Intro.cs

示例4: RectangleImpl

 public RectangleImpl(Rectangle r)
 {
     minX = r.GetMinX();
     maxX = r.GetMaxX();
     minY = r.GetMinY();
     maxY = r.GetMaxY();
 }
开发者ID:ccurrens,项目名称:Spatial4n,代码行数:7,代码来源:RectangleImpl.cs

示例5: Paint

        protected override void Paint(Graphics g, Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
            DataGridViewElementStates cellState, object value, object formattedValue,
            string errorText, DataGridViewCellStyle cellStyle,
            DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            int progressVal = 0;
              if (value != null)
            progressVal = (int)value;

              float percentage = (progressVal / 100.0f);
            // Need to convert to float before division; otherwise C# returns int which is 0 for anything but 100%.
              Brush backColorBrush = new SolidBrush(cellStyle.BackColor);
              Brush foreColorBrush = new SolidBrush(cellStyle.ForeColor);
              // Draws the cell grid
              base.Paint(g, clipBounds, cellBounds,
                 rowIndex, cellState, value, formattedValue, errorText,
                 cellStyle, advancedBorderStyle, (paintParts & ~DataGridViewPaintParts.ContentForeground));
              if (percentage > 0.0)
              {
            // Draw the progress bar and the text
            g.FillRectangle(new SolidBrush(Color.FromArgb(163, 189, 242)), cellBounds.X + 2, cellBounds.Y + 2,
                        Convert.ToInt32((percentage * cellBounds.Width - 4)), cellBounds.Height - 4);
            g.DrawString(progressVal + "%", cellStyle.Font, foreColorBrush, cellBounds.X + 6, cellBounds.Y + 2);
              }
              else
              {
            // draw the text
            if (DataGridView.CurrentRow.Index == rowIndex)
              g.DrawString(progressVal + "%", cellStyle.Font, new SolidBrush(cellStyle.SelectionForeColor), cellBounds.X + 6,
                       cellBounds.Y + 2);
            else
              g.DrawString(progressVal + "%", cellStyle.Font, foreColorBrush, cellBounds.X + 6, cellBounds.Y + 2);
              }
        }
开发者ID:sanyaade-embedded-systems,项目名称:MPTagThat,代码行数:34,代码来源:DataGridViewProgressColumn.cs

示例6: DrawText

        public override void DrawText(char[] buffer, Rectangle logicalTextBox, int textAlignment)
        {


            var clipRect = System.Drawing.Rectangle.Intersect(logicalTextBox.ToRect(), currentClipRect);
            //1.
            clipRect.Offset(canvasOriginX, canvasOriginY);
            //2.
            win32MemDc.SetClipRect(clipRect.Left, clipRect.Top, clipRect.Width, clipRect.Height);
            //3.
            NativeTextWin32.TextOut(win32MemDc.DC, CanvasOrgX + logicalTextBox.X, CanvasOrgY + logicalTextBox.Y, buffer, buffer.Length);
            //4.
            win32MemDc.ClearClipRect();

            //ReleaseHdc();
            //IntPtr gxdc = gx.GetHdc();
            //MyWin32.SetViewportOrgEx(gxdc, CanvasOrgX, CanvasOrgY, IntPtr.Zero);
            //System.Drawing.Rectangle clipRect =
            //    System.Drawing.Rectangle.Intersect(logicalTextBox.ToRect(), currentClipRect);
            //clipRect.Offset(CanvasOrgX, CanvasOrgY);
            //MyWin32.SetRectRgn(hRgn, clipRect.X, clipRect.Y, clipRect.Right, clipRect.Bottom);
            //MyWin32.SelectClipRgn(gxdc, hRgn);
            //NativeTextWin32.TextOut(gxdc, logicalTextBox.X, logicalTextBox.Y, buffer, buffer.Length); 
            //MyWin32.SelectClipRgn(gxdc, IntPtr.Zero); 
            //MyWin32.SetViewportOrgEx(gxdc, -CanvasOrgX, -CanvasOrgY, IntPtr.Zero); 
            //gx.ReleaseHdc();

        }
开发者ID:prepare,项目名称:HTML-Renderer,代码行数:28,代码来源:4_MyGdiPlusCanvas_TextAndFonts.cs

示例7: Table

    /**
     * Create a new Table of the given number of rows and columns
     *
     * @param numrows the number of rows
     * @param numcols the number of columns
     */
    public Table(int numrows, int numcols) {
        base();

        if(numrows < 1) throw new ArgumentException("The number of rows must be greater than 1");
        if(numcols < 1) throw new ArgumentException("The number of columns must be greater than 1");

        int x=0, y=0, tblWidth=0, tblHeight=0;
        cells = new TableCell[numrows][numcols];
        for (int i = 0; i < cells.Length; i++) {
            x = 0;
            for (int j = 0; j < cells[i].Length; j++) {
                cells[i][j] = new TableCell(this);
                Rectangle anchor = new Rectangle(x, y, TableCell.DEFAULT_WIDTH, TableCell.DEFAULT_HEIGHT);
                cells[i][j].SetAnchor(anchor);
                x += TableCell.DEFAULT_WIDTH;
            }
            y += TableCell.DEFAULT_HEIGHT;
        }
        tblWidth = x;
        tblHeight = y;
        SetAnchor(new Rectangle(0, 0, tblWidth, tblHeight));

        EscherContainerRecord spCont = (EscherContainerRecord) GetSpContainer().GetChild(0);
        EscherOptRecord opt = new EscherOptRecord();
        opt.SetRecordId((short)0xF122);
        opt.AddEscherProperty(new EscherSimpleProperty((short)0x39F, 1));
        EscherArrayProperty p = new EscherArrayProperty((short)0x43A0, false, null);
        p.SetSizeOfElements(0x0004);
        p.SetNumberOfElementsInArray(numrows);
        p.SetNumberOfElementsInMemory(numrows);
        opt.AddEscherProperty(p);
        List<EscherRecord> lst = spCont.GetChildRecords();
        lst.Add(lst.Count-1, opt);
        spCont.SetChildRecords(lst);
    }
开发者ID:hanwangkun,项目名称:npoi,代码行数:41,代码来源:Table.cs

示例8: clickInit

        private Rectangle boxBlank ;    // 空き位置

        /// <summary>
        /// 初期化ボタン
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void clickInit(object sender, EventArgs e)
        {
            var cols = new List<Color>()
            {
                Color.Red,
                Color.Navy,
                Color.Yellow,
                Color.Pink,
                Color.Purple,
            };
            var rnd = new Random();

            // キャンバスに Box を25個並べる
            boxes = new List<BoxViewEx>();
            for (int i = 0; i < 25; i++) {
                var box = new BoxViewEx();
                boxes.Add(box);
                canvas.Children.Add(box);
                int w = 60;
                int h = 60;

                int x = (i % 5) * (w + 10) + 30;
                int y = (i / 5) * (h + 10) + 30;

                var rect = new Rectangle(new Point(x, y), new Size(w, h));
                box.LayoutTo(rect);
                box.BackgroundColor = cols[ rnd.Next(cols.Count)];
                box.ManipulationDelta += Box_ManipulationDelta;
                box.ManipulationCompleted += Box_ManipulationCompleted;
                box.ManipulationStarted += Box_ManipulationStarted;
            }
        }
开发者ID:moonmile,项目名称:PazzleDrag,代码行数:39,代码来源:MainPage.xaml.cs

示例9: NPCSpawner

        /// <summary>
        /// Initializes a new instance of the <see cref="NPCSpawner"/> class.
        /// </summary>
        /// <param name="mapSpawnValues">The MapSpawnValues containing the values to use to create this NPCSpawner.</param>
        /// <param name="map">The Map instance to do the spawning on. The <see cref="MapID"/> of this Map must be equal to the
        /// <see cref="MapID"/> of the <paramref name="mapSpawnValues"/>.</param>
        /// <exception cref="ArgumentException">The <paramref name="map"/>'s <see cref="MapID"/> does not match the
        /// <paramref name="mapSpawnValues"/>'s <see cref="MapID"/>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="map" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="mapSpawnValues" /> is <c>null</c>.</exception>
        public NPCSpawner(IMapSpawnTable mapSpawnValues, Map map)
        {
            if (map == null)
                throw new ArgumentNullException("map");
            if (mapSpawnValues == null)
                throw new ArgumentNullException("mapSpawnValues");

            if (map.ID != mapSpawnValues.MapID)
                throw new ArgumentException("The map's MapID and mapSpawnValues's MapID do not match.", "map");

            _map = map;
            _characterTemplate = _characterTemplateManager[mapSpawnValues.CharacterTemplateID];
            _characterTemplateBody = BodyInfoManager.Instance.GetBody(_characterTemplate.TemplateTable.BodyID);
            _amount = mapSpawnValues.Amount;
            _area = new MapSpawnRect(mapSpawnValues).ToRectangle(map);
            _spawnDirection = mapSpawnValues.DirectionId;
            _respawn = mapSpawnValues.Respawn;

            if (_characterTemplate == null)
            {
                const string errmsg = "Failed to find the CharacterTemplate for CharacterTemplateID `{0}`.";
                var err = string.Format(errmsg, mapSpawnValues.CharacterTemplateID);
                if (log.IsFatalEnabled)
                    log.Fatal(err);
                Debug.Fail(err);
                throw new ArgumentException(err);
            }

            SpawnNPCs();
        }
开发者ID:mateuscezar,项目名称:netgore,代码行数:40,代码来源:NPCSpawner.cs

示例10: OnPaint

    void OnPaint(object sender, PaintEventArgs e)
    {
        Graphics g = e.Graphics;

          Rectangle r = new Rectangle(1, 1, castle.Width, castle.Height);
          g.DrawImage(castle, r);
    }
开发者ID:sciruela,项目名称:MonoWinformsTutorial,代码行数:7,代码来源:redrock.cs

示例11: CollisionCheck

    /// <summary>
    /// Checks whether or not the given ball is colliding with this paddle.
    /// </summary>
    /// <param name="b"></param>
    /// <returns></returns>
    public bool CollisionCheck(Ball b)
    {
        Rectangle recBall = new Rectangle((int)b.position.X - b.texture.Width / 2, (int)b.position.Y - b.texture.Height / 2, b.texture.Width, b.texture.Height);
        Rectangle recPaddle = new Rectangle((int)this.position.X - this.texture.Width / 2, (int)this.position.Y - this.texture.Height / 2, this.texture.Width, this.texture.Height);

        return !(Rectangle.Empty == Rectangle.Intersect(recBall, recPaddle));
    }
开发者ID:JonneDeurloo,项目名称:ParticleWorkshop,代码行数:12,代码来源:Paddle.cs

示例12: OnSizeAllocated

		protected override void OnSizeAllocated (double width, double height)
		{
			base.OnSizeAllocated (width, height);

			if (width != -1) {

				Device.BeginInvokeOnMainThread (() => {

					//Adjust height of pintile so it is equal to the width
					var tileLayout = new Rectangle (Bounds.X, Bounds.Y, Bounds.Width, width);
					this.Layout (tileLayout);

					this.ParentView.Layout (new Rectangle (ParentView.Bounds.X, ParentView.Bounds.Y, ParentView.Bounds.Width, width));

					//Ugly bug fix for iOS to get text centered vertically in label - needed in Xamarin.Forms 1.4.0.6341
					int yPositionLabel = 0;

					if (DeviceTypeHelper.IsIos) {
						if(Bounds.Height <= 65){
							yPositionLabel = 11;
						}
						else{
							yPositionLabel = 14;
						}
					}
					else if (DeviceTypeHelper.IsAndroid) {
						if(Bounds.Height > 55 && Bounds.Height < 70){
							yPositionLabel = 5;
						}
					}

					_labelPin.Layout (new Rectangle (_labelPin.X, yPositionLabel, Bounds.Width, Bounds.Height));
				});
			}
		}
开发者ID:RoyStobbelaar,项目名称:MedewerkerTemp,代码行数:35,代码来源:PinTile.cs

示例13: Button

 /// <summary>
 /// Initializes a new instance of the <see cref="Button"/> class.
 /// </summary>
 /// <param name='bounds'>
 /// Bounds.
 /// </param>
 /// <param name='content'>
 /// Content.
 /// </param>
 /// <param name='style'>
 /// Style.
 /// </param>
 public Button(Rectangle bounds, GUIContent content, GUISkin skin)
     : this()
 {
     this.Bounds = bounds;
     this.Content = content;
     this.Skin = skin;
 }
开发者ID:miguelmartin75,项目名称:Survival,代码行数:19,代码来源:Button.cs

示例14: QuadPrefixTree

 public QuadPrefixTree(SpatialContext ctx, Rectangle bounds, int maxLevels)
     : base(ctx, maxLevels)
 {
     //not really sure how big this should be
     // side
     // number
     xmin = bounds.GetMinX();
     xmax = bounds.GetMaxX();
     ymin = bounds.GetMinY();
     ymax = bounds.GetMaxY();
     levelW = new double[maxLevels];
     levelH = new double[maxLevels];
     levelS = new int[maxLevels];
     levelN = new int[maxLevels];
     gridW = xmax - xmin;
     gridH = ymax - ymin;
     xmid = xmin + gridW / 2.0;
     ymid = ymin + gridH / 2.0;
     levelW[0] = gridW / 2.0;
     levelH[0] = gridH / 2.0;
     levelS[0] = 2;
     levelN[0] = 4;
     for (int i = 1; i < levelW.Length; i++)
     {
         levelW[i] = levelW[i - 1] / 2.0;
         levelH[i] = levelH[i - 1] / 2.0;
         levelS[i] = levelS[i - 1] * 2;
         levelN[i] = levelN[i - 1] * 4;
     }
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:30,代码来源:QuadPrefixTree.cs

示例15: Main

        static void Main(string[] args)
        {
            // declare and initialize two int arrays with coordinates of 2 points
            int[] coords1 = { 2, 5 };
            int[] coords2 = { 4, 3 };

            // declare and initialize 2 points
            Point point1 = new Point(coords1);
            Point point2 = new Point(coords2);

            // declare and initialize an array with the 2 points
            Point[] points = { point1, point2 };

            // declare and initialize a rectangle
            Rectangle rectangle = new Rectangle(points);
            
            // show rectangle coordinates
            Console.WriteLine(rectangle);

            // show rectangle`s perimeter
            Console.WriteLine(rectangle.Perimeter());

            // show area of the circle around the rectangle
            Console.WriteLine(rectangle.Circle());
        }
开发者ID:arr13,项目名称:OOP-CSharp.NET,代码行数:25,代码来源:Program2.cs


注:本文中的Rectangle类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。