Antonio Teh Sumtin
Antonio Teh Sumtin

Reputation: 498

map maker application

I have created a somewhat complete application which allows me to create a map (.txt file with information about all the points of the map), load it and draw it.

My solution for this was, inside the windows forms application, to put a panel (since I need to be able to move on map) and inside that panel pictureboxes(since I want to put a background image and image on them) that represent points of map in size 50x50 pixels. The problem I am facing now is increased load time for my application, since I am loading pictures into the pictureboxes...

Does anyone have any alternative suggestion to what I have been attempting? Visual representation might help:

NOTE: Pictureboxes only have background color here...

The code, as requested: (well, some of it)

    private void Load_Map()
    {
        for (int i = Y - 12; i < Y + 12; i++)
        {
            if ((i >= 0) & (i < Int32.Parse(MP.Mheight)))
            {
                string Line = xline[i];
                for (int j = X - 12; j < X + 12; j++)
                {
                    if ((j >= 0) & (j < Int32.Parse(MP.Mwidth)))
                    {
                        int X = i * Int32.Parse(MP.Mwidth) + j;
                        int Z = Int32.Parse(Line[j].ToString());
                        Map_Location[X] = Z;

                        Color H = new Color();
                        Map_Point(j, i, Map_Height(Z, H), 50);
                    }
                }
            }
        }
    }

Creating points:

    private void Map_Point(int X, int Y, Color H, int Point_Size)
    {
        PictureBox MP = new PictureBox();
        MP.Name = Map_Coordinates(X, Y);
        MP.Size = new Size(Point_Size, Point_Size);
        MP.Location = new Point(Y * (Point_Size + 1) + 4, X * (Point_Size + 1) + 4);
        MP.BackColor = H;

        Control MW = this.Controls["WorldMap"];
        MW.Controls.Add(MP);

    }

Upvotes: 1

Views: 546

Answers (2)

Dai
Dai

Reputation: 155250

You'll be better off creating a custom control by deriving from System.Windows.Forms.Control and overriding the OnPaint method and doing your own drawing and handling click events yourself.

Using a large number of WinForms controls the way you're doing is an exercise in pain, as WinForms will create a hWnd object for each control, and WinForms doesn't scale too well, unfortunately.

Upvotes: 3

Malcolm O&#39;Hare
Malcolm O&#39;Hare

Reputation: 4999

You should be using System.Drawing.Graphics

Here are the MSDN Tutorials for it.

It has a method called DrawImage , which you can use instead of a picture box. For the grid you should be drawing it as a rectangle with a color for the background and vertical/horizontal lines to make the grid.

Upvotes: 1

Related Questions