求一段c#转vb代码,c#中是as 转为TryCast出错

cpf_cn 2013-12-10 08:45:04
 public C1DemoForm Run(string typeName, string title, string description)
{
Control.ControlCollection items = panelDemo.Controls;
Type t = Type.GetType(typeName);
loadedCode = false;
try
{
demoForm = t.Assembly.CreateInstance(t.FullName) as C1DemoForm;
c1DockingTabPage_Demo.Text = title;
demoForm.DisplayIn(items);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return demoForm;
}

用c# to vb.net 转成vb代码后
demoForm = TryCast(t.Assembly.CreateInstance(t.FullName),Frm_blank)
这句demoForm返回的是nothing,demoForm.DisplayIn这句就无法执行了。
提示为 “未将对象引用设置到对象的实例”,无法进入执行demoform中的displayin。开始以为是itmes的问题,后来发现是demoform为nothing了那句没转换成功应该是。

 Public Function Run(typeName As String, title As String, description As String) As Frm_blank       

Dim items As Control.ControlCollection = panelDemo.Controls
Dim t As Type = Type.[GetType](typeName)
loadedCode = False
Try
demoForm = TryCast(t.Assembly.CreateInstance(t.FullName),Frm_blank)
demoForm.DisplayIn(items)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Return demoForm
End Function

正在学习新技术,请大家不吝指教呀。
注:Frm_blank 和 C1DemoForm都是个空白窗体。panelDemo.Controls是个现在代码所在窗体的实体panel控件,里面没其他控件,通常返回0,
...全文
176 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
cpf_cn 2013-12-11
  • 打赏
  • 举报
回复
找到原因了,原因也不是这段代码的事,是我需要在设计映射窗体的时候,就得先做好Inherits Form_blank继承过来
wind_cloud2011 2013-12-10
  • 打赏
  • 举报
回复
threenewbee 2013-12-10
  • 打赏
  • 举报
回复
try ctype
cpf_cn 2013-12-10
  • 打赏
  • 举报
回复
vb.net代码应该如何修改才能正确呀?

16,550

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧