简体   繁体   中英

Layout Advice for C#

I'm having a difficult time on this issue. I've searched on this site and couldn't find a solution anywhere yet. I have to make a grid of blocks to be displayed on a picture. I've searched and found things about drawing the grid and the GridView class. But all that seems impossible since I have to manipulate the size of the blocks to whatever size. So if anyone can provide any advice I would be very grateful thanks.

If you need simple grid, you can do it by simply drawing it to image:

using (var bitmap = Bitmap.FromFile(@"C:\darbai_test\Penguins.jpg")) 
{
  var graphics = Graphics.FromImage(bitmap);
  var xStep = 10;
  var yStep = 15;
  for (int i = 0; i < bitmap.Width / xStep; i++)
  {
    var x = i * xStep;
    graphics.DrawLine(Pens.Black, x, 0, x, bitmap.Height);
  }

  for (int j = 0; j < bitmap.Height / yStep; j++)
  {
     var y = j * yStep;
     graphics.DrawLine(Pens.Black, 0, y, bitmap.Width, y);
  } 

  bitmap.Save(@"c:\darbai_test\penguins_withgrid.jpg");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM