home *** CD-ROM | disk | FTP | other *** search
/ ftp.tcs3.com / ftp.tcs3.com.tar / ftp.tcs3.com / DRIVERS / Audio / Office2010 / InfoPath.en-us / InfLR.cab / FL_DrawaRubberBandRectangle_snippet_142658_ENU____.3643236F_FC70_11D3_A536_0090278A1BB8 < prev    next >
Extensible Markup Language  |  2008-09-17  |  3KB  |  109 lines

  1. <?xml version="1.0"?>
  2. <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  3.   <CodeSnippet Format="1.0.0">
  4.     <Header>
  5.       <Title>Draw a Rubber Band Rectangle</Title>
  6.       <Author>Microsoft Corporation</Author>
  7.       <Description>Draws a rubber band rectangle on the form.</Description>
  8.       <Shortcut>drawBand</Shortcut>
  9.     </Header>
  10.     <Snippet>
  11.       <References>
  12.         <Reference>
  13.           <Assembly>System.Windows.Forms</Assembly>
  14.         </Reference>
  15.         <Reference>
  16.           <Assembly>System.Drawing</Assembly>
  17.         </Reference>
  18.       </References>
  19.       <Imports>
  20.         <Import>
  21.           <Namespace>Microsoft.VisualBasic</Namespace>
  22.         </Import>
  23.         <Import>
  24.           <Namespace>System.Drawing</Namespace>
  25.         </Import>
  26.         <Import>
  27.           <Namespace>System.Windows.Forms</Namespace>
  28.         </Import>
  29.       </Imports>
  30.       <Code Language="VB" Kind="method decl"><![CDATA[Dim originalPoint As Point = New Point()
  31. Dim lastPoint As Point = New Point()
  32. Dim mouseIsDown As Boolean
  33.  
  34. Public Sub MyMouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseDown
  35.  
  36.     mouseIsDown = True
  37.     originalPoint.X = e.X
  38.     originalPoint.Y = e.Y
  39.     lastPoint.X = -1
  40.     lastPoint.Y = -1
  41.  
  42. End Sub
  43.  
  44. Private Sub MyDrawReversibleRectangle(ByVal point1 As Point, ByVal point2 As Point)
  45.  
  46.     Dim rect As Rectangle = New Rectangle()
  47.  
  48.     point1 = PointToScreen(point1)
  49.     point2 = PointToScreen(point2)
  50.  
  51.     If point1.X < point2.X Then
  52.         rect.X = point1.X
  53.         rect.Width = point2.X - point1.X
  54.     Else
  55.         rect.X = point2.X
  56.         rect.Width = point1.X - point2.X
  57.     End If
  58.  
  59.     If point1.Y < point2.Y Then
  60.         rect.Y = point1.Y
  61.         rect.Height = point2.Y - point1.Y
  62.     Else
  63.         rect.Y = point2.Y
  64.         rect.Height = point1.Y - point2.Y
  65.     End If
  66.  
  67.     ControlPaint.DrawReversibleFrame(rect, _
  68.  Color.Yellow, FrameStyle.Thick)
  69.  
  70. End Sub
  71.  
  72. Public Sub MyMouseUp(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Me.MouseUp
  73.  
  74.     mouseIsDown = False
  75.  
  76.     If lastPoint.X <> -1 Then
  77.         Dim currentPoint As Point = New Point(e.X, e.Y)
  78.         MyDrawReversibleRectangle(originalPoint, lastPoint)
  79.     End If
  80.  
  81.     lastPoint.X = -1
  82.     lastPoint.Y = -1
  83.     originalPoint.X = -1
  84.     originalPoint.Y = -1
  85.  
  86. End Sub
  87.  
  88. Public Sub MyMouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Me.MouseMove
  89.  
  90.     Dim currentPoint As Point = New Point(e.X, e.Y)
  91.  
  92.     If mouseIsDown Then
  93.  
  94.         If lastPoint.X <> -1 Then
  95.             MyDrawReversibleRectangle(originalPoint, lastPoint)
  96.         End If
  97.  
  98.         lastPoint = currentPoint
  99.         MyDrawReversibleRectangle(originalPoint, currentPoint)
  100.     End If
  101.  
  102. End Sub
  103.  
  104. Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
  105.     mouseIsDown = False
  106. End Sub]]></Code>
  107.     </Snippet>
  108.   </CodeSnippet>
  109. </CodeSnippets>