I got a picture box that got an original image in my program. When i hover with my mouse over it it changes picture to another picture and when i leave it changes back.
But..
There is such a delay to change to the right picture if i hover over it or not. It takes like 1 second before it changes, What should i change to improve the speed of the change? This is the code i am using at the moment:
private void pictureBox1_MouseHover(object sender, EventArgs e)
{
pictureBox1.Image = ABC_Bok.Properties.Resources.BokVänsterhörn_1;
}
private void pictureBox1_MouseLeave(object sender, EventArgs e)
{
pictureBox1.Image = ABC_Bok.Properties.Resources.BokVänsterhörnet;
}
This is the third time today that I've seen this issue. MouseHover is raised when the mouse pointer STOPS OVER a control. If you want something to happen as soon as the mouse pointer goes over the control then you want MouseEnter, just as you're using MouseLeave for the change back again.
Related
I am trying to write a program to manage tasks from my team. For this I use drag&drop capable custom UserControls. I try the following: When the UserControl is dragged over a slot, the control should then snapped into the slot. The problem seems to be that the slot does not get the events like "MouseEnter" or "DragEnter". Does anyone know a workaround, or is it possible to pass events down?
I think I just need a little push in the right direction.
Edit:
Main functionality:
The user control, let's call it task, should be docked into a slot when released over it.
A slot consists of properties and a panel. The task should appear in the panel.
Bonus:
A task, should dock into the different slots while dragging. So that it is always visible where the 'task' is placed when it is released.
I hope this shows what I am trying to do.
Edit 2
To clarification: I use the "MouseDown", "MouseUp" and "MouseMove" for the drag an drop.
Here you can see my Example the blueish panel is my task. The white the slot it should snap to.
On the second picture I drag the Task over the Slot panel. The mouse is not visable here but it's right beside the "K" of task.
i have added for testing the following code. Which should color the panel inside the slot in a color if an event is raised. But the color stays white.
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
this.panel1.BackColor = Color.Black;
}
private void panel1_MouseEnter(object sender, EventArgs e)
{
this.panel1.BackColor = Color.Green;
}
private void panel1_DragEnter(object sender, DragEventArgs e)
{
this.panel1.BackColor = Color.Yellow;
}
private void panel1_DragDrop(object sender, DragEventArgs e)
{
this.panel1.BackColor = Color.Violet;
}
Why I don't get events on the Slotpanel?
I hope that this helps to understand my problem.
I know there are many questions on this, but I just can't get it to work. I have this event:
private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
e.Graphics.DrawRectangle(new Pen(selectionBrush, 1), selectionRectangle);
}
It works as it should. Draws a colored rectangle over the image I put inside picture box. But after I draw that rectangle, I want to erase it. I basically use it as selection area for cropping the image. Is there a way that I can erase the rectangle that I have drawn? Thanks.
Here is where I want to erase the rectangle:
private void button1_Click(object sender, EventArgs e)
{
//here are some examples of what I have tried
pictureBox1.Invalidate();
Invalidate();
}
Your Paint routine has a call to DrawRectangle. Then you invalidate the rectangle. At that point, your paint routine will get called again, and, if your code to draw the rectangle is still there, it will get redrawn. You need to make it so the DrawRectangle call no longer gets called once you don't need it any more (with an if statement or something).
You also probably want to inflate the size of the invalidation rectangle by one pixel all around to make sure you don't leave any bread crumbs behind
I have an Image control running in my MainWindow.xaml, I was wondering if I can get the X and Y coordinates to the pixel clicked from the RoutedEventArgs on the MouseUp event for the control? I don't need the color or anything at that pixel, I would just like to know where that pixel was. Thank you for the help.
You can try handling the MouseLeftButtonUp event:
private void image1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e){
Point pos = e.GetPosition(image1);
}
I have placed my Picture Box in the center of my Form, but I don't know how to make it move with the use of buttons.
I need to use a Class Library in the process, so my guess is that using if structure is out of the question?
Make a picture box and a button
This code for the click of a button should move your box 10 left of its current position:
private void button1_Click(object sender, EventArgs e)
{
this.pictureBox1.Left = this.pictureBox1.Left - 10;
}
You can also use this.pictureBox1.Top to move it vertically.
Make it an addition to .Left or .Top to make it go the opposite direction.
That should give you a nice start!
I have WebBrowser class and image loaded in it. After mouse click on the browser, I need to get mouse position - what is the best way to do it?
this is actually pretty simple if your just looking for the screen coordinates.
// this probably should be in your form initialization
this.MouseClick += new MouseEventHandler(MouseClickEvent);
void MouseClickEvent(object sender, MouseEventArgs e)
{
// do whatever you need with e.Location
}
if your strictly looking for the point in the browser, you need to consider the functions
browser.PointToClient();
browser.PointToScreen();