AutoScrollPosition : Form Frame Window « GUI Windows Form « C# / C Sharp






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());
    }
}

 








Related examples in the same category

1.Print out Form size and position related information
2.Use Font from Form to paint string on a form
3.Set ResizeRedraw property
4.Set ClientSize to change the form window size
5.FormStartPosition.CenterScreen
6.Form hideForm hide
7.Change Form window ownershipChange Form window ownership
8.Create Graphics Object from form window handleCreate Graphics Object from form window handle
9.Center form windowCenter form window
10.Assign Form window default valueAssign Form window default value
11.Change the background and text colors of a form using Color DialogChange the background and text colors of a form using Color Dialog
12.Draw image based on the window sizeDraw image based on the window size
13.Auto scroll form windowAuto scroll form window
14.Set Form window title and center the Form window on the desktopSet Form window title and center the Form window on the desktop
15.Add control to a form windowAdd control to a form window
16.Change Form window backgroundChange Form window background
17.Simplest form code: set window titleSimplest form code: set window title
18.Login fromLogin from
19.makes a new window out of a graphics path that has been traced on this forms spacemakes a new window out of a graphics path that has been traced on this forms space
20.Windows Forms Getting StartedWindows Forms Getting Started
21.A form-based Windows SkeletonA form-based Windows Skeleton
22.Simple formSimple form
23.Add controls to a formAdd controls to a form
24.Form for data inputForm for data input
25.Demonstrates creating a form in a console programDemonstrates creating a form in a console program