Taking form elements as method arguments?

I am writing a method that will take a screenshot of the submitted form element and print it. There are several issues that I have encountered. I want to be able to make this method general enough to accept almost any element of the form. I set the "element" argument to input "object". I think I will also need to pass a type argument, or is there a way to figure out what type of object is after passing it?

static public void PrintFormElement(object element, ?type?){

}

Am I approaching this problem correctly? Any advice would be greatly appreciated!

+5
source share
4 answers

, element Control, Control DrawToBitmap(), "".

, , , - polymorphism.

+3

, is/as, GetType. , . ?

, Control object.

+4

, object , Control. , is.

+1
source

Expand answers, suggesting to use the base class Control. I would make your function an extension to avoid creating ASDFHelper, ASDFUtility and other classes, static methods.

static public void PrintFormElement(this Control element){
    element.DrawToBitmap();
}

Then it can be called in this way.

new TextBox().PrintFormElement();
+1
source

All Articles