Posts
[Extension Method][VB.NET]ErrorProvider.GerErrorMsgs amp; ErrorProvider.HasError
Public Module ErrorProviderExtension
<Extension()> _ Public Function GetErrorMsgs(ByVal ep As ErrorProvider) As String() If ep.ContainerControl Is Nothing Then Return New String() {} End If Dim linq = From c In ep.ContainerControl.Controls Let msg = ep.GetError(c) Where msg.Length > 0 Select msg Return linq.ToArray End Function <Extension()> _ Public Function HasError(ByVal ep As ErrorProvider) As Boolean Return ep.GetErrorMsgs.Length > 0 End Function End Module
read morePosts
[VB.NET]密碼框顯示程式探討與其簡易的保護之道
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _ Private Shared Function PostMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Boolean End Function
Const EM_SETPASSWORDCHAR = &HCC Private Sub TargetSelectedControl1_TargetSelected(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TargetSelectedControl1.TargetSelected Dim hWnd As IntPtr = WindowFromPoint(MousePosition) PostMessage(hWnd, EM_SETPASSWORDCHAR, 0, 0) End Sub</pre></div> Const WM_SETTEXT As Integer = &HC Const WM_GETTEXT As Integer = &HD Const EM_SETPASSWORDCHAR = &HCC Sub New() With Me .
read morePosts
[VB.NET]自定義.NET WindowForm表單介面(三)
<DllImport("user32.dll", SetLastError:=True)> _ Private Shared Function SetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer End Function
Public Const WS_SYSMENU As Integer = &H80000 Const WS_MINIMIZEBOX As Integer = &H20000 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim winLong As Integer = GetWindowLong(New HandleRef(Me, Me.Handle), -16) SetWindowLong(New HandleRef(Me, Me.Handle), -16, winLong Or WS_SYSMENU Or WS_MINIMIZEBOX) End Sub</pre></div>
read morePosts
[Linq]Linq程式逐步執行與偵錯
foreach (var item in linq) { Console.WriteLine(item); } }</pre></div> For Each item In linq Console.WriteLine(item) Next End Sub</pre>
read morePosts
[Extension Method][VB.NET]使用擴充方法過濾出組件內的特定類別
Module AssembleExtension <Extension()> _ Public Function GetTypes(ByVal asm As Assembly, ByVal filterTypeName As String, Optional ByVal includeSubClass As Boolean = False) As Type() Return GetTypes(asm, Type.GetType(filterTypeName), includeSubClass) End Function
<Extension()> _ Public Function GetTypes(ByVal asm As Assembly, ByVal filterType As Type, Optional ByVal includeSubClass As Boolean = False) As Type() Dim linq = From t In asm.GetTypes Where t Is filterType OrElse (includeSubClass AndAlso t.IsSubclassOf(filterType)) Select t Return linq.ToArray End Function End Module
read morePosts
[VB.NET]比對兩個目錄中不同的檔案
Module DirectoryInfoExtension <Extension()> _ Function GetDifferentFileList(ByVal sourceDirectoryInfo As DirectoryInfo, ByVal targetDirectoryInfo As DirectoryInfo, Optional ByVal searchPattern As String = “.”, Optional ByVal searchOption As SearchOption = SearchOption.TopDirectoryOnly) As FileInfo() If sourceDirectoryInfo Is Nothing Then Throw New ArgumentNullException(“sourceDirectoryInfo”) End If If targetDirectoryInfo Is Nothing Then Throw New ArgumentNullException(“targetDirectoryInfo”) End If If targetDirectoryInfo.FullName = sourceDirectoryInfo.FullName Then Return New FileInfo() {} End If Dim sourceFiles = sourceDirectoryInfo.GetFiles(searchPattern, searchOption) Dim destFiles = targetDirectoryInfo.GetFiles(searchPattern, searchOption) Dim intersectFiles = sourceFiles.
read more