發表文章

目前顯示的是 10月, 2007的文章

列舉IP位置

要如何利用Visual Basic列舉出目前電腦上所有網卡所設定或取得的IP位置呢?請參考看看下面程式碼 Dim S As String = "" For Each item As Net.IPAddress In Net.Dns.GetHostByName(Net.Dns.GetHostName).AddressList S &= item.AddressFamily.ToString & " " & item.ToString & vbCrLf Next MessageBox.Show(S)

圖形縮放

利用Image類別提供的相關功能或是利用PictureBox我們可以很簡單的載入或是顯示圖形在畫面上,那麼如果要縮/放圖形的話應該要怎麼做呢?請參考看看下面程式碼 Dim img As Image img = Image.FromFile(Application.StartupPath & "\MyImages\9F.jpg") Dim G As Graphics = PictureBox2.CreateGraphics Dim P(2) As Point ''左上 P(0) = New Point(0, 0) ''右上 P(1) = New Point(100, 0) ''左下 P(2) = New Point(0, 100) G.DrawImage(img, P) 相關參考 ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.cht/cpref8/html/M_System_Drawing_Graphics_DrawImage_1_d482ade5.htm 或是可以直接上 MSDN 查詢有關DrawImage相關的部分 如果要把修改後的圖存成另外的檔案可以參考下面程式碼 Dim img As Image Dim B As New Bitmap(100, 100) img = Image.FromFile(Application.StartupPath & "\MyImages\9F.jpg") Dim G As Graphics = Graphics.FromImage(B) Dim P(2) As Point ''左上 P(0) = New Point(0, 0) ''右上 P(1) = New Point(100, 0) ''左下 P(2) = New Point(0, 100) G.DrawImage(img, P) B.Save(Application.StartupPath & "\tmp.jpg") 如果想要存到MemoryStream裡面可以參考下面程式碼,其實都是大同小異 Dim img As Image Dim B As

StopWatch

在前一篇 Performance Count 我們提到用Win32 API來取得程式碼經過的時間,在.Net framework中也提供了 StopWatch 類別供使用,下面是簡單的使用範例 Dim A As New Stopwatch A.Start() Threading.Thread.Sleep(1200) A.Stop() MessageBox.Show(A.ElapsedMilliseconds)

Performance Count

"在撰寫程式的過程中,有些時候我們要知道某些程式碼的效能,那麼要怎麼做呢?我們可以簡單的利用Win32 API來做這樣的功能 Imports System.Runtime.InteropServices Public Class cQueryPerformance Private _Freq As Int64 Private _Count1, _Count2 As Int64 _ Public Shared Function QueryPerformanceFrequency( _ ByRef lpFrequency As Int64) As Integer End Function _ Public Shared Function QueryPerformanceCounter( _ ByRef lpPerformanceCount As Int64) As Integer End Function ''' ''' 設定起始點 ''' ''' ''' Public Function StartCount() As Boolean If QueryPerformanceFrequency(_Freq) <> 0 Then If QueryPerformanceCounter(_Count1) <> 0 Then Return True Else Return False End If Else Return False End If End Function ''' ''' 設定結束點成功並傳回經過時間(ms) ''' ''' '&