This question already has an answer here:
Is there any event that fires when WPF animation ends?
(1 answer)
Closed 9 years ago.
Is there a possibility to register a function to a Animated Usercontroll that is called when the animation is over?
I have a Usercontroll-Animation I start by calling .BeginAnimation(propdp, animation);
How to call another function when the Animation is over?
There is a Timeline.Completed Event that you can use. You can either set it in XAML, or in C# on a Storyboard instance. The linked page has a full working example that you can view.
The handler used is the default EventHandler delegate:
private void StoryboardCompleted(object sender, EventArgs e)
{
// the Storyboard has stopped
}
UPDATE >>>
Although the Completed event can be set on a Storyboard instance, it is in fact defined in the Timeline class. As Timeline is the base class for all AnimationTimeline classes, this means that you can also attach a handler to the Completed event from the AnimationTimeline object that you are passing into the BeginAnimation event.
There is an animation.Completed event.
Related
This question already has answers here:
Parent Control Mouse Enter/Leave Events With Child Controls
(6 answers)
Closed 4 years ago.
I am currently working on a subclass to the WinForms NumericUpDown Control. But because they built it so it contains multiple sub-controls, it messes up the MouseLeave and MouseEnter event.
When the mouse moves into the controls bounds, MouseEnter will fire followed by MouseExit when the mouse moves over one of the subcontrols (e.g. the Up and Down Arrow Buttons). In addition to that, MouseExit will not fire at all sometimes, especially likely when moving the mouse out of control bounds fast...
How can I get the events to fire properly or work around this problem?
EDIT:
Here's a simple code example:
public class TMNumericUpDownControl : NumericUpDown
{
public TMNumericUpDownControl()
{
MouseEnter += MouseEnterHandler;
MouseLeave += MouseLeaveHandler;
}
private void MouseEnterHandler(object sender, EventArgs e)
{
Debug.WriteLine("entered");
}
private void MouseLeaveHandler(object sender, EventArgs e)
{
Debug.WriteLine("Left");
}
}
Okay I just got it myself.
I noticed I can just access the NumericUpDowns child controls via NumericUpDownName.Controls and assign the event handlers to them as well. Thought this wouldn't be possible before...
That means this is in fact a duplicate Question.
This question already has answers here:
RoutedEventArgs.Source vs Sender
(4 answers)
How do C# Events work behind the scenes?
(2 answers)
Closed 5 years ago.
I don't understand what event parameters do in C#. Let's say we have a button called CoffeeButton, and clicking on it takes you to another Page called Coffee using a Frame called myFrame.
This is my code:
private void CoffeButton_Click(object sender, RoutedEventArgs e)
{
MyFrame.Navigate(typeof(Coffee));
}
What does object sender and RoutedEventArgs e do in this case?
Examples would be great!
Normally, "sender" will be a reference to whatever object fired the event. So if, for example, you have more than one Button that all wire into the same button_Click handler function, the sender object would be a reference to whichever actual Button object was clicked.
The EventArgs object that's normally passed in as the second parameter is used for different things depending on the context. Generally, it's used to pass you additional information related to the event that happened. For example, in this case, the RouteEventArgs object provides a RoutedEvent property that you can look at if you need to.
This question already has answers here:
C# Windows Forms code not working - Attach Event to button
(2 answers)
Forms not responding to KeyDown events
(3 answers)
Closed 7 years ago.
It is my second day doing c#...don't judge please. I have read other threads but they did not help.
I have this code:
private void listView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
MessageBox.Show("aa");
}
}
which is not working.
What am I doing wrong?
The issue is that you haven't told the ListView to actually use the event. To do this you have to assign the method to the required event. there are two ways to do this. Either select the ListView and open the Properties tab go to events and double click on the one you want. (Visual studio will automatically put the event out for you). Or in the constructor of the form or elsewhere you can manually assign it. In your case it would look like...
listView1.KeyDown += listView1_KeyDown;
Note you don't have to use a name similar to what visual studio would automatically produce. You can name your method whatever you want as long as the method signature matches the event. This is nice if you have multiple list boxes and want to use the same method to handle all of them. For example you could do something like.
listView2.KeyDown += listView1_KeyDown;
I suggest reading up on how events work in c#.
This question already has answers here:
How to ensure that async method finished work?
(2 answers)
Closed 8 years ago.
I handle user click on a button like:
private void btnScanDirectory_Click(object sender, EventArgs e)
{
// some code
}
What events are fired after btnScanDirectory_Click() finishes it's work ?
The reason I'm asking, that in btnScanDirectory_Click() I create a new Thread() in which I "fire and forget" tree.BeginInvoke() method that updates a TreeView.
So even when worker thread closes, the main thread is still handling those multiple BeginInvoke() calls, and when I access tree like
tree.ExpandAll();
in the same btnScanDirectory_Click() - it has no effect.
I couldn't find a way to "wait in main thread while all EndInvoke() methods are called", so I want to try tree.ExpandAll() in the event that fires after btnScanDirectory_Click() is finished.
Check out this page. It has the following details and I think this is what you're asking for: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.mouseclick.aspx
Depressing a mouse button when the cursor is over a control typically raises the following series of events from the control:
MouseDown event.
Click event.
MouseClick event.
MouseUp event.
I don't know I should ask this question here or not But anyhow I am asking..
Suppose I have a asp button control, and I am using both Delegate and Click event for that button which will fire first?
On Init:
btn1.Click += delegate{ Save(); };
On Click Event:
protected void btn1_Click(object sender, EventArgs e)
{
Save1();
}
I want to know which will execute/raised first?
btn1_click is auto attached with click event in InitializeComponent() function at design time. InitializeComponent(0 function is called from constructor of form. It's default snippet of winforms.
You can not call the following statement before calling the InitializeComponent(), otherwise it will give error "Object reference not set to an instance of an object." Till this time the control is not intialised.
btn1.Click += delegate{ Save(); };
So the order of execution will be first the btn1_Click event and then the save function attached with delegate.
I think it has to do with the order in which they are assigned. Normally a method called btn1_Click will not fire until you bind it either in codebehind or in the ASPX file you are using.
I am guessing you are tying the btn1 to the btn1_Click method in the ASPX, that will probably fire first, but why not just test it? Put breakpoints on both lines and see which is hit first?
Event is not "executed", event is raised, so the execution will be of your event-handler which is btn1_Click on click esplicitly made by client.