在窗體上加上三個標簽控件:Label1、Label2、Label3

創新互聯公司于2013年創立,是專業互聯網技術服務公司,擁有項目成都網站設計、網站建設網站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元漳浦做網站,已為上家服務,為漳浦各地企業和個人服務,聯系電話:18980820575
Private?Sub?DataGridView1_MouseUp(ByVal?sender?As?Object,?ByVal?e?As?System.Windows.Forms.MouseEventArgs)?Handles?DataGridView1.MouseUp
Dim?counter?As?Integer
Dim?SelectedCellTotal?As?Integer?=?0
Dim?SelectedCellCount?As?Integer?=?0
For?counter?=?0?To?(DataGridView1.SelectedCells.Count?-?1)
If?DataGridView1.SelectedCells(counter).FormattedValueType?Is?_
Type.GetType("System.String")?Then
Dim?value?As?String?=?Nothing
If?(DataGridView1.IsCurrentCellDirty?=?True)?Then
value?=?DataGridView1.SelectedCells(counter).EditedFormattedValue.ToString()
Else
value?=?DataGridView1.SelectedCells(counter).FormattedValue.ToString()
End?If
If?value?IsNot?Nothing?Then
If?Not?value.Length?=?0?Then
SelectedCellTotal?=?SelectedCellTotal?+?Integer.Parse(value)
SelectedCellCount?=?SelectedCellCount?+?1
End?If
End?If
End?If
Next
Label1.Text?=?"選中的單元格個數為:?"??SelectedCellCount.ToString()
Label2.Text?=?"單元格里數據之和為:?"??SelectedCellTotal.ToString()
Label3.Text?=?"選中的單元格行數為:"??DataGridView1.SelectedRows.Count.ToString()
End?Sub
用正則匹配即可
Option?Explicit
Function?GetSource$(Source$)????????????????????????????????????????????????????'//正則匹配td/td
Dim?reg?As?Object
Dim?matchs?As?Object,?match?As?Object
Dim?s?As?String,?i?As?Integer
Set?reg?=?CreateObject("vbscript.regExp")
reg.Global?=?True
reg.IgnoreCase?=?True
reg.MultiLine?=?True
reg.Pattern?=?"label.*?(.*?)\/label"
Set?matchs?=?reg.Execute(Source)
For?Each?match?In?matchs
i?=?i?+?1
s?=?s??match.SubMatches(0)?+?vbCrLf
Next
GetSource?=?s
End?Function
Function?div$(Source$)??????????????????????????????????????????????????????????'//正則匹配??div/div
Dim?reg?As?Object
Dim?matchs?As?Object,?match?As?Object
Dim?s?As?String,?i?As?Integer
Set?reg?=?CreateObject("vbscript.regExp")
reg.Global?=?True
reg.IgnoreCase?=?True
reg.MultiLine?=?True
reg.Pattern?=?"div.*?(.*?)\/div"
Set?matchs?=?reg.Execute(Source)
For?Each?match?In?matchs
i?=?i?+?1
s?=?s??match.SubMatches(0)?+?vbCrLf
Next
div?=?s
End?Function
Private?Sub?Command1_Click()
MsgBox?"div標簽獲取"?+?vbCrLf?+?GetSource$(Text1)
MsgBox?"label標簽獲取"?+?vbCrLf?+?GetSource$(Text1)
End?Sub
另一個簡單點的方法是,假如HTML里面有個文本框是
input type="text" class="body_normal" id="TESTID" value="TEXTBOX" /
則VB.NET里寫
text=web.Document.GetElementById("TESTID").GetAttribute("value")
則得到text="TEXTBOX"
我將你的上面的html代碼復制到一個test.html文件中
html
head
titleTest Page/title
/head
body
input name="txtCSRQ" class="textbox" id="txtCSRQ" type="text" readonly="readonly" value="1993-05-10"/
/body
/html
然后在vb.net的webbrowser中加載這個test.html,加載完畢后點擊一個按鈕獲取input的value值,實現代碼如下:
' 此方法為Form1的加載事件
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' 加載本地文檔test.html
WebBrowser1.Url = New Uri(String.Format("{0}/test.html", Application.StartupPath))
' 文檔沒有加載完畢之前將按鈕禁用
Button1.Enabled = False
End Sub
' 此方法為Button1的Click事件
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim doc As HtmlDocument = WebBrowser1.Document
' 查找ID為txtCSRQ的元素
Dim element As HtmlElement = doc.GetElementById("txtCSRQ")
' 如果找到了改元素
If element IsNot Nothing Then
' 顯示該元素的值
MessageBox.Show(element.GetAttribute("value"))
End If
End Sub
' 此方法為WebBrowser的DocomentCompleted事件
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
' 文檔test.html加載完畢后,使按鈕可用
Button1.Enabled = True
End Sub
很簡單,看代碼:
Dim?objexcelfile?As?Excel.Application?=?New?Excel.Application
objexcelfile.DisplayAlerts?=?False
Dim?objworkbook?As?Excel.Workbook?=?objexcelfile.Workbooks.Open("D:\1.xlsx")??'Excel文件路徑
Dim?objimportsheet?As?Excel.Worksheet?=?objworkbook.Sheets(1)?'讀取第一個Sheet
Dim?intRow?As?Integer?=?objimportsheet.UsedRange.Rows.Count??'獲取總行數
Dim?prod?As?String?=?objimportsheet.Cells(j,?i).value?'讀取單元格的值(i是列,j是行)
'釋放Excel文件
objworkbook.Close()
objworkbook?=?Nothing
objexcelfile.Quit()
注意需要添加 Microsoft.Office.Interop 的引用。
用findwindowex的API函數查找這個句柄窗口中的子窗口(LABEL也是作為子窗口的),
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
新聞標題:關于vb.net獲取標簽內值的信息
鏈接地址:http://www.js-pz168.com/article16/hhcedg.html
成都網站建設公司_創新互聯,為您提供定制開發、網站設計公司、微信公眾號、自適應網站、網站維護、域名注冊
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯