How to make "mouse-transparent" panel? - c#

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.

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

GDI update graphics issue

i tried to search for this on google, but didnt seem to find anything related that could help me.
My problem is this, i have a panel in which i draw a cube, and i added a group box with 3 radio buttons and 4 normal buttons(these do the rotation of the cube)
For testing i have another button added on the panel but not in the group box.
The problem is this, when i push on any button it doesn't update the cube's rotation, only when i move the mouse on the test button(over it)
If i try to move the buttons outside the group box then all works well, but they don't work if they stay inside the group box.
Does anyone know how i can fix this?
May I suggest that instead of redrawing the panel you create a Bitmap for drawing your (rotated) cube and use a PictureBox to display it? The PictureBox could be inside the Panel together with the GroupBox.
The flickering comes because the panel redraws his background first and then raises the Paint event. To avoid this you must to create a custom control and do the drawing in OnPaintBackground protected method. This seems a overkill. Or you can write to a Bitmap and put it in the BackgroundImage property.

How to center selected grid row/column at the center of the window?

I just wasted my entire evening on something which I thought would be very simple but it seems WPF and Google are letting me down completely.
I need a grid, 6x6 of which I fill every row and column with a custom control. I want to be able to navigate through this grid via the keyboard (I can get those events, no problem) but I cannot seem to find how I can always have the selected grid row/column in the center of my window.
I found some carousel alike implementations, but most of them only work in a single direction and I want two way navigation, yet none seem to support this nor can I extend them to do this.
I essentially want to create a PSP alike grid navigation.
One easy way is to do this:
Create a scrollable form.
Add a 6x6 grid of child controls.
In the GotFocus (or similar) event for all the controls, set the parent form scroll offset to an appropriate position to centre the child.
This is pretty straight-forward thing to implement, with a little bit of maths to work out how to centre the x,y position of a control by setting the scroll offsets (it can be tricky/confusing, but as long as you understand the coordinate systems used for scrolling, not too bad)
Or, another approach that avoids scrolling via the windows APIs and using custom controls:
Create a form
Override OnPaint to draw your grid of 6x6 "controls" as simple graphical shapes or bitmap images centred on the selected "control".
Handle keyboard (KeyDown/Up) and mouse handling (MouseDown/Up) events to make the 36 areas of the graphic respond to user inputs in the way you desire. You'll have to track the selected item and force the window to redraw its graphics to show the new state. Enable double buffering to stop it flickering.
The first approach gives you a lot of windows-based handling for free (tabbing between controls, remembering where the input focus is, and directing events to separate classes for each "control", for example). The second approach strips away all this "help" but gives you complete control over everything, which can often help avoid unintended behaviours (e.g. it won't move the input focus when the user presses Tab unless you specifically write the code to make it do that).

Animation Effects in WinForms/C#

I'm pasting an image from the game im building.
the matrix of empty cells you see are made of PictureBox[][].
I wan't whenever I drop a coin to one of the columns... I want it to go down but the purple stuff will hide the falling coin and the gray color you see wont hide it.
How do I make this effect?
please notice that in each PictureBox control I have set the BG Image as you can see
Don't do it like that.
Create custom control. In custom control, override Paint, and then draw COIN sprite first, then draw mask over it. Be sure that you use double-buffered painting here.
It will work like a charm, trust me!
And, since you are (I gueess) building 5-in-a-row game here, your custom control will be able to paint occupied slots as well.
By designing custom control, you'll be able to hide all the animation and graphics stuff away from your main form.
I don't think it is possible like that. Controls in WinForms cannot be transparent, that is the problem
I would think in three directions:
Forgetting about controls and
painting everything OnPaint event of
the form. It is not too complicated
(well it would be more complicated
to detect some mouse events like you
did now, as you wouldn't know which
graybox is hit, but rather just
mouse coordinates)
Experimenting with coin as a form
(forms can be transparent)
Possibly using WPF with same logic
you did, as controls can be
transparent there
Controls in Windows Forms can be transparent. You need to set the TransparencyKey of the Form to some color that you never plan on using (many people seem to love/hate Magenta for this), and then set the BackgroundColor of each PictureBox to the same color. The result should be a transparent PictureBox with its Image drawn over it. I'm pretty sure this won't work with the BackgroundImage property, mind you- just the Image property.
One potentially unwanted side effect of this method is that you'll be able to see whatever's behind your form (the desktop, other application windows, etc.) through the transparent places in the PictureBox.

What is the easiest way to make tooltips behave how I want

I don't like the default ToolTip behavior. First, I don't like that, after tooltip is shown for "AutoPopDelay" miliseconds, it disappears and don't appear anymore if you move the mouse over the control again. Second, I don't like that AutoPopDelay is limited to 5000 miliseconds.
I found one way to make tooltip always reappear on mouse move over control, even if it was shown for a time exceeding AutoPopDelay value: I call toolTip.Hide() in MouseLeave handler. This way tooltip will appear again on mouse over.
But I haven't found a simple way to make tooltip stay shown for longer time (longer than maximum 5000 miliseconds). If I call toolTip.Show() in MouseEnter handler, then toolTip is shown in not good position. I like the position in which it shows automatically :)
So, what can you suggest?
Use the Show method to control the length of time (it is not limited to 5000ms).
There is a signature for Show that does not require that you set the relative coordinates and there is one that will take the coordinates if you want to fine-tune things. In your case you will need to pass coordinates (if you don't like what it automatically gives you). I do not believe there to be an alternative...

Categories