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,
------解决方案--------------------
try ctype
------解决方案--------------------
