Tag: vb.net预览模式: 普通 | 列表

cefsharp winfrom 保存用户登录状态

winfrom 使用cefsharp作为内嵌浏览器,要求是保存用户登录,在下次启动时不要要再输入用户名和密码,
CefSettings _settings = new CefSettings();
_settings.PersistSessionCookies = true;
但是无效

回答:
保持登录状态需满足

网站返回的 cookie 不带过期时间
设置缓存路径 CefSettings.CachePath
存储会话 cookie CefSettings.PersistSessionCookies

 

settings.CachePath = Application.StartupPath & "/cache"
settings.PersistSessionCookies = True

查看更多...

Tags: vb.net

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 377

vb.net unicode编码转中文字符

Private Function UniTostr(ByVal body As String)
Dim S2 As String
Dim S3 As String = ""
Dim I1 As String

body = Trim(body)
Do While Len(body) > 1
I1 = InStr(1, body, "\u")
If I1 > 0 Then
S3 = S3 & Strings.Left(body, I1 - 1)
S2 = "&H" & Mid(body, I1 + 2, 4)
S2 = ChrW(S2)
S3 = S3 & S2
body = Strings.Right(body, Len(body) - I1 - 5)
Else
S3 = S3 & body
body = ""
End If
Loop
UniTostr = S3
End Function

Tags: vb.net

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 340

VB.net使用CefSharp笔记

获取js执行返回值

 

Imports CefSharp.WinForms

Public Class Form1

'定义cef浏览器控件的全局变量,方便后面调用,注意WithEvents

查看更多...

Tags: vb.net

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 415

VB.NET字符串函数

1:字符串函数


StrComp 比较两个字符串

StrConv 转换字符串

InStrRev、StrReverse 翻转字符串

查看更多...

Tags: vb.net

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 817

VB.NET模拟鼠标事件

Inherits System.Windows.Forms.Form

Declare Auto Sub mouse_event Lib "user32" (ByVal dwFlags As Int32, ByVal dx As Int32, ByVal dy As Int32, ByVal cButtons As Int32, ByVal dwExtraInfo As IntPtr)

Const MOUSEEVENTF_MOVE As Int32 = &H1 ' mouse move
Const MOUSEEVENTF_LEFTDOWN As Int32 = &H2 ' left button down
Const MOUSEEVENTF_LEFTUP As Int32 = &H4 ' left button up
Const MOUSEEVENTF_RIGHTDOWN As Int32 = &H8 ' right button down
Const MOUSEEVENTF_RIGHTUP As Int32 = &H10 ' right button up
Const MOUSEEVENTF_MIDDLEDOWN As Int32 = &H20 ' middle button down
Const MOUSEEVENTF_MIDDLEUP As Int32 = &H40 ' middle button up
Const MOUSEEVENTF_ABSOLUTE As Int32 = &H8000 ' absolute move
Const MOUSEEVENTF_WHEEL As Int32 = &H800 ' wheel button rolled

' Simulate moving the mouse to the center of the
' PictureBox and clicking.
Private Sub cmdClick_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdClick.Click
Dim cur_x As Single
Dim cur_y As Single
Dim dest_x As Single
Dim dest_y As Single

查看更多...

Tags: vb.net

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 485

VB.net读写二进制数据方法

一、二进制文件读写

1、写二进制数据到指定目录


dim barray() as byte
dim strFileName as string
My.Computer.FileSystem.WriteAllBytes(strFileName, barray, False)
==>将barray字节数组中的数据创建在strFilename目录文件下,存储格式为二进制,False表示不添加,直接覆盖创建。

 

查看更多...

Tags: vb.net

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 493

vb.net 中功能强大的Tostring()

功能强大的Tostring()

//2007年4月24日
this.TextBox6.Text = System.DateTime.Now.ToString("D");
//2007-4-24
this.TextBox7.Text = System.DateTime.Now.ToString("d");

//2007年4月24日 16:30:15
this.TextBox8.Text = System.DateTime.Now.ToString("F");
//2007年4月24日 16:30
this.TextBox9.Text = System.DateTime.Now.ToString("f");

//2007-4-24 16:30:15
this.TextBox10.Text = System.DateTime.Now.ToString("G");
//2007-4-24 16:30
this.TextBox11.Text = System.DateTime.Now.ToString("g");

查看更多...

Tags: vb.net

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 464

VB.NET中如何动态创建控件

Option Explicit
Private WithEvents NewTextBox As TextBox
'通过使用WithEvents关键字声明一个对象变量为新的命令按钮

Private Sub Command1_Click()
If NewTextBox Is Nothing Then
Set NewTextBox = Controls.Add("VB.TextBox", "cmdNew", Form1)
NewTextBox.Move 200, 200
NewTextBox.Width = Form1.Width - 450
NewTextBox.Height = Form1.Height - 1400
NewTextBox.Visible = True
End If
End Sub

Private Sub Command2_Click()
If NewTextBox Is Nothing Then
Exit Sub
Else
Controls.Remove NewTextBox
Set NewTextBox = Nothing
End If
End Sub

Tags: vb.net

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 522

VB.net线程传递参数四种方法

Thread线程启动方法,一般来说要么是一个无参数的方法,要么是一个带有object参数的方法并且在Start时传递参数的值。
但是我们可以利用一些技巧给方法传递不受限制的参数。这些方法又可以在实际使用过程相互融合。
方法简单直接上代码,供君参考。

Imports System.Threading Module Module1 Sub Main() '第一种:在Start中传递参数值,但方法中的参数类型需为object类型 Dim t1 As New Thread(AddressOf CountNumber) t1.Start(10) '第二种:通过Lambda表达式创建线程,可以传递任意的参数 Dim t2 As New Thread(Sub() PrintNumber(20) End Sub) t2.Start() '第三种:通过实例化类来传递参数,然后调用类方法 Dim c As New Count(10) Dim t3 As New Thread(AddressOf c.CountNumber) t3.Start() '第四种:通过传递类或结构,以达到向方法传递多个参数 Dim p As New Person() With { .FirstName = "严", .LastName = "查散" } Dim t4 As New Thread(AddressOf ShowName) t4.Start(p) Console.Read() End Sub '传递单个参数 Private Sub CountNumber(number As Object) Dim sum As Integer For i As Integer = 1 To Integer.Parse(number) sum += i Next Console.WriteLine(sum) End Sub '传递非object参数 Private Sub PrintNumber(number As Integer) Console.WriteLine(number) End Sub '把方法包装成类,在实例化时传递参数 Class Count Dim number As Integer Sub New(number As Integer) Me.number = number End Sub Public Sub CountNumber() Dim sum As Integer For i As Integer = 1 To Integer.Parse(number) sum += i Next Console.WriteLine(sum) End Sub End Class '传递一个类或结构达到传递多个参数 Private Sub ShowName(person As Object) Dim myPerson As Person = CType(person, Person) Console.WriteLine(myPerson.FirstName & myPerson.LastName) End Sub Class Person Public Property FirstName As String Public Property LastName As String End Class End Module

Tags: vb.net

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 3052

Function GetWebCode(ByVal strURL As String) As String
Dim httpReq As System.Net.HttpWebRequest
Dim httpResp As System.Net.HttpWebResponse
Dim httpURL As New System.Uri(strURL)
Dim ioS As System.IO.Stream, charSet As String, tCode As String
Dim k() As Byte
ReDim k(0)
Dim dataQue As New Queue(Of Byte)
httpReq = CType(WebRequest.Create(httpURL), HttpWebRequest)
Dim sTime As Date = CDate("1990-09-21 00:00:00")
httpReq.IfModifiedSince = sTime
httpReq.Method = "GET"
httpReq.Timeout = 7000

Try
httpResp = CType(httpReq.GetResponse(), HttpWebResponse)
Catch
Debug.Print("weberror")
GetWebCode = "<title>no thing found</title>" : Exit Function
End Try
'以上为网络数据获取
ioS = CType(httpResp.GetResponseStream, Stream)
Do While ioS.CanRead = True
Try
dataQue.Enqueue(ioS.ReadByte)
Catch
Debug.Print("read error")
Exit Do
End Try
Loop
ReDim k(dataQue.Count - 1)
For j As Integer = 0 To dataQue.Count - 1
k(j) = dataQue.Dequeue
Next
'以上,为获取流中的的二进制数据
tCode = Encoding.GetEncoding("UTF-8").GetString(k) '获取特定编码下的情况,毕竟UTF-8支持英文正常的显示
charSet = Replace(GetByDiv2(tCode, "charset=", """"), """", "") '进行编码类型识别
'以上,获取编码类型
If charSet = "" Then 'defalt
If httpResp.CharacterSet = "" Then
tCode = Encoding.GetEncoding("UTF-8").GetString(k)
Else
tCode = Encoding.GetEncoding(httpResp.CharacterSet).GetString(k)
End If
Else
tCode = Encoding.GetEncoding(charSet).GetString(k)
End If
Debug.Print(charSet)
'Stop
'以上,按照获得的编码类型进行数据转换
'将得到的内容进行最后处理,比如判断是不是有出现字符串为空的情况
GetWebCode = tCode
If tCode = "" Then GetWebCode = "<title>no thing found</title>"
End Function

将如上代码复制,并引用:
Imports System.Net
Imports System.IO
Imports System.Text.Encoding
Imports System.Text

然后,就可以使用这个代码完成网页源代码下载的工作了。

Tags: vb.net

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 423

VB.net正则验证Email地址

 Imports System.Text.RegularExpressions
''' <summary>
''' 校验邮箱地址是否合法
''' </summary>
''' <param name="addr"></param>
''' <returns>合法返回True,不合法返回false</returns>
Public Function validateEmail(ByVal addr As String) As Boolean
Dim reg As New Regex("\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}")
Return reg.IsMatch(addr)
End Function

Tags: vb.net

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 476

vb.net 请求被中止: 未能创建 SSL/TLS

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 or SecurityProtocolType.Tls or SecurityProtocolType.Tls11 or SecurityProtocolType.Tls12
ServicePointManager.Expect100Continue = True

Tags: vb.net

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 360

 广告位

↑返回顶部↑