Native grid-.NET

I would like to advise if I should program the following myself from scratch or use a third party component. If there is a third party component that is suitable for an account without excess baggage, I would appreciate a recommendation.

I would like to have a component that is a matrix of cells as a grid control. I don't need any changes, no selection, dynamic resizing of columns, no default cell drawing behavior, no effects when the mouse moves over things does not match the keyboard.

All I need is to make each cell myself, and if the grid size exceeds the available space of the parent component then scrollbars will appear.

In other words, I would like to say: grid.Invalidate ()

and then I get a callback for each visible cell something like this:

void DrawCell (int x, int y, Graphics g, Rectangle cellDrawingRect)

+2


source to share


3 answers


My advice? Calculate the size of the grid, resize the image, draw the grid and place the image in a PictureBox and place this PictureBox in a ScrollableControl.

You don't have to mess around with Control.Paint as the picture handles that for you.



If you are so inclined, you can put the whole thing in a UserControl. This makes your code a little more reusable and more portable.

+2


source


This seems pretty trivial if you are just writing your own control (derived from ScrollableControl). Handle Control.Paint to paint your cells and use the HorizontalScroll and VerticalScroll properties to customize your scrollbars.



0


source


Here is my earliest question of mine on the matter:

Need help creating a control to display data

I would definitely recommend doing this yourself, especially since it is essentially a read-only control. Most of the ready-made mesh components are built to do a lot more than you need to, and fighting them into the shape you want could save you more effort than building your own from scratch.

As Charlie Solts mentioned, it would be easier to draw the whole thing on a large PictureBox and then move it to a smaller panel, but that will depend on how big the overall grid is. Bitmaps can take up a lot of memory.

0


source







All Articles