grid of buttons

  • Thread starter Thread starter cronusf
  • Start date Start date
C

cronusf

Hello,

I need to write a custom control that renders a grid of buttons (sort
of like the ChooseColor dialog). Here's a screenshot of what I am
after:

http://img388.imageshack.us/img388/2055/grides9.jpg

Basically, every element stores two buttons. I'm not sure how to get
the "sunken" look of an element (the little box containing two
elements).

Also, there will be about 500 buttons. Should I create 500 Button
objects, or just handle the logic myself?

Finally, I noticed I can use a Panel with the Fixed3D border to get
the sunken look. But creating a panel for every two buttons does not
seem like the way to go, since the panel is only being used for
cosmetics.

Please advise.
 
500 visible buttons at the same time could make rendering a bit slow and I
guess could cause some memory/handle problems as well. Give it a try and see
what happens.

Another option would be to draw everything yourself and then just handle the
mouse click events. It's pretty easy to do. You can use the ControlPaint
class to draw both the buttons (in whatever state you need) and the borders
that you need. Something like this should get you started:

private void DrawButtonElement(Graphics g, int x, int y)
{
ControlPaint.DrawBorder3D(g, x, y, 60, 30, Border3DStyle.Sunken,
Border3DSide.All);
ControlPaint.DrawButton(g, x + 4, x + 4, 24, 22, ButtonState.Normal);
ControlPaint.DrawButton(g, x + 32, x + 4, 24, 22, ButtonState.Normal);
}

/claes
 
private void DrawButtonElement(Graphics g, int x, int y)
{
ControlPaint.DrawBorder3D(g, x, y, 60, 30, Border3DStyle.Sunken,
Border3DSide.All);
ControlPaint.DrawButton(g, x + 4, x + 4, 24, 22, ButtonState.Normal);
ControlPaint.DrawButton(g, x + 32, x + 4, 24, 22, ButtonState.Normal);

}

Great, thanks. Doing the drawing is how I originally wanted to do it,
but I did not know how to draw the 3D border, etc. Thanks for the tip
about the ControlPaint class!
 
Back
Top