i need to implement hover areas to my Tool.
When i enter the last ~ 25% of the Window my Item should appear.
I tried to make an invisible Grid but an invisible object cant trigger events.
Is it possible to make a hover area with the Mouse Position?
private void BlackMetalClockRing_MouseLeave(object sender, MouseEventArgs e)
{
gridExpandInfo.Visibility = Visibility.Hidden;
}
private void BlackMetalClockRing_MouseEnter(object sender, MouseEventArgs e)
{
if (gridInformationPanel.Visibility != Visibility.Visible)
gridExpandInfo.Visibility = Visibility.Visible;
}
Associate the MouseEnter event to a new Border that'll cover your grid, with Background="Transparent". Set yourBorder.Visibility = Visibility.Collapsed at the end of this event (in order to make sure it wont intercept further mouse events).
In the MouseLeave event (which stays associated to your grid), set back yourBorder.Visibility = Visibility.Visible.
Related
I'm doing some kind of a pixel film editor and my problem there is that I am using Labels which I have to click individually to change their color, I would like to change the color by holding down the mouse button and just hovering above the Label.
Is there any Event or such to do so? I didn't find one. At the moment I am using Mouse_Down.
A look on the Editor
my Mouse_Down Event:
private void Mouse_Down(object sender, MouseEventArgs e)
{
var ActiveLabel = sender as Label;
if (ActiveLabel != null)
{
ActiveLabel.BackColor = ActiveColor.BackColor;
}
}
So I want it like on GIMP or stuff, to not click any single "pixel" but instead click and hold the mouse button and move it around and color all pixels I move over whilst my mouse is pressed.
Here's the idea:
You have a flag (boolean) which indicates whether the user is currently painting or not. If the mouse hovers over a label (event MouseEnter), you check whether it should be painted or not. If it shall be painted, you apply the code you already have.
bool paintmode = false;
// Assign this to all labels, since you don't know
// where the user will start painting
private void Mouse_Down(object sender, MouseEventArgs e)
{
paintmode = true;
}
// Make sure you assign this to all items, even the Form
// as you'll never know where the user will release the mouse
private void Mouse_Up(object sender, MouseEventArgs e)
{
paintmode = false;
}
// Assign this only to labels which can get painted
private void Mouse_Enter(object sender, MouseEventArgs e)
{
if (paintmode)
{
var ActiveLabel = sender as Label;
if (ActiveLabel != null)
{
ActiveLabel.BackColor = ActiveColor.BackColor;
}
}
}
Im working in WinForms I have 4 buttons on my form. I want to be able to hover my mouse over it and change the FlatStyle from Flat to System.
My code transforms all the buttons to System Style when you hover your mouse over it, that's not exactly what i had in mind.
All the buttons should remain flat until you hover over them. If you hover off the button it should turn back into flat button
private void All_Button_Hover_MouseHover(object sender, EventArgs e)
{
btn_Back.FlatStyle = FlatStyle.System;
Btn_Forward.FlatStyle = FlatStyle.System;
btn_Print.FlatStyle = FlatStyle.System;
btn_Open.FlatStyle = FlatStyle.System;
}
Here's a suggestion of how you could handle this.
You're already setting all the buttons in a single event method, which is fine. Since the button that triggered the event is stored in sender, you could just use that:
private void All_Button_Hover_MouseHover(object sender, EventArgs e)
{
((Button)sender).FlatStyle = FlatStyle.System;
}
To change the buttons back to the original FlatStyle.Flat style, you'll probably want to subscribe all of their MouseLeave events to a method as well:
private void All_Button_Hover_MouseLeave(object sender, EventArgs e)
{
((Button)sender).FlatStyle = FlatStyle.Flat;
}
Intro
I have a WPF application.
When i click/double click on a button to show next screen, this is captured with both MouseLeftButtonDown and MouseLeftButtonUp.
- MouseLeftButtonDown is making the button darker
- MouseLeftButtonUp is sending me to next screen
The problem:
If i "spam" or sometimes just click 2-3 (we say 3 times in this case) times on the button, it's start loading the next screen. When the next screen is shown, two mouse clicks is left in the queue and if the mouse is over another new button at the second screen, this is clicked on.
I tried with stuff like:
void LayoutRoot_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
Mouse.OverrideCursor = Cursors.Wait;
if (this.IsVisible && this.IsLoaded)
OnButtonPatient();
}
but both properties is set to true.
I guess thats right since i can see the button when the mouse event triggers.
The events can be explained like:
3 mouse clicks
mouse cursor = waiting cursor
next screen is loaded
mouse cursor = normal
mouse cursor = waiting cursor
next button is clicked
How can i handle this?
I dont want mouse event that happend on a previously screen follow on to my next screen.
Greetings!
I tried a simple example using StackPanel as control. Although I am not sure why you are not using Button Click event if you are using a button (Why move on ButtonUp?)
private int count = 0;
private void StackPanel_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (count == 0 && (sender as StackPanel).IsMouseOver)
{
Mouse.OverrideCursor = Cursors.Wait;
count++;
}
e.Handled = true;
}
private void StackPanel_OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
if (count == 1 && (sender as StackPanel).IsMouseOver)
{
Mouse.OverrideCursor = Cursors.Arrow;
count++;
}
e.Handled = true;
}
I would suggest checking the IsMouseOver property on your first window/screen when the MouseUp event fires. This would let you filter out events where the new window is blocking the first.
void LayoutRoot_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
Mouse.OverrideCursor = Cursors.Wait;
if (this.IsVisible && this.IsLoaded && this.IsMouseOver)
OnButtonPatient();
}
I have the following problem: I have a panel which has a specific color, say red.
When the user presses his mouse, the color of this panel gets stored in a variable. Then the user moves, his mouse still pressed, over to another panel. When he releases the mouse there, this panel should get the background color of the first that had been stored in the variable. My code looks something like this:
public Color currentColor;
private void ColorPickMouseDown(object sender, MouseEventArgs e)
{
Panel pnlSender = (Panel)sender;
currentColor = pnlSender.BackColor;
}
private void AttempsColorChanger(object sender, MouseEventArgs e)
{
Panel pnl = (Panel)sender;
pnl.BackColor = currentColor;
}
I need to identify the sender first because there are many possible panels that can trigger this event. The first MouseDown method works totally fine, the color is stored nicely in the variable. The secon one however doesn't even get triggered when the user does what I described above. When the ser clicks on the second panel, it works (there is an MouseUp part in a click aswell I guess).
What's wrong here? Why is the event not triggered when the user holds the mouse key down before?
(This answer assumes you are using Windows Forms.)
It could be that you need to capture the mouse by setting this.Capture = true in the MouseDown of the source control. (See Control.Capture)
If you did that, the source window would get the MouseUp event, and it would be the source window that had to determine the destination window under the mouse coords. You can do that using Control.GetChildAtPoint() (see this answer on Stack Overflow).
Use Windows Forms Drag and Drop Support Instead! <- Click for more info
I'm going to suggest you bite the bullet and use the .Net Drag and Drop methods to do this. It requires some reading up, but it will be much better to use it.
You start a drag in response to a MouseDown event by calling Control.DoDragDrop().
Then you need to handle the Control.DragDrop event in the drop target control.
There's a few more things you might need to do to set it up; see the Control.DoDragDrop() documentation for an example.
(For WPF drag and drop support, see here.)
when your mouse enter the target control , mouse down triggerd ang get target BackColor! you need add an boolean flag to your code :
public Color currentColor;
bool flag=false;
private void ColorPickMouseDown(object sender, MouseEventArgs e)
{
if(flag==false)
{
flag=true
Panel pnlSender = (Panel)sender;
currentColor = pnlSender.BackColor;
}
}
//assume mouse up for panles
private void AttempsColorChanger(object sender, MouseEventArgs e)
{
if(flag==true)
{
Panel pnl = (Panel)sender;
pnl.BackColor = currentColor;
flag=flase;
}
}
and also you need change your flag in mouseMove( if )
As I mentioned in my comment Mouse Events are captured by the originating control, You would probably be better off using the DragDrop functionality built into Windows Forms. Something like this should work for you. I assigned common event handlers, so they can be assigned to all of your panels and just work.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void panel_MouseDown(object sender, MouseEventArgs e)
{
((Control)sender).DoDragDrop(((Control)sender).BackColor,DragDropEffects.All);
}
private void panel_DragDrop(object sender, DragEventArgs e)
{
((Control)sender).BackColor = (Color)e.Data.GetData(BackColor.GetType());
}
private void panel_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
}
I know it's an old question but I had the same issue and none of the above answers worked for me. In my case I had to handle the MouseMove event in the target control and check for the mouse to be released. I did set 'BringToFront' on my target panel just in case that helped at all.
public Color currentColor;
private void ColorPickMouseDown(object sender, MouseEventArgs e)
{
Panel pnlSender = (Panel)sender;
currentColor = pnlSender.BackColor;
}
private void panelTarget_MouseMove(object sender, MouseEventArgs e)
{
//the mouse button is released
if (SortMouseLocation == Point.Empty)
{
Panel pnl = (Panel)sender;
pnl.BackColor = currentColor;
}
}
I have some context menu items that are not clickable. They just report the status of something. I don't like how the cursor still appears like they're clickable though.
Anyway to change this?
There isn't a Cursor Field like one would expect.
Handle the MouseMove event of the whole ToolStrip and check if the current mouse location is between the toolStripItem.Bounds. if so, change ToolStrip.Cursor
Amiram sent me in the right direction. You can't set the Cursor on the "ToolStripMenuItem" you have to set it on the parent ContextMenuStrip.
As for the mouse events, that has to go on the ToolStripMenuItems. As the MouseMove event is not fired when the Mouse is over ToolStripMenuItems.
// Init Code
contextMenuStrip1.Cursor = Cursors.Hand;
recentMessagesToolStripMenuItem.MouseLeave += new EventHandler(SetCursorToHandOn_MouseLeave);
recentMessagesToolStripMenuItem.MouseEnter += new EventHandler(SetCursorToArrowOn_MouseEnter);
private void SetCursorToArrowOn_MouseEnter(object sender, EventArgs e)
{
contextMenuStrip1.Cursor = Cursors.Arrow;
}
private void SetCursorToHandOn_MouseLeave(object sender, EventArgs e)
{
contextMenuStrip1.Cursor = Cursors.Hand;
}