本文整理汇总了VB.NET中System.Runtime.InteropServices.LayoutKind枚举的典型用法代码示例。如果您正苦于以下问题:VB.NET LayoutKind枚举的具体用法?VB.NET LayoutKind怎么用?VB.NET LayoutKind使用的例子?那么恭喜您, 这里精选的枚举代码示例或许可以为您提供帮助。
在下文中一共展示了LayoutKind枚举的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Main
' The program shows a managed declaration of the PtInRect function and defines Point
' structure with sequential layout and Rect structure with explicit layout. The PtInRect
' checks the point lies within the rectangle or not.
Imports System.Runtime.InteropServices
Enum Bool
[False] = 0
[True]
End Enum
<StructLayout(LayoutKind.Sequential)> _
Public Structure Point
Public x As Integer
Public y As Integer
End Structure
<StructLayout(LayoutKind.Explicit)> _
Public Structure Rect
<FieldOffset(0)> Public left As Integer
<FieldOffset(4)> Public top As Integer
<FieldOffset(8)> Public right As Integer
<FieldOffset(12)> Public bottom As Integer
End Structure
Friend Class NativeMethods
<DllImport("user32.dll", CallingConvention := CallingConvention.StdCall)> _
Friend Shared Function PtInRect(ByRef r As Rect, p As Point) As Bool
End Function
End Class
Class TestApplication
Public Shared Sub Main()
Try
Dim bPointInRect As Bool = 0
Dim myRect As New Rect()
myRect.left = 10
myRect.right = 100
myRect.top = 10
myRect.bottom = 100
Dim myPoint As New Point()
myPoint.x = 50
myPoint.y = 50
bPointInRect = NativeMethods.PtInRect(myRect, myPoint)
If bPointInRect = Bool.True Then
Console.WriteLine("Point lies within the Rect")
Else
Console.WriteLine("Point did not lie within the Rect")
End If
Catch e As Exception
Console.WriteLine(("Exception : " + e.Message.ToString()))
End Try
End Sub
End Class