Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accepting Form Elements As Method Arguments?

Tags:

c#

winforms

I am writing a method that will take a screenshot of a passed form element, and print it out. There are a few challenges I am facing. I want to be able to make this method generic enough to accept just about any type of form element. I set the "element" argument to type "object". I think I will also need to pass a "type" argument or is there a way to figure out what type the object is after it is passed?

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

}

Am I approaching this problem the right way? Any advice would be appreciated thanks!

like image 860
sooprise Avatar asked Feb 11 '11 19:02

sooprise


People also ask

Why should you use form elements instead of custom coding data inputs in Javascript?

If something is a form, use a form element. This helps assistive devices like screen readers better understand the content of the page and give the person using them more meaningful information.

How do we access the elements of a form?

In order to access the form element, we can use the method getElementById() like this: var name_element = document. getElementById('txt_name'); The getElementById() call returns the input element object with ID 'txt_name' .

Which method should be used if we do not want to display the form data in the request URL?

Appends form-data inside the body of the HTTP request (data is not shown in URL)

Which type of form submission particularly uses the GET method?

Since GET appends the form data to the current URL, it can only be used where the contents of the submission (including the complete URL) will result in a string that is 2048 characters long, or less. This is the maximum length of a URL. GET can only be used to send ASCII data.


1 Answers

You can find out what type something is either using the is/as operators, or using GetType. It's usually a bit of a design smell if you have to use them though. What are you planning to do that's type-specific?

If you're talking about visual elements, you might want to use Control instead of object.

like image 113
Jon Skeet Avatar answered Oct 03 '22 16:10

Jon Skeet