
正文
vb.netmvc例子 vbnet using
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
VB.net中类的实例化
1.不正确
Dim abc As myClassvb.netmvc例子,定义一个可以引用myClass类型对象vb.netmvc例子的变量abc。这个abc变量存在于栈上。
abc=New myClass。New myClass创建myClass实例对象,这个对象存在于托管堆上。然后(同时)让abc引用(指向)这个对象。
abc变量在栈上,而对象在托管堆上。
abc储存的是对象的地址,而不是对象本身。
看下面的代码
Dim a As myClass,b As myClass,c As myClass
a=New myClass
b=a
c=a
整个过程中只创建了一个myClass对象,位于托管堆上。
三个myClass类型的变量a、b、c位于栈上,都指向了这一个myClass对象
2.类的成员分 实例成员 和 静态成员
实例成员 必须在实例对象上调用
静态成员 可以直接调用,不需要实例对象。
相关问答
Q1: vb.net中如何用事件和委托,会C#中的事件和委托,但不知VB.net中的语法,望给个简单的例子熟悉语法。
一委托:此示例演示如何将方法与委托关联然后通过委托调用该方法。
创建委托和匹配过程
创建一个名为 MySubDelegate 的委托。
Delegate Sub MySubDelegate(ByVal x As Integer)
声明一个类,该类包含与该委托具有相同签名的方法。
Class class1
Sub Sub1(ByVal x As Integer)
MsgBox("The value of x is: " CStr(x))
End Sub
End Class
定义一个方法,该方法创建该委托的实例并通过调用内置的 Invoke 方法调用与该委托关联的方法。
Protected Sub DelegateTest()
Dim c1 As New class1
' Create an instance of the delegate.
Dim msd As MySubDelegate = AddressOf c1.Sub1
' Call the method.
msd.Invoke(10)
End Sub
二、事件
下面的示例程序阐释如何在一个类中引发一个事件,然后在另一个类中处理该事件。AlarmClock 类定义公共事件 Alarm,并提供引发该事件的方法。AlarmEventArgs 类派生自 EventArgs,并定义 Alarm 事件特定的数据。WakeMeUp 类定义处理 Alarm 事件的 AlarmRang 方法。AlarmDriver 类一起使用类,将使用 WakeMeUp 的 AlarmRang 方法设置为处理 AlarmClock 的 Alarm 事件。
该示例程序使用事件和委托和引发事件中详细说明的概念。
示例
' EventSample.vb.
'
Option Explicit
Option Strict
Imports System
Imports System.ComponentModel
Imports Microsoft.VisualBasic
Namespace EventSample
' Class that contains the data for
' the alarm event. Derives from System.EventArgs.
'
Public Class AlarmEventArgs
Inherits EventArgs
Private _snoozePressed As Boolean
Private nrings As Integer
'Constructor.
'
Public Sub New(snoozePressed As Boolean, nrings As Integer)
Me._snoozePressed = snoozePressed
Me.nrings = nrings
End Sub
' The NumRings property returns the number of rings
' that the alarm clock has sounded when the alarm event
' is generated.
'
Public ReadOnly Property NumRings() As Integer
Get
Return nrings
End Get
End Property
' The SnoozePressed property indicates whether the snooze
' button is pressed on the alarm when the alarm event is generated.
'
Public ReadOnly Property SnoozePressed() As Boolean
Get
Return _snoozePressed
End Get
End Property
' The AlarmText property that contains the wake-up message.
'
Public ReadOnly Property AlarmText() As String
Get
If _snoozePressed Then
Return "Wake Up!!! Snooze time is over."
Else
Return "Wake Up!"
End If
End Get
End Property
End Class
' Delegate declaration.
'
Public Delegate Sub AlarmEventHandler(sender As Object, _
e As AlarmEventArgs)
' The Alarm class that raises the alarm event.
'
Public Class AlarmClock
Private _snoozePressed As Boolean = False
Private nrings As Integer = 0
Private stopFlag As Boolean = False
' The Stop property indicates whether the
' alarm should be turned off.
'
Public Property [Stop]() As Boolean
Get
Return stopFlag
End Get
Set
stopFlag = value
End Set
End Property
' The SnoozePressed property indicates whether the snooze
' button is pressed on the alarm when the alarm event is generated.
'
Public Property SnoozePressed() As Boolean
Get
Return _snoozePressed
End Get
Set
_snoozePressed = value
End Set
End Property
' The event member that is of type AlarmEventHandler.
'
Public Event Alarm As AlarmEventHandler
' The protected OnAlarm method raises the event by invoking
' the delegates. The sender is always this, the current instance
' of the class.
'
Protected Overridable Sub OnAlarm(e As AlarmEventArgs)
RaiseEvent Alarm(Me, e)
End Sub
' This alarm clock does not have
' a user interface.
' To simulate the alarm mechanism it has a loop
' that raises the alarm event at every iteration
' with a time delay of 300 milliseconds,
' if snooze is not pressed. If snooze is pressed,
' the time delay is 1000 milliseconds.
'
Public Sub Start()
Do
nrings += 1
If stopFlag Then
Exit Do
Else
If _snoozePressed Then
System.Threading.Thread.Sleep(1000)
If (True) Then
Dim e As New AlarmEventArgs(_snoozePressed, nrings)
OnAlarm(e)
End If
Else
System.Threading.Thread.Sleep(300)
Dim e As New AlarmEventArgs(_snoozePressed, nrings)
OnAlarm(e)
End If
End If
Loop
End Sub
End Class
' The WakeMeUp class has a method AlarmRang that handles the
' alarm event.
'
Public Class WakeMeUp
Public Sub AlarmRang(sender As Object, e As AlarmEventArgs)
Console.WriteLine((e.AlarmText + ControlChars.Cr))
If Not e.SnoozePressed Then
If e.NumRings Mod 10 = 0 Then
Console.WriteLine(" Let alarm ring? Enter Y")
Console.WriteLine(" Press Snooze? Enter N")
Console.WriteLine(" Stop Alarm? Enter Q")
Dim input As String = Console.ReadLine()
If input.Equals("Y") Or input.Equals("y") Then
Return
Else
If input.Equals("N") Or input.Equals("n") Then
CType(sender, AlarmClock).SnoozePressed = True
Return
Else
CType(sender, AlarmClock).Stop = True
Return
End If
End If
End If
Else
Console.WriteLine(" Let alarm ring? Enter Y")
Console.WriteLine(" Stop Alarm? Enter Q")
Dim input As String = Console.ReadLine()
If input.Equals("Y") Or input.Equals("y") Then
Return
Else
CType(sender, AlarmClock).Stop = True
Return
End If
End If
End Sub
End Class
' The driver class that hooks up the event handling method of
' WakeMeUp to the alarm event of an Alarm object using a delegate.
' In a forms-based application, the driver class is the
' form.
'
Public Class AlarmDriver
Public Shared Sub Main()
' Instantiates the event receiver.
Dim w As New WakeMeUp()
' Instantiates the event source.
Dim clock As New AlarmClock()
' Wires the AlarmRang method to the Alarm event.
AddHandler clock.Alarm, AddressOf w.AlarmRang
clock.Start()
End Sub
End Class
End Namespace
Q2: 用VB.NET轻松制作特效窗体
体是Windows应用程序vb.netmvc例子的基础 新一代的开发工具Visual Basic Net为设计制作窗体提供了更多简单而丰富的方法 无需再求助于复杂而易错的API函数 vb.netmvc例子我们就可以轻松制作多种特效窗体 轻松制作透明窗体VB NET可以轻松制作出任一透明度的窗体 我们只要在窗体的 属性 窗口中 将 Opacity 属性设置为一个介于 (完全透明)与 (完全不透明)之间的值就可以了 Dim frm As FrmTrans = New FrmTrans()frm Opacity = frm ShowDialog() 轻松制作始终位于最上层的窗体在VB 中 要制作一个始终位于最上层的窗体我们只能求助于令人头痛的API函数 然而在 NET 中 我们只要简单设置窗体的 TopMost 属性就可实现同样效果了vb.netmvc例子!例如 Dim frm As frmTopMost = New frmTopMost()frm TopMost = Truefrm Show() 轻松制作不可见的窗体如果要编写一个不让别人发现的隐藏程序 制作不可见的窗体就是必须实现的第一步 窗体的可见性通常由 Visible 属性控制 但是 如果希望 Windows 应用程序的主窗体在应用程序启动时不可见 您将会发现将它的 Visible 属性设置为 False 的方法无效 窗体总会自己显示出来(这是因为 启动窗体的生存期决定了应用程序的生存期) 虽然如此 我们还是可以通过简单将应用程序的启动设置为一个模块 从而从窗体的生存期分出应用程序的生存期 轻松实现不可见的窗体 在下面这个例子中 窗体在特定的时间内自动隐藏 ( )在 Visual Basic 中 右击项目并选择 添加模块 以将模块添加到 Windows 应用程序 ( )在已添加的模块(或类)内 创建可作为项目启动对象的 Main 函数 Sub main()Dim f As New Form ()f Visible = FalseWhile Hour(Date Now) 如果当前时间早于 点 窗体自动隐藏Application DoEvents()End Whilef ShowDialog()End Sub 轻松编写托盘程序托盘程序作为一类特殊的窗体 其快捷图标显示在系统托盘中 窗体本身则隐藏不可见 在 NET之前版本的VB中编写托盘程序是十分困难的 但是VB NET提供的新的NotifyIcon组件却使VB初学者也能轻松编写一个这样的程序 新建 Windows应用程序 设置主窗体Opacity属性为 FormBorderStyle属性为None ShowInTaskbar属性为False 这样窗体将在启动后隐藏 在窗体上放置一个NotifyIcon组件NotifyIcon 一个ContextMenu(弹出菜单)组件ContextMenu 并根据需要为ContextMenu 添加菜单项 设置NotifyIcon 的ICON属性 这个图标就是应用程序出现在系统托盘中的快捷图标 设置NotifyIcon 的Text属性为 VB NET托盘程序 这就是鼠标移动到托盘图标时弹出的文字说明 设置NotifyIcon 的ContextMenu属性为ContextMenu 也就是右键单击快捷图标时的弹出菜单为ContextMenu OK 按F 运行vb.netmvc例子!几乎不用编写代码 一个托盘程序就这样轻松实现了 lishixinzhi/Article/program/net/201311/13831
关于vb.netmvc例子和vbnet using的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







