Mega Code Archive

 
Categories / C# / GUI Windows Form
 

AutoScrollPosition

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Drawing.Drawing2D; public class Form1 : Form {     private Rectangle rectangleBounds = new Rectangle(new Point(0, 0), new Size(200, 200));     private Rectangle ellipseBounds = new Rectangle(new Point(50, 200), new Size(200, 150));     private Pen bluePen = new Pen(Color.Blue, 3);     private Pen redPen = new Pen(Color.Red, 2);     private Brush solidAzureBrush = Brushes.Azure;     private Brush solidYellowBrush = new SolidBrush(Color.Yellow);     static private Brush brickBrush = new HatchBrush(HatchStyle.DiagonalBrick,Color.DarkGoldenrod, Color.Cyan);     private Pen brickWidePen = new Pen(brickBrush, 10);     public Form1() {     }     protected override void OnPaint(PaintEventArgs e) {         base.OnPaint(e);         Graphics dc = e.Graphics;         Point scrollOffset = this.AutoScrollPosition;         dc.TranslateTransform(scrollOffset.X, scrollOffset.Y);         if (e.ClipRectangle.Top + scrollOffset.X < 350 ||             e.ClipRectangle.Left + scrollOffset.Y < 250) {             dc.DrawRectangle(bluePen, rectangleBounds);             dc.FillRectangle(solidYellowBrush, rectangleBounds);             dc.DrawEllipse(redPen, ellipseBounds);             dc.FillEllipse(solidAzureBrush, ellipseBounds);             dc.DrawLine(brickWidePen, rectangleBounds.Location,ellipseBounds.Location + ellipseBounds.Size);         }     }     public static void Main() {         Application.Run(new Form1());     } }