I have 2 problems:
"Which Button called this form?" (short version)
I can not touch the button or button's form
Why do I want this?
I have many forms and need to know how the user got there. If I could get the Form (not the button) it may also solve the problem.
Long version: I need to copy some properties of source form/button to the new one without do it manually and I intend to use it later on Exception reporting to catch more info
Initially, i tried to do a "newForm.Caller = this;" on each button but there are 200+ forms and lots of buttons on each.
All forms and it's buttons are custom controls so I can do things there.
Tried things
I tried to do things with StackFrames and reflection at form constructor but don't work (889310)
I found this 10401190 for JAVA but it can't help
I thought I could use the OnClick override to store the last button instance in a static place in buttons/forms class then get it in the form constructor but seems to be the worst solution. (Many things open forms and the culprit would be the last button pressed)
The problem get worse when other things open Forms and I lost the reference (DataGridVewButton, timers, linked label, ...)
EDIT1: (oɔɯǝɹ) Another detail, forms can be called from external Plugins. So again I don't have acesses to the code to change it.
EDIT2: Example (Graham Bass,ShreyasKapur) FormA has a ButtonA that when clicked shows FormB FormA inherits FormBase Button inherits ButtonBase FormB inherits FormBase
I can NOT change FormA neither ButtonA codes, only FormBase and ButtonBase codes
Edit3: (Bradley Uffner) ShowDialog() forms have the Owner property that solves part of the problem. Thanks Bradley, I forgot about that! Unfortunately, all existing code uses the parameterless constructor. "Displays this form as a modal dialog box with no owner window" (1)