Posts
[VB.NET]MDI子視窗清單的實作
Private Sub WindowsMenu_DropDownOpening(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WindowsMenu.DropDownOpening If ActiveMdiChild Is Nothing Then Return End If Dim sp As New ToolStripSeparator sp.Name = "MdiWindowListSeperator" WindowsMenu.DropDownItems.Add(sp) For Each f As Form In MdiChildren If Not f.Visible Then Continue For End If WindowsMenu.DropDownItems.Add(New ToolStripMenuItem(f.Text, Nothing, AddressOf MDIChildren_Click) With {.Checked = ActiveMdiChild Is f, .Tag = f}) Next End Sub Private Sub MDIChildren_Click(ByVal sender As Object, ByVal e As EventArgs) DirectCast(DirectCast(sender, ToolStripMenuItem).
read morePosts
[VB.NET]使用Win32 API擷取滑鼠游標位置的顏色
Private Function GetColor() As Color Return GetColor(Cursor.Position) End Function Private Function GetColor(ByVal point As Point) As Color Return GetColor(point.X, point.Y) End Function Private Function GetColor(ByVal x As Integer, ByVal y As Integer) As Color Dim hdc As IntPtr hdc = GetDC(IntPtr.Zero) '取該Handle值的DC GetColor = ColorTranslator.FromWin32(GetPixel(hdc, x, y)) ReleaseDC(IntPtr.Zero, hdc) '將DC 釋放 End Function</pre></div> Public Class Form1 <DllImport(“User32.dll”, EntryPoint:=“GetDC”, _ CallingConvention:=CallingConvention.StdCall, _ CharSet:=CharSet.Auto, exactspelling:=True)> _ Public Shared Function GetDC(ByVal hwnd As IntPtr) As IntPtr End Function Public Declare Function GetPixel Lib “gdi32” Alias “GetPixel” (ByVal hdc As IntPtr, ByVal X As Int32, ByVal Y As Int32) As Int32 <DllImport(“user32.
read morePosts
[VB.NET]使用mouse_event API 來操控滑鼠動作
<td valign="top" width="404">說明</td> </tr> <tr> <td valign="top" width="91"><em>dwFlags</em></td> <td valign="top" width="404">指示滑鼠動作</td> </tr> <tr> <td valign="top" width="91">dx</td> <td valign="top" width="404">x座標 (dwFlags有設MOUSEEVENTF_ABSOLUTE時,該座標為絕對座標)</td> </tr> <tr> <td valign="top" width="91">dy</td> <td valign="top" width="404">y座標 (dwFlags有設MOUSEEVENTF_ABSOLUTE時,該座標為絕對座標)</td> </tr> <tr> <td valign="top" width="91">dwData</td> <td valign="top" width="404">dwFlags為MOUSEEVENTF_HWHEEL時,該值代表捲軸捲動的量。 <br /> <br />dwFlags為MOUSEEVENTF_XDOWN或MOUSEEVENTF_XUP時,該值可為XBUTTON1 (&H0001)或XBUTTON2 (&H0002)。 <br /> <br />當dwFlags不為MOUSEEVENTF_HWHEEL、 <br />MOUSEEVENTF_XDOWN或MOUSEEVENTF_XUP,該值為0。</td> </tr> <tr> <td valign="top" width="91">dwExtraInfo</td> <td valign="top" width="404">An additional value associated with the mouse event. An application calls <strong>GetMessageExtraInfo</strong> to obtain this extra information.
read morePosts
[VB.NET]將集合類別繫結至DataGridView並使其具備新增功能
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim lst As New List(Of Person) lst.Add(New Person With {.Name = "Larry"}) DataGridView1.DataSource = lst End Sub End Class
Class Person Dim _name As String Property Name() As String Get Return _name End Get Set(ByVal value As String) _name = value End Set End Property End Class
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.
read morePosts
[VB.NET]SecureString較為安全的加密字串類別
Public Sub PrintSecureString(ByVal secureString As SecureString) ... End Sub</pre></div> Module Module1
Sub Main() Console.WriteLine("Please enter your password to be encrypted:") Dim password As SecureString = ReadPassword() Console.WriteLine() Console.WriteLine("Decripted password:") PrintPassword(password) End Sub Public Function ReadPassword() As SecureString Dim password As New SecureString() Dim nextKey As ConsoleKeyInfo = Console.ReadKey(True) While nextKey.Key <> ConsoleKey.Enter If nextKey.Key = ConsoleKey.Backspace Then If password.Length > 0 Then password.RemoveAt(password.Length - 1) ' erase the last * as well Console.
read morePosts
[VB.NET]Keys lt;=gt; Char
Module Module1
Sub Main() Dim key As Keys = Keys.A Dim keyChar As Char = Convert.ToChar(key) Console.WriteLine(Convert.ToChar(key)) Console.WriteLine(Asc(keyChar)) Console.WriteLine(Microsoft.VisualBasic.ChrW(key)) End Sub End Module
read more