Re: Vertical and horizonatal rulers



On 29 Jan, 00:43, John McCartney <jmcart...@xxxxxxxxx> wrote:

I am trying to create a vertical and horizontal rule (for
labeling the cells around my grid - kinda like Excel - i.e.
I want to be able to scroll up/down, with the rulers
indicating my row and column numbers respectively.
. . . I have seen an example somewhere, where the form
was drawn on directly - however, that does not look very
nice (especially, since I want to use a different background
color for the ruler strips.

I apologise if this response ends up appearing more than once but I
seem to have a problem with my postings getting through the MS server
at the moment (unless of course it is a problem with my ISP) so I'm
posting this from Google Groups in the hope that it will get through
okay from there. In fact, when i view this thread in Google groups I
can see "two messages" in the little sub header that tells you how
many messages are in the thread, but only one message (the OP's
original post) actually appears. Hmmm . . .

Actually drawing directly to the Form (or directly into a Picture Box)
is by far the most flexible method because it leaves you in control of
every single pixel and you can draw anything you want. You can draw
lines and dots and arcs and circles and shaded areas and colour
gradients and standard text or filled or unfilled outline text and you
can draw pictures (images of various kinds) and all sorts of things.
If you have an artistic flair you can draw your own images and if you
are not very artistic you can acquire ready drawn images from various
sources and incorporate them in your code and paint them onto your
Form or PictureBox, either alone or in conjunction with all the other
methods I have mentioned. The only limit is your imagination. Saying
that stuff drawn to a Form does not look very nice because you saw a
bad example somewhere is a bit like saying that you don't like oil
paintings because you once saw a bad one in a dodgy art gallery
somehwere ;-)

In fact, having thought about it some more since your previous posts
and having realised that you are actually quite capable even though
you are a beginner in VB, I think you should change to drawing your
entire game grid (or whatever it is) into a single large PictureBox
instead of using the large number of small PictureBoxes that I
previously suggested to represent your grid. I suggested that method
initially because I thought that you might have problems with code for
the other available methods and that you might have wanted the very
simplest (in terms of code) method, but it now appears that you are
quite happy to delve a little bit deeper into this stuff. You can draw
into a large PictureBox in such a way that it looks exactly like the
grid that you have currently made out of small picture boxes, grid
borders, shading or images, grid text items and everything else. A
little bit of math on the MouseDown event of the large picture box
will allow you to use the x and y values to determine which part of
the drawing the user clicked, and therefore which "cell" he is in.

You can still continue to use your existing "move a number of picture
boxes around as a group" method to allow the user to drag a group of
cells around (to save you going to the trouble of writing proper
sprite code to perform the task). All you need to do when the user
clicks the mouse is to first determine which "cell" he is in and then
immediately place a previously invisible small picture box directly on
top of that "drawn cell" and another previously invisible small
picture box directly on top of each other "cell" that is linked to the
clicked cell (for movement purposes). Each of these little
PictureBoxes will be created so as to look exactly like the cell that
they are now sitting on top of (this can be done extremely quickly).
In this way if you only ever need to drag (perhaps) six or seven
"cells" at a time as a group then you will only ever need a total of
six or seven small Picture Boxes. All of this will happen within about
a millisecond as the user clicks down the mouse button and as far as
the user is concerned he will see nothing happen at all. The entire
grid after he clicked down the button will look exactly the same to
the user as it did immediately before he clicked, except that (unknown
to the user) some of the "cells" have had little picture boxes
positioned on top of them, with each picture box being an exact copy
of the cell that lies beneath it. All of this is invisible to the
user, but yet that group of cells (now as a group of Picture Boxes
acting as sprites) will get dragged around the screen as the user
moves the mouse with the button still held down. Then when the user
"drops" the group of cells at a new place you immediately draw the
appropriate new cell data at those positions and then immediately make
the group of little PictureBoxes become invisible again (again , all
of this happens in about a millisecond), so all the user sees is the
new "cells" dropping into their new positions and everything in the
grid once again becomes simply a single large drawing. The mechanics
of this "cell to picture box and then picture box back to cell"
business is totally invisible to the user.

Also, you can then draw your vertical and horizontal rules directly
onto the same large PictureBox into which you have drawn the 10 x 24
grid of cells. A VB Picture Box can be almost as large as you wish
(within certain quite sensible limits) and it can be much larger than
the display or than the Form on which it lives if that is what you
require. This single "larger than the Form" Picture Box (containing a
drawing of the 10 x 24 cells and the rules and various other things
you may require in the "scrolling grid" can be made to "live inside"
another Picture Box which is of such a size that it is fully visible
on your Form and you can place standard scrollbars at its sides.
Scrolling the "larger than the Form" picture Box within the "fully
visible on the Form" container Picture Box can be achieved simply by
setting its Top and Left property in accordance with the positions of
the scroll bars. There has been a lot written about this kind of thing
(scrolling one picture box inside another) on this group and in other
places. Have a little search for "scrollable viewport" or "scrolling
viewport". I'd look for a link myself but I'm (again!) running out of
available time :-)

Mike



.


Loading