问题描述
亲爱的所有
PLs帮助我希望我的所有表格中的更换者属性来自 sub / function
PLs Help MeI want changer property all my form from sub/function
示例
我的程序
模块TestForm
  ;   Public Sub gsubSetRezise(ByRef vForm As System.Windows.Forms.Form)
vForm.Left = 0
vForm.Top = 0
vForm.Width = 500
vForm.Height = 400
Module TestForm
Public Sub gsubSetRezise(ByRef vForm As System.Windows.Forms.Form)
vForm.Left = 0
vForm.Top = 0
vForm.Width = 500
vForm.Height = 400
MsgBox("gsubSetRezise上的宽度"& vForm.name&""& vForm.Width)
MsgBox("width on gsubSetRezise " & vForm.name &" is " & vForm.Width)
退出Sub¥
结束分组
结束模块
Exit Sub
End Sub
End Module
我的表格名称是test001
ON my form name is test001
公共类test01
Private Sub test01_Load(sender As Object,e As EventArgs)Handles MyBase.Load
Dim cFrom As System.Windows.Forms.Form
cForm =新test01
Public Class test01
Private Sub test01_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim cFrom As System.Windows.Forms.Form
cForm = New test01
MsgBox(" width Before"& Me.Width)
MsgBox("width Before " & Me.Width)
致电gsubSetRezise(cForm)
Call gsubSetRezise(cForm)
MsgBox(" wdith After& Me.Width)
MsgBox("wdith After " & Me.Width)
结束分
$
结束等级
End Sub
End Class
结果 我的程序
Result my program
宽度40之前
width Before 40
gsubSetRezise test001的宽度为500
width on gsubSetRezise test001 is 500
宽度40后
width After 40
为什么不改变形成test01
Why form test01 with not change
推荐答案
而不是创建新表单(new test01)使用当前实例
instead of creating a new form (new test01) use the current instance
Private Sub test01_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim cFrom As System.Windows.Forms.Form
cForm = Me 'Me is a keyword, a reference to the current instance of the current class
MsgBox("width Before " & Me.Width)
Call gsubSetRezise(cForm)
MsgBox("wdith After " & Me.Width)
End Sub
或者只用"Me"来调用sub。作为参数:
or just call the sub with "Me" as parameter:
Private Sub test01_Load(sender As Object, e As EventArgs) Handles MyBase.Load
MsgBox("width Before " & Me.Width)
Call gsubSetRezise(Me)
MsgBox("wdith After " & Me.Width)
End Sub
问候,
Thorsten
Thorsten
这篇关于从子/功能改变表格属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!