CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Grid of buttons

  1. #1
    Join Date
    May 2001
    Location
    Mobile, AL.
    Posts
    64

    Grid of buttons

    I want to have an 8x8 array of square buttons, all equal size. The buttons should be created and placed in the cells of the grid by the code.

    Each button should have a specified background color, and sometimes an image. The image has a transparent background so the button background color shows through the transparent parts.

    All buttons will share an event handler, which should be able to determine which cell (row, col) the button is located. I could probably put that information in the button's tag if I need.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Grid of buttons

    What is your question?

  3. #3
    Join Date
    May 2001
    Location
    Mobile, AL.
    Posts
    64

    Re: Grid of buttons

    I had accomplished this in VB.Net forms application, but I want to do the same thing in WPF. But I'm running into several obstacles, such as placing the buttons in the appropriate cells (specified by row and column), and setting the background color and image properties of the buttons.

    What's the best control to use to contain the buttons?

  4. #4
    Join Date
    Feb 2008
    Posts
    79

    Re: Grid of buttons

    For Silverlight 1.1
    There is no prebuilt grid control
    So I would manage the placement manually.

    For the callback, I would populate the Button.Tag field with data defining its location within the grid, then use (Button)sender.Tag to get the data in the call back function.

    psudocode:
    placebtn(x,y)
    {
    b = new button
    b.setx = x
    b.sety = y
    b.text = "bla"
    b.tag=new point(x,y);
    b.onclick(clickfunction)
    }

    clickFunction(sender, e)
    {
    pos = (Point)((Button)sender.Tag);
    }

    Hope it helps...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured