Windows窗体设计器生成的代码 [英] Windows Form Designer generated code

查看:142
本文介绍了Windows窗体设计器生成的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在2003年大约一年前完成的项目中,我被告知要将下面的

SocketWrench代码添加到Windows窗体设计器生成的代码

区域,如下所示。


#Region" Windows窗体设计器生成的代码


Public Sub New()

MyBase.New()


' 'Windows窗体设计器需要此调用。

InitializeComponent()

''在InitializeComponent()调用后添加任何初始化


socket = New SocketWrenchCtl.SocketWrench

如果socket.Initialize(" ELMO")< 0那么

抛出新的System.Exception(" ;无法初始化控制)

结束如果


结束子


我正在完成2005年程序现在非常相似我复制了许多旧的2003程序的部分,但我不知道如何使用这个

代码。我知道2005年保留了Windows窗体设计器生成的代码

某处,但我真的不想在那里添加它,除非它真的是必要的b / b
。显然它可以进入Form1_Load,但我不确定'

是否合适。我应该在2005年把它放在哪里?优点和缺点?

In a project done in 2003 about a year ago I was told to add the
SocketWrench code below into the Windows Form Designer generated code
area as shown below.

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

''This call is required by the Windows Form Designer.
InitializeComponent()

''Add any initialization after the InitializeComponent() call

socket = New SocketWrenchCtl.SocketWrench
If socket.Initialize("ELMO") <0 Then
Throw New System.Exception("Unable to initialize control")
End If

End Sub

I''m completing a 2005 program now that was so similar I copied many
parts of the old 2003 program but I''m not sure what to do with this
code. I know 2005 keeps the Windows Form Designer generated code
somewhere but I really don''t want to add it there unless it is really
necessary. Apparently it can go in Form1_Load but I''m not sure that''s
appropriate. Where should I put it in 2005? Pros and cons?

推荐答案

在Visual Studio 2005中,设计器生成的代码通常位于

seperat文件中。如果您有一个名为MyForm的表单,您将获得3个文件:

MyForm.vb,MyForm.Designer.vb,MyForm.resx。由

设计器生成的代码在MyForm.Designer.vb中。双击一个并有一个

看看你是否需要在那里添加它。


cj写道:
In Visual Studio 2005, the designer generated code usually goes in a
seperat file. If you have a form named "MyForm", you''ll get 3 files:
MyForm.vb, MyForm.Designer.vb, MyForm.resx. The code generated by the
designer goes in MyForm.Designer.vb. double-click on one and have a
look to see if you need to add it there.

cj wrote:

在2003年大约一年前完成的项目中,我被告知要将下面的

SocketWrench代码添加到Windows窗体设计器生成的代码中

区域如下图所示。


#Region" Windows窗体设计器生成的代码


Public Sub New()

MyBase.New()


' 'Windows窗体设计器需要此调用。

InitializeComponent()

''在InitializeComponent()调用后添加任何初始化


socket = New SocketWrenchCtl.SocketWrench

如果socket.Initialize(" ELMO")< 0那么

抛出新的System.Exception(" ;无法初始化控制)

结束如果


结束子


我正在完成2005年程序现在非常相似我复制了许多旧的2003程序的部分,但我不知道如何使用这个

代码。我知道2005年保留了Windows窗体设计器生成的代码

某处,但我真的不想在那里添加它,除非它真的是必要的b / b
。显然它可以进入Form1_Load,但我不确定'

是否合适。我应该在2005年把它放在哪里?优点和缺点?
In a project done in 2003 about a year ago I was told to add the
SocketWrench code below into the Windows Form Designer generated code
area as shown below.

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

''This call is required by the Windows Form Designer.
InitializeComponent()

''Add any initialization after the InitializeComponent() call

socket = New SocketWrenchCtl.SocketWrench
If socket.Initialize("ELMO") <0 Then
Throw New System.Exception("Unable to initialize control")
End If

End Sub

I''m completing a 2005 program now that was so similar I copied many
parts of the old 2003 program but I''m not sure what to do with this
code. I know 2005 keeps the Windows Form Designer generated code
somewhere but I really don''t want to add it there unless it is really
necessary. Apparently it can go in Form1_Load but I''m not sure that''s
appropriate. Where should I put it in 2005? Pros and cons?


windows表单设计器生成的代码现在位于一个单独的文件中。

如果单击显示所有文件 ;在解决方案资源管理器中,你将获得
将看到myForm.Designer.vb。


除非你的代码是一次性代码,否则你永远不应该改变它。

文件,因为无论何时更改表单都会重新生成。


我建议将代码放在Form_Load例程中。


Robin S.

--------------------------------------- ------


" cj" < cj@nospam.nospamwrote in message

news:u5 ************** @ TK2MSFTNGP03.phx.gbl ...
The windows form designer-generated code is now in a separate file.
If you click on "Show All Files" in the Solution Explorer, you
will see myForm.Designer.vb.

Unless your code is throwaway code, you should never change that
file, because it is regenerated whenever you change the form.

I recommend putting the code in the Form_Load routine.

Robin S.
---------------------------------------------

"cj" <cj@nospam.nospamwrote in message
news:u5**************@TK2MSFTNGP03.phx.gbl...

在2003年大约一年前完成的项目中,我被告知要将下面的

SocketWrench代码添加到Windows窗体设计器生成的代码中

区域如下图所示。


#Region" Windows窗体设计器生成的代码


Public Sub New()

MyBase.New()


' 'Windows窗体设计器需要此调用。

InitializeComponent()

''在InitializeComponent()调用后添加任何初始化


socket = New SocketWrenchCtl.SocketWrench

如果socket.Initialize(" ELMO")< 0那么

抛出新的System.Exception(" ;无法初始化控制)

结束如果


结束子


我正在完成2005年程序现在非常相似我复制了许多旧的2003程序的部分,但我不知道如何使用这个

代码。我知道2005年保留了Windows窗体设计器生成的代码

某处,但我真的不想在那里添加它,除非它真的是必要的b / b
。显然它可以进入Form1_Load,但我不确定'

是否合适。我应该在2005年把它放在哪里?优点和缺点?
In a project done in 2003 about a year ago I was told to add the
SocketWrench code below into the Windows Form Designer generated code
area as shown below.

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

''This call is required by the Windows Form Designer.
InitializeComponent()

''Add any initialization after the InitializeComponent() call

socket = New SocketWrenchCtl.SocketWrench
If socket.Initialize("ELMO") <0 Then
Throw New System.Exception("Unable to initialize control")
End If

End Sub

I''m completing a 2005 program now that was so similar I copied many
parts of the old 2003 program but I''m not sure what to do with this
code. I know 2005 keeps the Windows Form Designer generated code
somewhere but I really don''t want to add it there unless it is really
necessary. Apparently it can go in Form1_Load but I''m not sure that''s
appropriate. Where should I put it in 2005? Pros and cons?



嗨CJ,

2005年的
如果你输入''Public Sub New''在.vb文件中按回车

编辑器将自动生成代码: -


Public Sub New()

''Windows窗体设计器需要此调用。

InitializeComponent()


''在InitializeComponent()之后添加任何初始化打电话。


结束子


您可以在添加任何....后添加您的代码。


HTH


" cj" < cj@nospam.nospamwrote in message

news:u5 ************** @ TK2MSFTNGP03.phx.gbl ...
Hi CJ,

in 2005 if you type ''Public Sub New'' in the .vb file and press return the
editor will auto-generate the code:-

Public Sub New()

'' This call is required by the Windows Form Designer.
InitializeComponent()

'' Add any initialization after the InitializeComponent() call.

End Sub

You can add your code after the ''Add any....'' comment

HTH


"cj" <cj@nospam.nospamwrote in message
news:u5**************@TK2MSFTNGP03.phx.gbl...

在2003年大约一年前完成的项目中,我被告知要将下面的

SocketWrench代码添加到Windows窗体设计器生成的代码区域中

如下所示。


#Region" Windows窗体设计器生成的代码


Public Sub New()

MyBase.New()


' 'Windows窗体设计器需要此调用。

InitializeComponent()

''在InitializeComponent()调用后添加任何初始化


socket = New SocketWrenchCtl.SocketWrench

如果socket.Initialize(" ELMO")< 0那么

抛出新的System.Exception(" ;无法初始化控制)

结束如果


结束子


我正在完成2005年程序现在非常相似我复制了很多部分

的旧2003程序,但我不知道如何处理这段代码。我知道2005年保留了Windows窗体设计器生成的代码,但是我确实不想将它添加到那里,除非真的有必要。

显然它可以使用Form1_Load,但我不确定是否合适。

我应该在2005年把它放在哪里?优点和缺点?
In a project done in 2003 about a year ago I was told to add the
SocketWrench code below into the Windows Form Designer generated code area
as shown below.

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

''This call is required by the Windows Form Designer.
InitializeComponent()

''Add any initialization after the InitializeComponent() call

socket = New SocketWrenchCtl.SocketWrench
If socket.Initialize("ELMO") <0 Then
Throw New System.Exception("Unable to initialize control")
End If

End Sub

I''m completing a 2005 program now that was so similar I copied many parts
of the old 2003 program but I''m not sure what to do with this code. I
know 2005 keeps the Windows Form Designer generated code somewhere but I
really don''t want to add it there unless it is really necessary.
Apparently it can go in Form1_Load but I''m not sure that''s appropriate.
Where should I put it in 2005? Pros and cons?



这篇关于Windows窗体设计器生成的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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