how to hide panel when cursor goes outside of the object - c#

I want to write code in c# to disable the panel when I outside from the objects.I use RectTransform for objects.
I want to write code in c# to disable the panel automatically and enable when again over to object with mouse when I outside from the objects.I use RectTransform for objects.
can anyone please help me to figure out this?

Related

In Unity, how can I use an X, Y screen coordinate to find if there is a child of my Canvas object there? [duplicate]

This question already has answers here:
How to detect left mouse click but not when the click occur on a UI Button component [closed]
(3 answers)
Closed 4 years ago.
Is there some Unity API that allows me to pass in an X,Y screen coordinate and figure out if there is a child of my Canvas object there? The HitTest from the camera seemed to ignore the children of the Canvas.
Thanks in advance!
Edit: (background information)
I've got a 2D game that resembles an endless chessboard, and I've implemented drag functionality and pinch-to-zoom functionality in a component attached to the camera. This works fine, but I've got a button bar on the side (made of panels and buttons, children of my Canvas) and if I drag from button A to button B it moves the map that's behind the buttons. In order to prevent this, I'd like this component to simply ignore any touch or click events that occur over GUI elements like Panels and Buttons, but I can't tell the difference.
An easy way is to use EventSystem.IsPointerOverGameObject:
if( Input.GetButtonDown( "Fire1" ) )
{
if( EventSystem.current.IsPointerOverGameObject() )
return;
You can also derive your own control from Button and handle pointer clicks directly...
class MyButtonClass : Button
{
public override void OnPointerDown( PointerEventData eventData )
{
base.OnPointerDown(eventData);
EventSystem.currentSelectedGameObject can also come in handy.
The answer that ended up working for me was suggested by vakabaka on the Unity forums. It was to use the GraphicsRayCaster:
https://docs.unity3d.com/ScriptReference/UI.GraphicRaycaster.Raycast.html
Their answer is here: https://forum.unity.com/threads/did-the-user-click-a-menu-object.578026/#post-3859102
the IsPointerOverGameObject may work as well, but I had trouble with it earlier and I'm not sure how well it would work for multi-touch scenarios.
Thanks everyone!

Add Invisible Control and use Control.MouseHover Event

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.

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 capture a moving customcontrol

I try to explain my problem:
I got many customcontrols of same type on a panel.
At runtime I'm free to move any custumcontrol ( mousedown and mousemove events) in the form with mouse over any others customcontrols using bringtofront() to have it over all.
Now I need to know when the control I'm moving is over any other control and which control is under.
So far I've tryed to use drag-n-drop events but without success, there's some other way to do this or I've to re elaborate it with drag events?
thank you all for help
and sorry for my English.
EDIT:
The controls are cards game and my final goal is to use cards to create logical sequence following rules based on card value and/or color.
You can't solve the problem with drag-and-drop because you're not actually dropping one control onto the other control. You're merely moving them around in the form.
You need to become familiar with Z order, which is the front-to-back arrangement of objects in a virtual 3D space. To adjust the Z order, you can call the BringToFront and SendToBack methods of any object that derives from System.Windows.Forms.Control.
The Z order is also exposed by the parent (container) control's Controls collection. Using the GetChildIndex method, you can determine the position of any control within the Z order.
So now, all you need to do is figure out which control the control you're dragging is over. Do that by comparing the Location properties of the two controls. When you know that the locations of two controls overlap, check their respective Z order indices to see which one is on top.

How do I "Stick" a shape to the mouse in WPF?

I have a wpf application that has some shapes on a canvas I want to allow the user to click on a shape and then the shape gets stuck the the mouse until they click again.
So far I know very little about WPF so go easy on me ;)
Hopefully this is what you're looking for.
"Mouse dragging logic is fairly straightforward: In the OnMouseDown handler, you save the position of both the object you want to drag and the mouse pointer, and you call CaptureMouse. In OnMouseMove, you calculate the difference between the coordinates of the current mouse pointer position and the saved position, and add that to the original object position. (If you're on a Canvas, you can move the object by calling Canvas.SetLeft and Canvas.SetTop for the object; otherwise you can adjust a TranslateTransform object set to the object's RenderTransform property.) In OnMouseUp, you call ReleaseCapture.
Because your app can lose the mouse capture in other ways (such as the appearance of a system modal message box), you'll also want to override OnLostMouseCapture to abort the dragging operation (if it hasn't terminated with OnMouseUp) and perform cleanup. You might also want to override OnTextInput to abort the drag if the user presses the Escape key."
Copied from http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/b6c51eef-269e-4c85-96af-b5b1e4cb9bd5/ there's also code up on this site for how to do it.
Check out this Thread - http://silverlight.net/forums/t/68889.aspx
Since your 'Stick' is on the Canvas, keep setting the Canvas.Left and Canvas.Top on MouseMove with MousePositions

Categories