Clicking grid view with drag and drop? [duplicate] - c#

This question already exists:
Closed 10 years ago.
Possible Duplicate:
Click and drag image to image grid?
I have a few image boxes in my form and I was wondering how can I would place a grid across the form that have a bunch of lines so the whole grid is a bunch of 64 x 64 squares. I need it so I can select an image and place it onto a specific square using the mouse and be able to go through the whole grid and check for example how many of one specific image is on the grid. To give you a better idea of what I'm doing is that I have a few image boxs which contain different 64 x 64 images. There is another image box that shows the image I clicked on last, which is like a brush because whenever you left click a box in the grid it pastes it into that specific box in the grid. I also need it so I can right click the box and delete the image in the box the mouse is over. Finally I need to be able to read all the images in the box and output it into a file that I can later open. I'm using it to create land in a game, which the program will output the needed texture and and where ground level is for the boxs which make up the whole terrain. What I need to know is what kind of thing should I do to be able to do this? I've been trying the past few hours on how I make the boxs and how to know where the mouse is and stuff and I'm completely stuck. A simple idea would be helpful. I actually don't know what control(s) I should use for this so an idea that doesn't involve any grid controls is still very helpful.

I don't know if it's the best possible idea, but you could use FlowLayoutPanel with WrapContent set to true and FlowDirection = LeftToRight. I dont know about Drag&Drop operation though (never done it with FlowLayoutPanel, buth there are some nice tutorials out there).
You can track your mouse position using mouse events. If you don't want to do that:
You can get absolute position at any time using:
Point currentPos = System.Windows.Forms.Cursor.Position;
Then, to get relative position on your (current) control:
Point relativeLoc = this.PointToClient(currentPos)
... and then, to get control over which your mouse is on FlowLaoutPanel:
Control c = flowLayoutPanel1.GetChildAtPoint(relativeLoc);

Related

How to move the control/UI elements along with the keyboard in UWP

I'm wondering if there any solution that could make the app automatically adjust the controls position when the keyboard is activated. For example, in the image below, I want to make those four button on the screen move dependently with keyboard. When the keyboard is activated, buttons move to the center and move back when the keyboard is gone.
There might be some similar questions here but I couldnt see them in the search result, maybe they are using some different words on title so if this question is duplicated it will be appreciated if you guys could paste the link on comment or whereever.
The idea is you can listen to the Showing and Hiding event of the InputPane. In the event handler, you adjust your UI layout with respect to the keyboard.
For example, you can realign the button relative to the height of the keyboard.
For more information on InputPane, refer to https://msdn.microsoft.com/EN-US/library/windows/apps/windows.ui.viewmanagement.inputpane.aspx
For dynamically align the UI layout example, refer to
https://code.msdn.microsoft.com/windowsapps/Keyboard-Events-Sample-866ba41c

Creating a Drag and Drop game

I'm creating a game that first requires the user to drag a certain textblock into a rectangle. Depending on which textblock is dropped into the rectangle, I want to store the contents of that specific textblock. It's important to note: I want the values stored only when the textblock is dropped inside the rectangle.
The problem: How can I make it so the computer knows that the rectangle contains the textblock?
Here's a screenshot to make things a little more clear: http://gyazo.com/3aa3a8678f11260889261fcd46366616.png
As of now, I can drag and drop the textblock fine, but the computer has no way of knowing if the textblock and rectangle intersect.
I've been trying to solve this problem for a few days now, and have spent a lot of time trying to use the system.drawing.rectangle.IntersectsWith()...only to find out that you can't dynamically add a system.drawing.rectangle to the canvas.
I've also thought of doing it by coordinates: if(textblock's coordinates are within the bounds of the rectangles coordinates)... However, I've spent time trying to figure out how to dynamically get the coordinate position of a xaml control, only to find out that you can't.
Could someone please offer some guidance? I've been working hard towards this and I've hit a dead end, so any degree of help will be great.
Thanks!

metro menu using viewport3D how placing and resize items

I'm Trying create a menu like windows 8 start menu (metro)
its not hard to create buttons (i mean those special buttons that you all saw in metro style with image and description text) and do some animation for them like when mouse over the text change and show full description . i create those was not hard but ...
if you see win 8 start menu carefully you will see after button click there is a 3DRotation animation that rotate the button around Y axis and scale it to big (scale animation). the button come front and full screen then the page load and page element fade in page.
after 1 day search i understand i must use 3d working and i cant do that with 2d animation and transform.
now i create a viewport3D and i place my visual in that (4 buttons (UserControl)) then after click it rotation animation work .I using Viewport2DVisual3D for show my button in 3d viewport3D.
problem is here :
1- How can i resize my element to full screen of window (i scale it but it is not exact full screen and other element still are in back of this big one and if the user resize the window scale fail !)
2- after doing animation how can i remove other menu button (like close and minimize) from window .(i have a grid that has viewport3D and two button close and minimize in it after scale the button they are still there (i must set those 2 button in viewport3D too ? because i dont need 3d effect for them))
3- when you maximize the window 3d element miss the real place how can i do like grid placing in viewport3D.(dont forget i cant put my button in grid because i need animation the visual then if i place them in grid visual will be whole grid , all grid will get animation)
I'm Using wpf in VS2010 and target pc with xp and 7 windows ;
in viewport3d, there are attributes like scalex,scaley and scalez. you can give scaling for each axis, also i thinking , you have to adjus fov , nearplane distance. when scaling.
please refer this link https://social.msdn.microsoft.com/Forums/vstudio/en-US/642253a6-e7a5-4ce2-bc08-e91f2634605b/disable-autoresize-autoscale-in-viewport3d?forum=wpf

How to create an number line control?

I'm planning to create a number-line control similar to the image below (only one of them):
I'm creating a program where the children can detect where's the position's number. I mean, instruct them to write the number 4 (and the boy writes a vertical line).
The idea is when the cursor is on the control, it shows a vertical line. And when the user presses OK, returns with an event the X position and hold it the line.
Do you know if there's a similar control on the web?
Just use a Slider with a new template.
How to Create/Apply a Slider Template

How to make "mouse-transparent" panel?

I'm new to WPF so I've got a problem:
I need to create a grid. This grid should contain a column with a kind of thumbnails.
When I move mouse over a thumbnail, there should appear a panel with a big image. This panel will cover all grid.
But this will make thumbnail think that mouse already has gone.
After mouse's gone, panel should dissappear. Mouse appears above thumb again, and panel appears. And again, and again. I don't know how to handle this.
Could anybody suggest any solution?
Sounds to me like you want to use IsHitTestVisible="False" on the image that pops up. This will make it ignore the popup when testing where the mouse is, so it will think your mouse is still over the thumbnail image. This should work on any UI element, except windows.
Use MouseEnter and MouseLeave:
http://www.hanselman.com/blog/MouseEnterAndMouseLeaveLoopsInWPF.aspx
There are two ways I can think of to do this, depending on what kind of functionality you're looking for.
If you want the larger image to appear in proximity to the mouse and the thumbnail, then you might want to take a look at using a Tooltip.
Otherwise as Aliostad mentioned above, you could use the MouseEnter and MouseLeave events to trigger the display of whatever content is needed.

Categories