System.Drawing.Rectangle.Offset C# (CSharp) Method

Offset() public method

Adjusts the location of this rectangle by the specified amount.

public Offset ( Point pos ) : void
pos Point
return void
        public void Offset(Point pos) => Offset(pos.X, pos.Y);

Same methods

Rectangle::Offset ( System pos ) : void
Rectangle::Offset ( int x, int y ) : void

Usage Example

Example #1
0
		private void PenAlignment_Paint(object sender, PaintEventArgs e)
		{
			// Example of border problem.
			//Rectangle rect = new Rectangle(10, 10, 110, 110);
			//Pen pen = new Pen(Color.Red, 1);
			//Brush brush = Brushes.LightBlue;
			//e.Graphics.DrawRectangle(pen, rect);
			//e.Graphics.FillRectangle(brush, rect);

			
			Rectangle rect = new Rectangle(10, 10, 110, 110);
			Pen pen = new Pen(Color.White, 11);
			Pen penOutline = new Pen(Color.Black, 1);
			penOutline.Alignment = PenAlignment.Inset;
			pen.Alignment = PenAlignment.Center;
			e.Graphics.DrawString("11-Pixel Centered Pen", SystemFonts.DefaultFont, Brushes.Black, rect.Location);
			rect.Offset(0, 25);
			e.Graphics.FillRectangle(Brushes.LightBlue, rect);
			e.Graphics.DrawRectangle(pen, rect);
			e.Graphics.DrawRectangle(penOutline, rect);
			
			rect.Offset(150, -25);
			e.Graphics.DrawString("11-Pixel Inset Pen", SystemFonts.DefaultFont, Brushes.Black, rect.Location);
			rect.Offset(0, 25);
			pen.Alignment = PenAlignment.Inset;
			e.Graphics.FillRectangle(Brushes.LightBlue, rect);
			e.Graphics.DrawRectangle(pen, rect);
			e.Graphics.DrawRectangle(penOutline, rect);
			
			
			pen.Dispose();
		}
All Usage Examples Of System.Drawing.Rectangle::Offset