© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•11mo ago
Mariyana

winforms c# --> translateTo method

public void TranslateTo(PointF p)
{
// дали има избрани фигури за преместване
if (Selection.Count == 0 || Selection == null)
{
return;
}

PointF currentPoint = new PointF(p.X, p.Y);

if(lastLocation == null)
{
lastLocation = currentPoint;
return;
}

// минава през всички избрани фигури
foreach (Shape shape in Selection)
{

using (Matrix invertMatric = shape.TransformationMatrix.Clone())
{
try
{
invertMatric.Invert();
}
catch (Exception ex)
{

Console.WriteLine($"Error invert {ex.Message}");
}

PointF[] pointsArray = new PointF[] {currentPoint,lastLocation};
invertMatric.TransformPoints(pointsArray);

PointF localP = pointsArray[0];
PointF localLastLocation = pointsArray[1];

float deltaX = localP.X - localLastLocation.X;
float deltaY = localP.Y - localLastLocation.Y;


if(!(shape is GroupShape))
{
shape.Location = new PointF(shape.Location.X + deltaX, shape.Location.Y + deltaY);
}


if (shape is GroupShape group && group.SubShapes != null)
{

foreach (Shape subShape in group.SubShapes)
{
if (subShape == null) continue;

subShape.Location = new PointF(subShape.Location.X + deltaX, subShape.Location.Y + deltaY);
}
}
}
when i have a group , the figures in the group are not moving synchronized
message.txt4.25KB
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

c# winforms size
C#CC# / help
9mo ago
C# WinForms Chat
C#CC# / help
2y ago
please help!!! (winforms c#)
C#CC# / help
3y ago
✅ c# winforms toggle switch help
C#CC# / help
3y ago