类型转换文本框 [英] Type Casting TextBox

查看:65
本文介绍了类型转换文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我在C#中进行了abt转换,下面让我解释一下.

我有第三方类,该类返回System.Window.Form.Textbox.


我想将此TextBox分配给My custom textbox Class.

以下是我的自定义课程的示例


Hi all ,


I have dout abt casting in C# let me explain .

I have third party class which return a System.Window.Form.Textbox.


I want to assign this TextBox to My custom textbox Class .

Below is the Eg of my Custom Class


public class TestTextbox : TextBox
 {
     public override Font Font { get { return base.Font; } set { base.Font = value; } }

 }



但我无法投射此



but i m not able to cast this

TestTextbox txt = (TestTextbox)(Some method Which returns System.Window.Form.Textbox );



我缺少什么,


在此先感谢.



What im missing ,


Thanks in Advance.

推荐答案

您是从TextBox派生的.结果,您不能强制将父级强制转换为子级.
这段代码根本行不通.

你不能垂头丧气. TestTextBox 将具有一些TextBox 可能没有的其他方法.
结果,如果您能够向下转换,则这些方法将不可用.
You are deriving from TextBox. As a result, you cannot force a cast of a parent into a child class.
This code simply won''t work.

You cannot downcast. TestTextBox will have some additional methods which TextBox may not have.
As a result, if you were able to downcast, those methods would not be available.


您好,

请尝试,

Hi,

Please try,

TestTextbox txt =(method Which returns System.Window.Form.Textbox) as  TestTextbox;



希望这会有所帮助.



Hope this helps.


这篇关于类型转换文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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