大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
1.对象变量与对象本身是不同的,对象变量代表了对象真实数据在内存中的地址.
十余年的花山网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整花山建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。成都创新互联公司从事“花山网站设计”,“花山网站推广”以来,每个客户项目都认真落实执行。
打个比方,“对象变量”就象你家的地址,“对象本身”就象你家。
你不能说你家的地址(xx路xx号xx房)就是你家,但是可以通过这个地址而找到你家。
2.传值的参数本身是被复制一份的,但这并不意味着它所代表的对象也被复制一份.
有如下一个函数:
Public
Function
Do_delete(ByVal
ps_usr_id
As
String)
As
Boolean
你在调用时可能这样调用:
dim
strID
as
string
strID
=
"kknd001"
if
Do_delete(strID)
then.....
当程序执行到Do_delete函数体里面时ps_usr_id变量其实是按照StrID的值而复制的一个变量。
两个参数:一个是数组名,一个是传递的长度
Function thename(ByVal imgFrom As Image) As String
thename = imgFrom.Name
End Function
Private Sub Image1_Click()
MsgBox thename(Image1)
End Sub
byval
byref
Of
Optional
ParamArray
在Visual stdio 工程中写 public sub AA(
下面自动出现这五个.
你这个默认是指自动生成的方法(过程\函数)吗?
那么默认是值传递Byval
要是自己写函数.则无参为默认
新窗体中写
构造函数
,然后调用。
比如你要调用的新窗体是From1.cs这个窗体,
public
Form1(要传入的参数)
{
//把传入的参数传入窗体中
//执行窗体标准内容
}
然后在需要调用的地方调用
Form1
f
=
new
Form1(传出的参数);
'--------Form1--------
Dim
f2
As
Form2
Private
Sub
Command1_Click()
Set
f2
=
New
Form2
f2.Show
vbModal
End
Sub
'--------Form1
End--------
'--------Form2--------
Dim
WithEvents
f3
As
Form3
Private
Sub
Command1_Click()
Set
f3
=
New
Form3
f3.Show
End
Sub
Public
Sub
f3_f2W()
Me.Command1.Caption
=
"f2W"
End
Sub
'--------Form2
End--------
'--------Form3--------
Public
Event
f2W()
Private
Sub
Command1_Click()
RaiseEvent
f2W
End
Sub
'--------Form3
End--------
f.Show();
如此就能实现调用了。
利用全局变量
利用控件属性
在vb.net中两个窗体间的变量可以相互引用了
例如:可以这样用
Public Class Form1
Public asd As Integer
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
asd = 123
End Sub
End Class
Public Class Form2
Private Sub Form2_Click(sender As Object, e As System.EventArgs) Handles Me.Click
TextBox1.Text = Form1.asd
End Sub
End Class
线程结束后利用委托生成事件返回,线程应用包括传入和传出参数。
Public Delegate Sub ThreadCallback(value As ThreadResult)
Public Class Form1
Private WithEvents _th_1 As Thread_1
Protected Overrides Sub OnLoad(e As System.EventArgs)
Dim value As ThreadObject
value.Index = 1
Me._th_1 = New Thread_1(Me)
Me._th_1.Run(value)
MyBase.OnLoad(e)
End Sub
Private Sub Thread_1_End(sender As Object, e As ThreadEventArgs) Handles _th_1.ThreadEnd
Me.TextBox1.Text = e.Result.Text
End Sub
End Class
Public Class Thread_1
Public Event ThreadEnd(sender As Object, e As ThreadEventArgs)
Private _control As Control
Sub New(control As Control)
Me._control = control
End Sub
Public Sub Run(value As Object)
Dim th As New Threading.Thread(AddressOf ThreadProc)
th.Start(value)
End Sub
Private Sub ThreadProc(obj As Object)
Dim value As ThreadObject = CType(obj, ThreadObject)
Dim result As ThreadResult = Nothing
If value.Index = 1 Then result.Text = "测试"
Dim callback As New ThreadCallback(AddressOf ThreadInvoke)
_control.Invoke(callback, result)
End Sub
Private Sub ThreadInvoke(value As ThreadResult)
RaiseEvent ThreadEnd(Me, New ThreadEventArgs(value))
End Sub
End Class
Public Structure ThreadObject
Public Index As Integer
'Public Rect As Rectangle
End Structure
Public Structure ThreadResult
Public Text As String
'Public Rect As Rectangle
End Structure
Public Class ThreadEventArgs
Inherits System.EventArgs
Private _result As ThreadResult
Public ReadOnly Property Result As ThreadResult
Get
Return _result
End Get
End Property
Sub New(value As ThreadResult)
Me._result = value
End Sub
End Class