リサイズコンポーネントでLineShape、OvalShape、RectangleShapeのリサイズ時に発生する問題を回避するリサイズポリシー
対象製品
PlusPak for Windows Forms 7.0J
詳細
リサイズコンポーネント(GcResize)を使用して、Visual Basic PowerPacksのLineShape、OvalShape、RectangleShapeコントロールをリサイズする場合、下記の問題が発生します。
本現象は、Shapeコントロールにおける制限事項です。以下のコードを使用してユーザー定義のリサイズポリシーを追加することで対応できます。
なお、本現象はリサイズパネル(GcResizePanel)でも発生しますが、同じ方法で対応できます。
ユーザー定義のリサイズポリシーの使い方については、製品ヘルプの以下の内容をご参照ください。
PowerTools PlusPak for Windows Forms 7.0J
- PlusPak の使い方
- レイアウト
- GcResize コンポーネント
- リサイズポリシー
- フォームのサイズ変更に合わせてコントロールをリサイズできない
本現象は、Shapeコントロールにおける制限事項です。以下のコードを使用してユーザー定義のリサイズポリシーを追加することで対応できます。
なお、本現象はリサイズパネル(GcResizePanel)でも発生しますが、同じ方法で対応できます。
ユーザー定義のリサイズポリシーの使い方については、製品ヘルプの以下の内容をご参照ください。
PowerTools PlusPak for Windows Forms 7.0J
- PlusPak の使い方
- レイアウト
- GcResize コンポーネント
- リサイズポリシー
[Visual Basic]
Imports Microsoft.VisualBasic.PowerPacks
Imports GrapeCity.Win.Components
Public Class ShapeContainerResizePolicy
Inherits ResizePolicy
Public Overrides ReadOnly Property TargetType() As Type
Get
Return GetType(ShapeContainer)
End Get
End Property
Public Overrides Sub ResizeLayout(control As Control, infos As ResizeLayoutInfo)
Dim shapeContainer As ShapeContainer = TryCast(control, ShapeContainer)
For Each shape As Shape In shapeContainer.Shapes
If TypeOf shape Is SimpleShape Then
Dim simpleShape As SimpleShape = TryCast(shape, SimpleShape)
simpleShape.Bounds = infos.ScaleRectangle(simpleShape.Bounds)
ElseIf TypeOf shape Is LineShape Then
Dim lineShape As LineShape = TryCast(shape, LineShape)
lineShape.StartPoint = New Point(infos.ScaleX(lineShape.StartPoint.X), infos.ScaleY(lineShape.StartPoint.Y))
lineShape.EndPoint = New Point(infos.ScaleX(lineShape.EndPoint.X), infos.ScaleY(lineShape.EndPoint.Y))
End If
Next
MyBase.ResizeLayout(control, infos)
End Sub
End Class
Imports Microsoft.VisualBasic.PowerPacks
Imports GrapeCity.Win.Components
Public Class ShapeContainerResizePolicy
Inherits ResizePolicy
Public Overrides ReadOnly Property TargetType() As Type
Get
Return GetType(ShapeContainer)
End Get
End Property
Public Overrides Sub ResizeLayout(control As Control, infos As ResizeLayoutInfo)
Dim shapeContainer As ShapeContainer = TryCast(control, ShapeContainer)
For Each shape As Shape In shapeContainer.Shapes
If TypeOf shape Is SimpleShape Then
Dim simpleShape As SimpleShape = TryCast(shape, SimpleShape)
simpleShape.Bounds = infos.ScaleRectangle(simpleShape.Bounds)
ElseIf TypeOf shape Is LineShape Then
Dim lineShape As LineShape = TryCast(shape, LineShape)
lineShape.StartPoint = New Point(infos.ScaleX(lineShape.StartPoint.X), infos.ScaleY(lineShape.StartPoint.Y))
lineShape.EndPoint = New Point(infos.ScaleX(lineShape.EndPoint.X), infos.ScaleY(lineShape.EndPoint.Y))
End If
Next
MyBase.ResizeLayout(control, infos)
End Sub
End Class
[C#]
using GrapeCity.Win.Components;
using Microsoft.VisualBasic.PowerPacks;
public class ShapeContainerResizePolicy : ResizePolicy
{
public override Type TargetType
{
get { return typeof(ShapeContainer); }
}
public override void ResizeLayout(Control control, ResizeLayoutInfo infos)
{
ShapeContainer shapeContainer = control as ShapeContainer;
foreach (Shape shape in shapeContainer.Shapes)
{
if (shape is SimpleShape)
{
SimpleShape simpleShape = shape as SimpleShape;
simpleShape.Bounds = infos.ScaleRectangle(simpleShape.Bounds);
}
else if (shape is LineShape)
{
LineShape lineShape = shape as LineShape;
lineShape.StartPoint = new Point(infos.ScaleX(lineShape.StartPoint.X), infos.ScaleY(lineShape.StartPoint.Y));
lineShape.EndPoint = new Point(infos.ScaleX(lineShape.EndPoint.X), infos.ScaleY(lineShape.EndPoint.Y));
}
}
base.ResizeLayout(control, infos);
}
}
using GrapeCity.Win.Components;
using Microsoft.VisualBasic.PowerPacks;
public class ShapeContainerResizePolicy : ResizePolicy
{
public override Type TargetType
{
get { return typeof(ShapeContainer); }
}
public override void ResizeLayout(Control control, ResizeLayoutInfo infos)
{
ShapeContainer shapeContainer = control as ShapeContainer;
foreach (Shape shape in shapeContainer.Shapes)
{
if (shape is SimpleShape)
{
SimpleShape simpleShape = shape as SimpleShape;
simpleShape.Bounds = infos.ScaleRectangle(simpleShape.Bounds);
}
else if (shape is LineShape)
{
LineShape lineShape = shape as LineShape;
lineShape.StartPoint = new Point(infos.ScaleX(lineShape.StartPoint.X), infos.ScaleY(lineShape.StartPoint.Y));
lineShape.EndPoint = new Point(infos.ScaleX(lineShape.EndPoint.X), infos.ScaleY(lineShape.EndPoint.Y));
}
}
base.ResizeLayout(control, infos);
}
}