接受表单元素作为方法参数? [英] Accepting Form Elements As Method Arguments?

查看:24
本文介绍了接受表单元素作为方法参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个方法,它会截取传递的表单元素的屏幕截图并将其打印出来.我面临着一些挑战.我希望能够使这个方法足够通用以接受几乎任何类型的表单元素.我将元素"参数设置为对象"类型.我想我还需要传递一个类型"参数,或者有没有办法在传递后确定对象是什么类型?

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!

推荐答案

我猜你的 element 应该是 Control,并且每个 ControlDrawToBitmap() 方法,你可以用它来截图".

I guess that your element should be Control, and every Control has DrawToBitmap() method that you can use to take 'screenshot' of it.

所以你可以忘记所有类型参数,因为你不需要它,因为多态.

So you can forget all about type parameter, because you won't need it, because of polymorphism.

这篇关于接受表单元素作为方法参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆