Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET GDI+ graphics
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
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 30-Sep-12 10:31am
Edited 30-Sep-12 11:42am
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

For a form graphics rendering, override the method OnPaint and call your rendering method in it:
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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 7,215
1 DamithSL 5,114
2 Maciej Los 4,866
3 Sergey Alexandrovich Kryukov 4,747
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 30 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100