I have developed a board game. I want to add one more feature onto it. If I move my cursor onto one of the entry on the game board. It will show relevant information right next to the cursor. I know I can add invisible controls onto the game board and use Control.MouseHover Event to make this feature work. However, what kind of invisible control I can add onto the board? The rectangle shape will be most useful. One more question, how to display text right next to the cursor? I have attached the board I was talking about in below.
Thank you for helping me.
Related
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
I am have been trying all day to figure out how to not allow controls that I draw on event to check and see if there is another control there and if so to move it over so they do not overlap. I need them to be able to be overlapping if the user drags them there but on the creation of the control to check and move them if necessary. I am trying to create a card game and dont want controls to be hidden behind controls (cards) that the user has not yet moved manually. I am using picture boxes as my cards. Any help would greatly be appreciated. Here is a screen shot of my form. The darker panels are whats in the players hand. The panels that are a light grey are the playing field. Ideally, the user would play a card and it would try and place it in the top left of the panel. if there is a card that intersects then move it over until it doesn't touch a card. Basically find a open space to put the card.
Have you tried using the flow layout panel Class it's under the toolbox=> container with this control you can set how controls are added to it.
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!
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);
I'm making a bomberman game in a C# windows form application. It has over 300 pictureboxes (walls) that are placed on a panel. The picturebox of bomberman himself is also on that panel.
When the location of bombermans picturebox changes, all the controls on the panel are automatically refreshed. Because there are so many controls on that panel, and because the location of the picturebox changes multiple times per second, the program becomes laggy when I try to move.
I want to have control over the refresh event of the panel (and it's controls), because I think my problem is solved when only the pictureboxes that need to be refreshed, are refreshed programmatically.
I hope someone can help me out with this!
Ruud.
If you move the child, the parent has to be refreshed because it may need to draw the area where child was located previously. It would also mean that all children (of parent) would get refreshed.
OTH, using so many controls may not be a good idea. I would suggest you to keep data structures describing walls and then use it to draw it within Panel (or your custom control). You can write your own logic for hit testing (mouse or keyboard click within wall boundary) by capturing mouse/keyboard events at Panel/Parent level. With correct organization data structure, hit testing can be very efficient.
You are trying to paint the whole form which will surely take time . If you want to change only a part of the form, which in your case is Moving the bomberman to a new position, Only invalidate the area you want to repaint and then pass it to the Invalidate method.
Do something similar to this.
//Invalidate previous position of bomberman
Rectangle invalid = new Rectangle(picturebox1.Location.x,picturebox1.Location.y,picturebox1.Width,picturebox1.Height);
Invalidate(invalid);
//Add code to move your picture box and then call above two lines again
invalid = new Rectangle(picturebox1.Location.x,picturebox1.Location.y,picturebox1.Width,picturebox1.Height);
Invalidate(invalid);
Note sure but somthing similar polished code would work...
Here is a link to an example for reference. http://msdn.microsoft.com/en-us/library/ms229628.aspx