Shape.PointToScreen メソッド
更新 : 2007 年 11 月
指定したクライアント ポイントの位置を計算して画面座標を算出します。
名前空間 : Microsoft.VisualBasic.PowerPacks
アセンブリ : Microsoft.VisualBasic.PowerPacks.Vs (Microsoft.VisualBasic.PowerPacks.Vs.dll 内)
構文
'宣言
Public Function PointToScreen ( _
p As Point _
) As Point
'使用
Dim instance As Shape
Dim p As Point
Dim returnValue As Point
returnValue = instance.PointToScreen(p)
public Point PointToScreen(
Point p
)
public:
Point PointToScreen(
Point p
)
public function PointToScreen(
p : Point
) : Point
パラメータ
p
型 : System.Drawing.Pointクライアント座標で示された変換対象の Point。
戻り値
例
ドラッグ操作がクライアント領域で終了したときに、PointToScreen メソッドと RectangleToScreen メソッドを使用して RectangleShape の色を変更する例を次に示します。この例では、RectangleShape1 という名前の RectangleShape コントロールがフォーム上に配置され、BackStyle プロパティが Opaque に設定されている必要があります。
Public isDrag As Boolean = True
Public theRectangle As System.Drawing.Rectangle
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles _
RectangleShape1.MouseMove
' If the mouse is being dragged, undraw and redraw the rectangle
' while the mouse moves.
If (isDrag) Then
' Hide the previous rectangle by calling the
' DrawReversibleFrame method, using the same parameters.
ControlPaint.DrawReversibleFrame(theRectangle, Me.BackColor, _
FrameStyle.Dashed)
' Calculate the endpoint and dimensions for the new rectangle,
' again by using the PointToScreen method.
Dim startPoint As Point = New Point(RectangleShape1.Width, _
RectangleShape1.Height)
Dim endPoint As Point = RectangleShape1.PointToScreen(New Point(e.X, e.Y))
Dim width As Integer = endPoint.X - startPoint.X
Dim height As Integer = endPoint.Y - startPoint.Y
theRectangle = New Rectangle(startPoint.X, startPoint.Y, _
width, height)
' Draw the new rectangle by calling DrawReversibleFrame again.
ControlPaint.DrawReversibleFrame(theRectangle, Me.BackColor, _
FrameStyle.Dashed)
End If
End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles RectangleShape1.MouseUp
' If the MouseUp event occurs, the user is not dragging.
isDrag = False
' Draw the rectangle to be evaluated. Set a dashed frame style
' by using the FrameStyle enumeration.
ControlPaint.DrawReversibleFrame(theRectangle, Me.BackColor, _
FrameStyle.Dashed)
' Find out which controls intersect the rectangle, and change
' their colors.
' The method uses the RectangleToScreen method to convert the
' control's client coordinates to screen coordinates.
Dim controlRectangle As Rectangle
controlRectangle = RectangleShape1.RectangleToScreen _
(RectangleShape1.ClientRectangle)
If controlRectangle.IntersectsWith(theRectangle) Then
RectangleShape1.BackColor = Color.BurlyWood
End If
' Reset the rectangle.
theRectangle = New Rectangle(0, 0, 0, 0)
End Sub
public bool isDrag = true;
public System.Drawing.Rectangle theRectangle;
private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
// If the mouse is being dragged, undraw and redraw the rectangle
// while the mouse moves.
if (isDrag)
// Hide the previous rectangle by calling the
// DrawReversibleFrame method, using the same parameters.
{
ControlPaint.DrawReversibleFrame(theRectangle, this.BackColor, FrameStyle.Dashed);
// Calculate the endpoint and dimensions for the new rectangle,
// again by using the PointToScreen method.
Point startPoint = new Point(rectangleShape1.Width, rectangleShape1.Height);
Point endPoint = rectangleShape1.PointToScreen(new Point(e.X, e.Y));
int width = endPoint.X - startPoint.X;
int height = endPoint.Y - startPoint.Y;
theRectangle = new Rectangle(startPoint.X, startPoint.Y, width, height);
// Draw the new rectangle by calling DrawReversibleFrame again.
ControlPaint.DrawReversibleFrame(theRectangle, this.BackColor, FrameStyle.Dashed);
}
}
private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
// If the MouseUp event occurs, the user is not dragging.
isDrag = false;
// Draw the rectangle to be evaluated. Set a dashed frame style
// by using the FrameStyle enumeration.
ControlPaint.DrawReversibleFrame(theRectangle, this.BackColor, FrameStyle.Dashed);
// Find out which controls intersect the rectangle, and change
// their colors.
// The method uses the RectangleToScreen method to convert the
// control's client coordinates to screen coordinates.
Rectangle controlRectangle;
controlRectangle = rectangleShape1.RectangleToScreen(rectangleShape1.ClientRectangle);
if (controlRectangle.IntersectsWith(theRectangle))
{
rectangleShape1.BackColor = Color.BurlyWood;
}
// Reset the rectangle.
theRectangle = new Rectangle(0, 0, 0, 0);
}
アクセス許可
- 直前の呼び出し元に対する完全な信頼。このメンバは、部分的に信頼されているコードから使用することはできません。詳細については、「部分信頼コードからのライブラリの使用」を参照してください。
参照
参照
Microsoft.VisualBasic.PowerPacks 名前空間
その他の技術情報
方法 : LineShape コントロールを使用して線を描画する (Visual Studio)
方法 : OvalShape コントロールおよび RectangleShape コントロールを使用して図形を描画する (Visual Studio)