"Bob Powell [MVP]" wrote:
> The clip rectangle reports the amount of screen area that needs to be
> updated. If you scroll the window to the left then it exposes an area to the
> right of the window that needs to be refreshed.
>
> The code below my signature shows how such a scheme might be created.
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Ramuseco Limited .NET consulting
>
http://www.ramuseco.com >
> Find great Windows Forms articles in Windows Forms Tips and Tricks
>
http://www.bobpowell.net/tipstricks.htm >
> Answer those GDI+ questions with the GDI+ FAQ
>
http://www.bobpowell.net/faqmain.htm >
> All new articles provide code in C# and VB.NET.
> Subscribe to the RSS feeds provided and never miss a new article.
>
> ---------------------------------------------------------------------
> using System;
> using System.Drawing;
> using System.Drawing.Drawing2D;
> using System.Collections;
> using System.ComponentModel;
> using System.Windows.Forms;
> using System.Data;
>
> namespace cliprectangles
> {
> /// <summary>
> /// Summary description for Form1.
> /// </summary>
> public class Form1 : System.Windows.Forms.Form
> {
>
> ArrayList ar=new ArrayList();
>
> /// <summary>
> /// Required designer variable.
> /// </summary>
> private System.ComponentModel.Container components = null;
>
> public Form1()
> {
> //
> // Required for Windows Form Designer support
> //
> InitializeComponent();
>
> //
> // TODO: Add any constructor code after InitializeComponent call
> //
> Random r=new Random();
> for(int x=0;x<1024;x+=10)
> {
> ColorRect cr=new ColorRect();
> cr.Rect=new Rectangle(x,(int)(x*0.66f),10,7);
> cr.Color=Color.FromArgb(r.Next(255),r.Next(255),r.Next(255));
> ar.Add(cr);
> }
> }
>
> /// <summary>
> /// Clean up any resources being used.
> /// </summary>
> protected override void Dispose( bool disposing )
> {
> if( disposing )
> {
> if (components != null)
> {
> components.Dispose();
> }
> }
> base.Dispose( disposing );
> }
>
> #region Windows Form Designer generated code
> /// <summary>
> /// Required method for Designer support - do not modify
> /// the contents of this method with the code editor.
> /// </summary>
> private void InitializeComponent()
> {
> //
> // Form1
> //
> this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
> this.AutoScroll = true;
> this.AutoScrollMinSize = new System.Drawing.Size(1024, 768);
> this.ClientSize = new System.Drawing.Size(275, 249);
> this.Name = "Form1";
> this.Text = "Form1";
> this.Paint += new
> System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
>
> }
> #endregion
>
> /// <summary>
> /// The main entry point for the application.
> /// </summary>
> [STAThread]
> static void Main()
> {
> Application.Run(new Form1());
> }
>
> private void Form1_Paint(object sender,
> System.Windows.Forms.PaintEventArgs e)
> {
> //transform the drawing output according to the scroll positions
> Matrix mx=new
> Matrix(1,0,0,1,this.AutoScrollPosition.X,this.AutoScrollPosition.Y);
> e.Graphics.Transform=mx;
>
> //adjust the clip rectangle...
> //note the use of the inverse of the scrollposition
> Rectangle clip=e.ClipRectangle;
> clip.Offset(-this.AutoScrollPosition.X,-this.AutoScrollPosition.Y);
> int rectCount=0;
> foreach(ColorRect cr in this.ar)
> {
> if(cr.Rect.IntersectsWith(clip))
> {
> cr.Draw(e.Graphics);
> rectCount++;
> }
> }
> System.Diagnostics.Trace.WriteLine(string.Format("This pass drew {0}
> rectangles.",rectCount));
> }
> }
>
> public class ColorRect
> {
> Rectangle _rect;
> public Rectangle Rect
> {
> get{return _rect;}
> set{_rect=value;}
> }
>
> Color _color;
> public Color Color
> {
> get{return _color;}
> set{_color=value;}
> }
>
> public void Draw(Graphics g)
> {
> SolidBrush sb=new SolidBrush(this._color);
> g.FillRectangle(sb,_rect);
> sb.Dispose();
> }
> }
> }
>
> ---------------------------------------------------------------------
>
>
>
> "Andrew" <Andrew@discussions.microsoft.com> wrote in message
> news:D84FC897-0CB6-41FC-8612-DC59322EA898@microsoft.com...
> > Hello ,
> >
> > Does anyone have a comment regarding the cliprectangle values upon the
> > form
> > scrolling ?
> >
> >
> >
> > "Andrew" wrote:
> >
> >> Bob,
> >>
> >> Yes the screen resolution is 1024 * 768.
> >>
> >> Because I have a properties panel to the right and another panel situated
> >> below my form, the view/form's client rectangle is {0,0,842,426}.
> >>
> >> With no scroll the clip rectangle is the same as the client rectangle.
> >>
> >> The building rectangle is initially displayed in the buildingview with no
> >> scrolling required. When I increase the building length, scroll margins
> >> are
> >> generated in the horizontal direction and upon scrolling I should be
> >> able to
> >> see the right edge of the building rectangle. However what happens is
> >> that
> >> upon scrolling, nothing appears to the right of the existing rectangle
> >> shape.
> >>
> >> I observe from the debug screen that just as the scroll commences (eg
> >> scroll
> >> point is -1,0) that the clip rectangle jumps to {840,0,1,426} which puts
> >> it
> >> right at the extremity of the display rectangle!
> >>
> >> No given graphical shape is going to pass a intersectwith/contains test
> >> with
> >> such a clip rectangle, hence it won't be drawn.
> >>
> >> As per your advice, I am now translating the location of the clip
> >> rectangle
> >> in accordance with the scroll position - thanks. The main point is the
> >> concern regarding the values in the cliprectangle as soon as scrolling
> >> begins.
> >>
> >> Prior to introducing the clip rectangle test , the graphical objects
> >> would
> >> draw correctly upon scrolling using the transformed graphics object ie
> >>
> >> In the view forms's base class, I would take the graphics object that was
> >> provided to the base classes OnPaint handler and transform it by the
> >> amount
> >> of the scrollposition ie
> >> Graphics g = e.Graphics
> >> Point pt = this.AutoScrollPosition;
> >> g.TranslateTransform(pt.X,pt.Y);
> >>
> >> in the derived form/view I then draw the object ie
> >>
> >> g.DrawRectangle(object)
> >>
> >> Now, in the base classes OnPaint handler I have introduced an offset to
> >> the