⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmmain.vb

📁 Microsoft Mobile Development Handbook的代码,有C#,VB,C++的
💻 VB
字号:
Imports Microsoft.VisualBasic
Imports System
Imports System.Windows.Forms
Imports Microsoft.WindowsCE.Forms
Imports System.Drawing

Namespace CodeForChapter2
  Public Partial Class frmMain
	  Inherits Form
	Public Sub New()
	  InitializeComponent()
	End Sub

	#Region "Orientation and size"
	Private Sub frmMain_Resize(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Resize
	  ' use the info for repositioning controls
	  label1.Text = "Orientation is " & SystemSettings.ScreenOrientation.ToString()
	  label2.Text = "Screen size is " & Screen.PrimaryScreen.Bounds.Width & " x " & Screen.PrimaryScreen.Bounds.Height
	End Sub

	Private Sub menuItem5_Click(ByVal sender As Object, ByVal e As EventArgs) Handles menuItem5.Click
	  SystemSettings.ScreenOrientation = ScreenOrientation.Angle0
	End Sub

	Private Sub menuItem6_Click(ByVal sender As Object, ByVal e As EventArgs) Handles menuItem6.Click
	  SystemSettings.ScreenOrientation = ScreenOrientation.Angle90
	End Sub

	Private Sub menuItem8_Click(ByVal sender As Object, ByVal e As EventArgs) Handles menuItem8.Click
	  SystemSettings.ScreenOrientation = ScreenOrientation.Angle180
	End Sub

	Private Sub menuItem7_Click(ByVal sender As Object, ByVal e As EventArgs) Handles menuItem7.Click
	  SystemSettings.ScreenOrientation = ScreenOrientation.Angle270
	End Sub

	#End Region

	#Region "Cursor"
	Private Sub menuItem2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles menuItem2.Click
	  Cursor.Current = Cursors.WaitCursor
	End Sub

	Private Sub menuItem3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles menuItem3.Click
	  Cursor.Current = Cursors.Default
	End Sub

	#End Region

	#Region "mouse_event"
	' Button1 event handler. Simulates button click OR opening a main menu.
	' Same principle applies for ToolBarButton
	Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
	  PerformMouseClick(Me.Left + 5, Me.Height + 5, Me)
	End Sub

	' Wrapper for mouse_event, performing click action on coordinates given
	Public Shared Sub PerformMouseClick(ByVal x As Int32, ByVal y As Int32, ByVal f As Control)
	  Dim p As Point = f.PointToScreen(New Point(x, y))

      Dim m1 As Int32 = (65535 \ Screen.PrimaryScreen.Bounds.Width)
      Dim m2 As Int32 = (65535 \ Screen.PrimaryScreen.Bounds.Height)

	  Dim x2 As Int32 = m1 * p.X
	  Dim y2 As Int32 = m2 * p.Y

	  mouse_event(2 Or &H8000, x2, y2, 0, 0)
	  mouse_event(4 Or &H8000, x2, y2, 0, 0)
	End Sub

	<System.Runtime.InteropServices.DllImport("coredll.dll")> _
	Public Shared Sub mouse_event(ByVal dwFlags As Int32, ByVal dx As Int32, ByVal dy As Int32, ByVal dwData As Int32, ByVal dwExtraInfo As Int32)
	End Sub

	#End Region

	Private Sub SomeMethod()
#If PocketPC Then
	  ' do soemthing PocketPC-specific
#ElseIf Smartphone Then
	  ' do something Smartphone-specific
#Else
	  ' do something desktop-specific
#End If
	End Sub

	' Show form ensuring that:
	' 1. only one entry appears in the running list
	' 2. the single entry has the same caption regardless of form shown
	Private Sub button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button3.Click
	  Dim f As frmShown = New frmShown()


	  If checkBox1.Checked Then ' show modal
		f.Owner = Me
		f.ShowDialog()
	  Else
		f.MinimizeBox = False
		f.Text = Me.Text
		caption = Me.Text
		Me.Text = "" 'hides the form from the list
		AddHandler f.Closed, AddressOf f_Closed
		f.Show()
		' code in this form still runs (i.e. it is not modal)
		' but the user cannot navigate to it until they close the one shown
	  End If
	End Sub

	Private caption As String
	Private Sub f_Closed(ByVal sender As Object, ByVal e As EventArgs)
	  Me.Text = caption
	  Me.BringToFront()
	End Sub

	Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button2.Click
	  Dim f As frmShown = New frmShown()
	  If checkBox1.Checked Then ' show modal
		f.ShowDialog()
	  Else
		f.Show()
	  End If
	End Sub
  End Class
End Namespace

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -