....但是我不接受,也不是Dim f As New TypeOf(Me)。 我想把CreateAndShow放在一个基本形式然后继承 它仍然可以使用CreateAndShow方法。 有什么建议吗?坦克! :o) MOJO 解决方案 这是一个好主意,所以我尝试解决它练习。好的 新闻是有效的。 坏消息是我已经学习.NET大约一周了,所以我'' m 相当尴尬地告诉你我是怎么做到的。但是这里是: Dim s1 As String = Me.ToString ''s1的格式为WindowsApplication1.Form1,Text:Form1 ''现在删除那个不是类名的部分。 Dim i1 As Integer = InStr(s1,",") 如果i1 0那么s1 = Mid(s1,1,i1-1) ''注意:不能使用上面的左(s1,i1-1) - 由于某种原因VB认为 我正试图 ''访问Me.Left而不是! < grrr> Dim objNewForm As Object = Activator.CreateInstance(Type.GetType(s1)) Dim frm As Form = DirectCast (objNewForm,表格) frm.Show() 好的,我还做了更多,这个版本是远没那么尴尬了! 享受: DirectCast(Activator.CreateInstance(Type.GetType(M e.GetType.ToString)), 表格。显示() te * *****@hotmail.com 写道: 如果i1 0则s1 = Mid(s1,1,i1-1) ''注意:上面不能使用Left(s1,i1-1) - 出于某种原因,VB认为 我正在尝试 ''访问Me.Left! <哎呀> 您可以使用以下行: 进口VB = Microsoft.VisualBasic $ b代码前的$ b,以便您可以使用VB.Left(s1,i1-1)。这告诉你 你想用VB作为Microsoft.VisualBasic的缩写。 另外,如果你使用Option Strict On,它会告诉你当事情不匹配 他们应该的方式。 HTH Andrew Hi, Instead of doing this....Public Class Form1Public Shared Sub CreateAndShow()Dim f As New Form1f.Show()End SubEnd Class I would like to make it generic by doing something like... Public Class Form1Public Shared Sub CreateAndShow()Dim f As New Mef.Show()End SubEnd Class .... but "Me" is not accepted, neither is "Dim f As New TypeOf(Me)". I would like to put the CreateAndShow in a base form and then inherit fromit and still be able to use the CreateAndShow method. Any suggestions? TANKS!!! :o) M O J O 解决方案 That''s a good idea, so I tried solving it as an exercise. The goodnews is that it works. The bad news is that I''ve been learning .NET for about a week, so I''mrather embarassed to show you how I did it. But here goes: Dim s1 As String = Me.ToString'' s1 is in the format "WindowsApplication1.Form1, Text: Form1"'' Now remove the part that isn''t the class name.Dim i1 As Integer = InStr(s1, ",")If i1 0 Then s1 = Mid(s1, 1, i1 - 1)'' Note: Can''t use Left(s1, i1-1) above - for some reason VB thinksI''m trying to'' access Me.Left instead! <grrr>Dim objNewForm As Object =Activator.CreateInstance(Type.GetType(s1))Dim frm As Form = DirectCast(objNewForm, Form)frm.Show() Ok, I worked on it some more, and this version is far less embarrasing!Enjoy: DirectCast(Activator.CreateInstance(Type.GetType(M e.GetType.ToString)),Form).Show() te******@hotmail.com wrote: If i1 0 Then s1 = Mid(s1, 1, i1 - 1) '' Note: Can''t use Left(s1, i1-1) above - for some reason VB thinksI''m trying to '' access Me.Left instead! <grrr>You can use the line: Imports VB = Microsoft.VisualBasic before your code so that you can use VB.Left(s1, i1-1). That tells it thatyou want to use VB as an abbreviation for Microsoft.VisualBasic. Also, if you use Option Strict On, it will tell you when things don''t matchup the way they should. HTH Andrew 这篇关于创建新的“我”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-23 04:21