drawchange | An application to manage volunteer registrations | Portal library
kandi X-RAY | drawchange Summary
kandi X-RAY | drawchange Summary
This portal is meant to be used by Atlanta nonprofit drawchange to manage their volunteers and events. New volunteers will register an account, be vetted by an administrator, then sign up for volunteer events through this portal.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of drawchange
drawchange Key Features
drawchange Examples and Code Snippets
Community Discussions
Trending Discussions on drawchange
QUESTION
I am having a bit of a small issue performing a certain task in my winforms application.
I am basically attempting to recreate a "Top-View RTS Map", on a winform. In order to save memory, not all tiles of the "Map" are displayed on the screen. Only the ones that fit within the viewport. Therefore, I am trying to allow the user to perform a pan/scroll on the displayed tiles in order to navigate the entire map!
Right now, I am doing this by creating and displaying GroupBox
controls dynamically at runtime. These represent the tiles...
I have created my own objects to support all of this (contains screen coordinates, Row and Col info, etc.)
Here is how I am currently accomplishing all of this, in pseudo-code:
Creating the form, tiles and the map in general
I create a winforms form that is 600px X 600px.
I create a new "Map" (using a
List
) that is 100 tiles by 100 tiles (for testing) on form load and save that into a variable.I keep track of the displayed tiles via another list (or property that derives from the main list
bool MapTile.isDrawn
)Each tile is visually made of a
GroupBox
control that is 100px X 100px (so [7 X 7] of them fit on screen)To start, I find the center
MapTile
(tile [50, 50]) in the "Map", create theGroupBox
for it and place that in the middle of the form,I then add the other tiles/controls necessary to fill in the form (center - 3 tiles, center + 3 tiles (up, down, left, and right)).
Each tile, of course, subscribes to the proper mouse events to perform a drag
When the user mouse drags a tile, all other tiles being displayed follow suit/follow the leader by updating all "displayed tiles" coordinates to match the movement that was made by the "dragged" tile.
Managing Displayed Tiles
- While the
GroupBox
tiles are being dragged/moved, I perform a check to see if the tiles that are on the outer edge of the viewport are within its bounds. - If, as an example, the top-left-most tile's right edge falls outside the bounds of the left edge of the viewport, I remove the entire left column tiles, and add the entire right column tiles programmatically. The same goes all directions (up, down, left and right).
So far, this works fine as long as I don't go too fast... however, when I drag the tiles "too fast" passed an outer edge (e.g.: where point 2 ci-dessus would apply), it seems that the application is unable to keep up because it doesn't add the column or row where they should be on the form, and other times, it does not have time to remove all controls of a row or column and I end up with controls that are still on the screen when they shouldn't be there. At that point the entire grid/map is off balance and stops working as intended because either the events that should fire on one edge don't (the tiles are not present) and/or there are now multiple controls with the same name on the form and the removal or referencing fails...
While I am well aware that winforms is not designed to perform intensive GPU/GDI operations, you would think that something this simple would still be easily do-able in winforms?
How would I go about making this more responsive at runtime? Here's my entire set of code:
Form code
...ANSWER
Answered 2020-Jan-29 at 22:17I'd create the grid using (DataGridView
, TableLayoutPanel
, GDI+
, or whatever) and then in the drag and drop, just calculate the new indexes and update the indexes, without moving the grid.
Example
The following example shows how to do it using a TableLayoutPanel
:
- Assign a fixed size to cells
- Build the grid to fill the form
- When form resizes, rebuild the grid
- In mouse down capture the mouse down point and current top left index of grid
- In mouse move, calculate the new index based on mouse movement and update index
- In cell paint of the panel, draw the indexes
Here is the code:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install drawchange
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page