Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to create tiles grid background in gdi+ where i can draw shapes or do other stuff on it..it would be my application 's surface design and and use scrolling feature ??????? As I am new to GDI+ so kindly gives some guideline

i have have created this function now i want to set this design as background screen
C#
private void DrawCaroBoard(Graphics graphics, int row, int col, int width)
        {
            //Draw background
            var linearBrush = new LinearGradientBrush(new Rectangle(_startPoint.X, _startPoint.Y, col * width, row * width), Color.Turquoise,
                Color.White, LinearGradientMode.BackwardDiagonal);
            graphics.FillRectangle(linearBrush, _startPoint.X, _startPoint.Y, col * width, row * width);

            //Draw rows
            for (var i = 0; i <= row; i++)
            {
                graphics.DrawLine(new Pen(Brushes.DarkTurquoise, 2), _startPoint.X, _startPoint.Y + i * width, _startPoint.X + col * width, _startPoint.Y + i * width);
            }

            //Draw columns
            for (var j = 0; j <= col; j++)
            {
                graphics.DrawLine(new Pen(Brushes.DarkTurquoise, 2), _startPoint.X + j * width, _startPoint.Y, _startPoint.X + j * width, _startPoint.Y + row * width);
            }
        }

now how to use this function in my form to its background ???
Posted
Updated 30-Sep-12 10:42am
v3

1 solution

For a form graphics rendering, override the method OnPaint and call your rendering method in it:
C#
protected void OnPaint(PaintEventArgs e) {
   int row = // ???
   int column = // ???
   int width = // I have no idea how you calculate those, but this is something 
               // depending on the state of the form -- you should know better
   DrawCaroBoard(e.Graphics, row, column, width);
}

Please see http://msdn.microsoft.com/en-us/library/3e40ahaz.aspx[^].

Now, scrolling. Pay attention that the class System.Windows.Forms.Form is derived from the class System.Windows.Forms.ScrollableControl, so scrolling is already created for you. As Panel also inherits the properties and behavior of this class, you can scroll its content the same way. Please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.scrollablecontrol.aspx[^].

The idea is to use AutoScroll and AutoScrollMinSize. When the actual size becomes less then "auto", vertically or horizontally, the appropriate scroll bar appears (or both), helping to scroll the control's content to show the whole content which is assumed to be of the minimal size.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900