文件: Wintalk.vb
'
' 摘要: 演示如何使用.NET Framework library创建聊天程序.
'
'=====================================================================
Option Explicit On
Option Strict On
Imports System
Imports System.IO
Imports System.Text
Imports System.Threading
Imports System.Net
Imports System.Net.Sockets
Imports System.Drawing
Imports System.Windows.Forms
Imports Microsoft.VisualBasic
Class App
'Entry point which delegates to C-style main Private Function
Public Overloads Shared Sub Main()
Main(System.Environment.GetCommandLineArgs())
End Sub
' Entry point
Overloads Public Shared Sub Main(args() As String)
' If the args parse in known way then run the app
If ParseArgs(args) Then
' Create a custom Talker object
Dim talkerObj As New Talker(endPoint, client)
' Pass the object reference to a new form object
Dim form As New TalkForm(talkerObj)
' Start the talker "talking"
talkerObj.Start()
' Run the applications message pump
Application.Run(form)
End If
End Sub 'Main
' Parsed Argument Storage
Private Shared endPoint As IPEndPoint
Private Shared client As Boolean
' Parse command line arguments
Private Shared Function ParseArgs(args() As String) As Boolean
Try
If args.Length = 1 Then
client = False
endPoint = New IPEndPoint(IPAddress.Any, 5150)
Return True
End If
Dim port As Integer
Select Case Char.ToUpper(args(1).ToCharArray()(1))
Case "L"c
port = 5150
If args.Length > 2 Then
port = Convert.ToInt32(args(2))
End If
endPoint = New IPEndPoint(IPAddress.Any, port)
client = False
Case "C"c
port = 5150
Dim address As String = "127.0.0.1"
client = True
If args.Length > 2 Then
address = args(2)
port = Convert.ToInt32(args(3))
End If
endPoint = New IPEndPoint(Dns.Resolve(address).AddressList(0), port)
Case Else
ShowUsage()
Return False
End Select
Catch
End Try
Return True
End Function 'ParseArgs
' Show sample usage
Private Shared Sub ShowUsage()
MessageBox.Show("WinTalk [switch] [parameters...]" & ControlChars.CrLf & ControlChars.CrLf & _
" /L [port]" & ControlChars.Tab & ControlChars.Tab & "-- Listens on a port. Default: 5150" & ControlChars.CrLf & _
" /C [address] [port]" & ControlChars.Tab & "-- Connects to an address and port." & ControlChars.CrLf & ControlChars.CrLf & _
"Example Server - " & ControlChars.CrLf & _
"Wintalk /L" & ControlChars.CrLf & ControlChars.CrLf & _
"Example Client - " & ControlChars.CrLf & _
"Wintalk /C ServerMachine 5150", "WinTalk Usage")
End Sub 'ShowUsage
End Class 'App
' UI class for the sample
Class TalkForm
Inherits Form
Public Sub New(talkerObj As Talker)
' Associate for method with the talker object
Me.talkerObj = talkerObj
AddHandler talkerObj.Notifications, AddressOf HandleTalkerNotifications
' Create a UI elements
Dim talkSplitter As New Splitter()
Dim talkPanel As New Panel()
receiveText = New TextBox()
sendText = New TextBox()
'we'll support up to 64k data in our text box controls
receiveText.MaxLength = 65536
sendText.MaxLength = 65536
statusText = New Label()
' Initialize UI elements
receiveText.Dock = DockStyle.Top
receiveText.Multiline = True
receiveText.ScrollBars = ScrollBars.Both
receiveText.Size = New Size(506, 192)
receiveText.TabIndex = 1
receiveText.Text = ""
receiveText.WordWrap = False
receiveText.ReadOnly = True
talkPanel.Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or AnchorStyles.Left Or AnchorStyles.Right
talkPanel.Controls.AddRange(New Control() {sendText, talkSplitter, receiveText})
talkPanel.Size = New Size(506, 371)
talkPanel.TabIndex = 0
talkSplitter.Dock = DockStyle.Top
talkSplitter.Location = New Point(0, 192)
talkSplitter.Size = New Size(506, 6)
talkSplitter.TabIndex = 2
talkSplitter.TabStop = False
statusText.Dock = DockStyle.Bottom
statusText.Location = New Point(0, 377)
statusText.Size = New Size(507, 15)
statusText.TabIndex = 1
statusText.Text = "Status:"
sendText.Dock = DockStyle.Fill
sendText.Location = New Point(0, 198)
sendText.Multiline = True
sendText.ScrollBars = ScrollBars.Both
sendText.Size = New Size(506, 173)
sendText.TabIndex = 0
sendText.Text = ""
sendText.WordWrap = False
AddHandler sendText.TextChanged, AddressOf HandleTextChange
sendText.Enabled = False
AutoScaleBaseSize = New Size(5, 13)
ClientSize = New Size(507, 392)
Controls.AddRange(New Control() {statusText, talkPanel})
Me.Text = "WinTalk"
Me.ActiveControl = sendText
End Sub 'New
' When the app closes, dispose of the talker object
Protected Overrides Sub OnClosed(e As EventArgs)
If Not (talkerObj Is Nothing) Then
RemoveHandler talkerObj.Notifications, AddressOf HandleTalkerNotifications
talkerObj.Dispose()
End If
MyBase.OnClosed(e)
End Sub 'OnClosed
' Handle notifications from the talker object
Private Sub HandleTalkerNotifications(notify As Talker.Notification, data As Object)
Select Case notify
Case Talker.Notification.Initialized
' Respond to status changes
Case Talker.Notification.StatusChange
Dim statusObj As Talker.Status = CType(data, Talker.Status)
statusText.Text = String.Format("Status: {0}", statusObj)
If statusObj = Talker.Status.Connected Then
sendText.Enabled = True
End If
' Respond to received text
Case Talker.Notification.Received
receiveText.Text = data.ToString()
receiveText.SelectionStart = Int32.MaxValue
receiveText.ScrollToCaret()
' Respond to error notifications
Case Talker.Notification.ErrorNotify
Close(data.ToString())
' Respond to end
Case Talker.Notification.EndNotify
MessageBox.Show(data.ToString(), "Closing WinTalk")
Close()
Case Else
Close()
End Select
End Sub 'HandleTalkerNotifications
' Handle text change notifications and send talk
Private Sub HandleTextChange(sender As Object, e As EventArgs)
If Not (talkerObj Is Nothing) Then
talkerObj.SendTalk(CType(sender, TextBox).Text)
End If
End Sub 'HandleTextChange
' Close with an explanation
Private OverLoads Sub Close(message As String)
MessageBox.Show(message, "Error!")
Close()
End Sub 'Close
' Private UI elements
Private receiveText As Te
没有合适的资源?快使用搜索试试~ 我知道了~
VB.net 锁屏幕
共69个文件
txt:25个
vb:6个
pdb:6个
5星 · 超过95%的资源 需积分: 9 44 下载量 95 浏览量
2009-01-02
15:07:15
上传
评论 1
收藏 178KB RAR 举报
温馨提示
一 个 vb.net 的 锁 屏 源 码
资源推荐
资源详情
资源评论
收起资源包目录
.rar (69个子文件)
在VB中实现客户端程序自动查找并连接服务端程序.txt 3KB
判断计算机当前的网络是否连接.txt 1015B
如何在vb 中用api函数代替winsock控件建立网络连接?.txt 6KB
利用线程调用程序执行的方法.txt 328B
一个加强的文件上传(VB.Net).txt 8KB
VB.NET中监视文件夹的变化.txt 7KB
VB.NET启动并监测外部程序.txt 12KB
Net中的socket编程—聊天程序.txt 5KB
VB程序中用ADO对象动态创建数据库和表.txt 9KB
创建一个Windows Service应用程序.txt 6KB
实现端口对端口的聊天.txt 3KB
从Window系统托盘控制Windows服务.txt 8KB
VB开发客户服务器软件的设计与实现.txt 7KB
vb.net下载数据.txt 3KB
屏幕锁.exe 56KB
VB.NET聊天程序.txt 17KB
巧用Win32 API函数增强VB位操作功能.txt 11KB
USB通讯检测U盘插入与卸载并可以写入读取文件.txt 4KB
Visual Basic编程访问WMI对象.txt 3KB
基于Winsock控件制作的一个“服务器,N客户端”通讯程序(完整原程序).txt 5KB
用VB5 Winsock控件创建TCPIP客户机 服务器程序.txt 5KB
vb.net执行外部程序的代码.txt 295B
设置系统时间.txt 1KB
屏幕锁
index.Designer.vb 21KB
bin
Debug
WindowsApplication1.vshost.exe 6KB
WindowsApplication9.pdb 72KB
屏幕锁.pdb 72KB
屏幕锁.xml 621B
屏幕锁.vshost.exe 6KB
WindowsApplication9.xml 127B
WindowsControlLibrary1.dll 28KB
WindowsApplication9.exe 44KB
Release
屏幕锁.pdb 70KB
屏幕锁.xml 621B
WindowsControlLibrary1.dll 28KB
WindowsApplication9.sln 900B
obj
WindowsApplication9.vbproj.FileList.txt 449B
Debug
WindowsApplication1.Resources.resources 180B
锁屏.vbproj.GenerateResource.Cache 842B
屏幕锁.Resources.resources 180B
ResolveAssemblyReference.cache 5KB
WindowsApplication9.pdb 72KB
屏幕锁.pdb 72KB
屏幕锁.xml 621B
WindowsApplication1.index.resources 3KB
WindowsApplication9.vbproj.GenerateResource.Cache 842B
WindowsApplication9.xml 127B
TempPE
My Project.Resources.Designer.vb.dll 8KB
屏幕锁.index.resources 3KB
Release
锁屏.vbproj.GenerateResource.Cache 842B
屏幕锁.Resources.resources 180B
屏幕锁.pdb 70KB
屏幕锁.xml 621B
TempPE
My Project.Resources.Designer.vb.dll 8KB
屏幕锁.index.resources 3KB
锁屏.vbproj.FileList.txt 734B
WindowsApplication9.suo 19KB
index.vb 10KB
锁屏.vbproj 5KB
My Project
AssemblyInfo.vb 1KB
Settings.Designer.vb 3KB
Application.myapp 469B
Settings.settings 279B
Resources.resx 5KB
Resources.Designer.vb 3KB
Application.Designer.vb 2KB
index.resx 10KB
Mis Documentos.ico 8KB
编写随Windows启动自动运行的程序.txt 4KB
共 69 条
- 1
资源评论
- vicanary2013-06-17这个 不错,完全可以用
- qiandaber2014-03-08简单好用的代码
- 暮雨奋甜2013-02-18很好的资源 值得学习
- Joyous6292015-01-27简易实用,实在好!
VampireB
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功