I'm considering programming a game of patience (solitaire), I've drawn my cards, and I don't expect any trouble placing 'em on the 'table', but I'm wondering about being able to pick up and move several cards in a 'pile'.
I'm planning on placing piled cards a few pixels apart from each other in order to be able to see at a glance how many cards are in any 'pile'.
If, for example, I have a pile of (say) 30 cards, will I be able to pick 'em all up and move 'em all in one mouse click and drag? Or will I have to pick 'em up one at a time?
I'm hoping for a pointer to a technique for doing that. Obviously I'll need 'em all to remain in the order they were in when picked up.
Also, will I be able to pan (scroll left or right) the 'table'? My game will consist of a single row of cards which may become so wide that reducing the card heights to accommodate 'em all would render them too small to be able to distinguish one card value from another. Imagine (say) 30 cards in a single row!
Poppa
Along with the sunshine there has to be a little rain sometime.
You haven't actually told us what a "card" is in this context but, given the forum we're in, I'm assuming that you are drawing them using GDI+. In that case, it's completely up to you whether you move them as a group or not. What you draw is just a visual representation of some data, so it's up to you what that data is and how it's represented. I suspect that this may be of use to you.
One-way upgrade
Visual Studio will automatically make functional changes to the following projects in order to open them. You will not be able to open these projects in the version of Visual Studio in which they were originally created.
- Wunnell.Drawing.GdiPlusManipulationDemo, "C:\Users\georg\AppData\Local\Temp\Temp1_Manipulating GDI+ Drawings (VB).zip\Manipulating GDI+ Drawings (VB)\Wunnell.Drawing.GdiPlusManipulationDemo\Wunnell.Drawing.GdiPlusManipulationDemo.vbproj"
Non-functional changes required
Visual Studio will automatically make non-functional changes to the following projects in order to enable them to open in Visual Studio 2015, Visual Studio 2013, Visual Studio 2012, and Visual Studio 2010 SP1. Project behavior will not be impacted.
- Wunnell.Drawing.GdiPlusManipulationDemo, "C:\Users\georg\AppData\Local\Temp\Temp1_Manipulating GDI+ Drawings (VB).zip\Manipulating GDI+ Drawings (VB)\Wunnell.Drawing.GdiPlusManipulationDemo\Wunnell.Drawing.GdiPlusManipulationDemo.sln"
So of course I clicked Continue...
...and this happened:
Migration Report - Wunnell.Drawing.GdiPlusManipulationDemo
Overview
Project Path Errors Warnings Messages
Wunnell.Drawing.GdiPlusManipulationDemo Wunnell.Drawing.GdiPlusManipulationDemo.vbproj 11 0 1
Solution and projects
Wunnell.Drawing.GdiPlusManipulationDemo
Message
Form1.vb: Failed to backup file as C:\Users\georg\AppData\Local\Temp\Temp1_Manipulating GDI+ Drawings (VB).zip\Manipulating GDI+ Drawings (VB)\Wunnell.Drawing.GdiPlusManipulationDemo\Backup\Form1.vb
Form1.Designer.vb: Failed to backup file as C:\Users\georg\AppData\Local\Temp\Temp1_Manipulating GDI+ Drawings (VB).zip\Manipulating GDI+ Drawings (VB)\Wunnell.Drawing.GdiPlusManipulationDemo\Backup\Form1.Designer.vb
My Project\AssemblyInfo.vb: Failed to backup file as C:\Users\georg\AppData\Local\Temp\Temp1_Manipulating GDI+ Drawings (VB).zip\Manipulating GDI+ Drawings (VB)\Wunnell.Drawing.GdiPlusManipulationDemo\Backup\My Project\AssemblyInfo.vb
My Project\Application.Designer.vb: Failed to backup file as C:\Users\georg\AppData\Local\Temp\Temp1_Manipulating GDI+ Drawings (VB).zip\Manipulating GDI+ Drawings (VB)\Wunnell.Drawing.GdiPlusManipulationDemo\Backup\My Project\Application.Designer.vb
My Project\Resources.Designer.vb: Failed to backup file as C:\Users\georg\AppData\Local\Temp\Temp1_Manipulating GDI+ Drawings (VB).zip\Manipulating GDI+ Drawings (VB)\Wunnell.Drawing.GdiPlusManipulationDemo\Backup\My Project\Resources.Designer.vb
My Project\Settings.Designer.vb: Failed to backup file as C:\Users\georg\AppData\Local\Temp\Temp1_Manipulating GDI+ Drawings (VB).zip\Manipulating GDI+ Drawings (VB)\Wunnell.Drawing.GdiPlusManipulationDemo\Backup\My Project\Settings.Designer.vb
My Project\Application.myapp: Failed to backup file as C:\Users\georg\AppData\Local\Temp\Temp1_Manipulating GDI+ Drawings (VB).zip\Manipulating GDI+ Drawings (VB)\Wunnell.Drawing.GdiPlusManipulationDemo\Backup\My Project\Application.myapp
My Project\Settings.settings: Failed to backup file as C:\Users\georg\AppData\Local\Temp\Temp1_Manipulating GDI+ Drawings (VB).zip\Manipulating GDI+ Drawings (VB)\Wunnell.Drawing.GdiPlusManipulationDemo\Backup\My Project\Settings.settings
Form1.resx: Failed to backup file as C:\Users\georg\AppData\Local\Temp\Temp1_Manipulating GDI+ Drawings (VB).zip\Manipulating GDI+ Drawings (VB)\Wunnell.Drawing.GdiPlusManipulationDemo\Backup\Form1.resx
My Project\Resources.resx: Failed to backup file as C:\Users\georg\AppData\Local\Temp\Temp1_Manipulating GDI+ Drawings (VB).zip\Manipulating GDI+ Drawings (VB)\Wunnell.Drawing.GdiPlusManipulationDemo\Backup\My Project\Resources.resx
Wunnell.Drawing.GdiPlusManipulationDemo.vbproj: Unable to save migrated project file.
Show 1 additional messages
Plus of course, I'm using Version 2019.
Shame, looked interesting.
Poppa
Along with the sunshine there has to be a little rain sometime.
In my Seahaven solitaire game implementation, I used a simple structure to keep track of where the "cards" are located, and what card is below or above the given card.
Cards could then easily be moved together. If you clicked on one card, then all the cards that were "linked" to this card (dealt on top) were copied to a list and as you moved the one card, the list was looped through to move all the other cards by the same amount.
Since there are a fixed number of cards, which exist in a deck, I used an array for the deck, and the deck was an array of these structures. If I had to dynamically create or destroy cards, then a class would have been used, but in this case, a structure worked fine.
The implementation had its origins in a VB3 version of code which used User Defined Types, so the conversion of UDTs to Structures was the minimal code change method of porting the code from legacy VB to VB.Net.
Code:
'The cards are linked together and to the stacks using a double-linked list. The links are part
'of the Card_Type UDT (changed to Structure in VB.Net).
'The Card_Type holds placement information (left, top) and a double link (prev, next) for each card or stack.
'The left and top fields identify the upper left corner of the card for positioning
'The Prev field identifies the card this card is linked to.
'The next field identifies the card linked to it.
'(Note "Tricky" used of PrevCard field when this type is used as the base of a Stack (i.e., normal, transit or home)
' Since the PrevCard field is not applicable to a stack it is used to control the "fan", aka vertical spacing, of the cards
' placed on the stack. So, for the Home stacks, PrevCard is 0, so the cards are stacked "Squared" so you can't see the underlying
' cards. For the Normal Stacks, it is some small value so the tableau cards fan down so you can see the tops of the
' underlying cards and identify their rank and suit)
Private Structure Card_Type
Public Left As Integer
Public Top As Integer
Public PrevCard As Integer
Public NextCard As Integer
End Structure
If you want to reference the full project code, then a version using Pictureboxes for the cards would be found in Post #6, and the same code modified to not use Pictureboxes (i.e. draw the cards) is found in Post #12 of this thread.
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
You're right of course. Forgetting the basics now !
Thanks John, dragging isn't my problem, I've used dragging in a few projects.
My problem is how to drag a group of items, in this case I expect 'em to be PictureBoxes.
I'm going to take a look at Passel's suggestion in a little trial project, to see if I can make that work. Thanks Passel.
I haven't given much thought yet about my left and right scrolling problem, it might only be a case of trying to show just a small section of a very wide form. I'll see if I can drag a stack of cards before I worry too much about that.
I may not need to do that at all, play proceeds in a single row from left to right so if I just keep (up to, say) the last ten or so cards in the row visible, and bear off the cards or stacks to the left of those, then reintroduce 'em later as required, that may work.
Poppa
Along with the sunshine there has to be a little rain sometime.
My problem is how to drag a group of items, in this case I expect 'em to be PictureBoxes.
When you call DoDragDrop, it's completely up to you what data you actually drag. If you want it to be multiple controls then make it multiple controls.
...
I haven't given much thought yet about my left and right scrolling problem, it might only be a case of trying to show just a small section of a very wide form....
I think I would draw everything and use the translatetransform to "scroll" the drawing.
But since you're already using pictureboxes, one way to approach the problem is to use a large panel within the form to hold the controls.
Since the mouse will move over the panel and a lot of controls, the scrolling of the panel should probably be handled outside any MouseMove events, so that you don't have to coordinate processing from the various controls. Also, if you move the panel directly in response to the MouseMove event, that event can happen quicker than the scroll may be able to be done, so the scroll will fall behind the mouse movement and catch up when you stop moving the mouse. This lagging type movement can be distracting.
So, the example uses the MousePosition (which is screen coordinates) and subtracts the Form's position to make the value relative to the left of the form and scrolls the panel based on the ratio of the size of the panel to the size of the form, so that the full move of the mouse from left side of the form to the right, causes the panel to move in sync by a larger amount so that when the mouse is at the left of the form, the left of the panel is at the left of the form.
Likewise, when the mouse reaches the right side of the form, the right side of the panel lines up with the right of the form.
The panel will scroll proportionately, continuously, as the mouse moves across the form. You can resize the form, and the scrolling is automatically managed so that the full horizontal panel is scrolled when the mouse moves the full width of the form, regardless of size.
To make the movement consistent and not lag behind fast mouse movement, the movement is done at a fixed rate from a timer tick (I think 20hz is sufficient).
The example is using 32 pictureboxes, and lines them horizontally across the panel. I create a bitmap and draw a number in it for each picturebox so that you can easily distinguish between each picturebox as it is scrolled back and forth. You can click and drag on any picturebox to move it around the panel so you can see the panel scrolling independent of the picturebox being dragged.
Last edited by passel; Aug 31st, 2021 at 05:12 PM.
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930