C # instance passing different types of Windows.Forms
I have a function that takes a parameter from a type System.Windows.Forms.Label
, so I can pass a specific instance of the shortcut as well.
But I want this setting to be as flexible as possible. For example, I also want to be able to pass a Textbox-Instance as a parameter to a function, or whatever , that provides a property .Text
andinvokeable
.
So, I have this:
public void Test(Label targetLabel) { //stuff }
But I want something as flexible as possible, something like
public void Test(object target) { //stuff }
-> but how can i convert target
to the right type which is
a) invokeable
b) has the property .Text
- otherwise an exception or something else?
Take something like System.Windows.Forms.Control
.
Control is a class that first declares the .Text property and also implements (which invokes the methods ). ISynchronizeInvoke
*Invoke
source to share