This question already has answers here:
Manual editing of *.designer.cs file
(5 answers)
Closed 8 years ago.
I have a custom control and I subscribe to an event in the InitializeComponent method. Whenever I go into the designer and move the control or make any changes, the initialize component will rewrite and remove the subscription to the event. Is there any way to avoid this? I would rather not just subscribe in the Load event of the form, but I am unfamiliar with how this method gets dynamically created.
This is why you don't edit the designer code. It's specifically designed to not maintain these types of changes.
You should be subscribing to the event in the object's constructor, load event, or some similar location.
Related
This question already has answers here:
NumericUpDown differentiate up and down
(2 answers)
Closed 9 months ago.
Is there a way to detect with the Numeric Up-down control to see if the Up or Down button is pressed without coding?
I know I could keep track of the current value and write some code in the method ValueChanged. I was just thinking maybe there is an easier/shorter way to do this
If you want to track specifically the buttons being used and not the value being changed directly you can create your own UserControl that inherits from NumericUpDown and override the UpButton() and DownButton() methods. Otherwise if you want to track all value changes, using the ValueChanged event is the best way to cover all ways of changing the value, including programatically.
This question already has answers here:
Determining when a WPF window is being moved
(3 answers)
Closed 7 years ago.
In need to get whether or not my WPF application's Window is currently in the process of being dragged or re-sized. I need to prevent a specific action from happening if this is the case.
I need to check if the window is currently in any situation where the mouse is being held down on the the part of the window that can preposition it.
I am assuming there is probably some information somewhere on the
Application.Current.MainWindow
property. Or maybe there is a few events that I need to keep track of to have this information.
Any ideas how I would do this? Thanks in advance.
Subscribe to the LocationChanged event.
Set the ResizeBegin and ResizeEnd event. They should both fire when the application is being moved, and disable your feature when Begin is called and until End finishes.
EDIT: Just realized this is WPF, in which case check this article: Determining when a WPF window is being moved
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Detect change of resolution c# WinForms
I have an application written in C# where my window is docked to the edge of the screen.
I need to know where I can find the event if the resolution has changed so I can call the Dock method so I can repaint my window.
On the form object I can only see the SystemColorsChanged event.
You're looking for the SystemEvents.DisplaySettingsChanged event.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Calling A Button OnClick from a function
I want to do button click event automatically .I want code for button click event without manual clicking of the button.
I think you're looking for Button.PerformClick();
button1.PerformClick();
I have two things to say:
You should modify your applications to use IObservables for the events in such a way that you can mock the events allowing for better testing.
If you want to automate UI interaction, There is a DLL for that thanks to DataDink
This question already has answers here:
Is it bad to not unregister event handlers?
(2 answers)
Closed 9 years ago.
I have a Winform, i have added a few controls like Textbox, buttons.
I subscribed to the textbox Changed event, teh button click event.
The designer automatically adds the += statements i.e subsribtion of events in the
designer.cs file.
My question is should we add the unregisterig of these events in the dispose function ?
is it necesssary, or will there be any leak if i do not unregister.
Or is it that .NET takes care of it.
Refers to following link:
Is it bad to not unregister event handlers?
This is not required to unregister events that is subscribed on same class.
If your WinForm is the only one that is consuming/subscribing to it, then you dont need to worry about unsub.