© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
1 reply
DisfunctionalCucumber

❔ CS0123No overload for 'CanvasMain_PreviewMouseMove' matches delegate for 'EventMouseHandler'

Basically i'm trying to make a system where there is a grid with moveable objects - if you drag the object to a certain position and let go, it will snap to the nearest grid cell. I have no clue what a delegate is or how to solve this error - I appreciate any help and here is the code below:

private void CanvasMain_PreviewMouseMove(object sender, MouseEventArgs e)
{

int numofcolumns = 2; //This is to work out the coordinates of the centre of each cell.
int numofrows = 2;
int displaywidth = 800;
int displayheight = 450;
int cellwidth = displaywidth / numofcolumns;
int cellheight = displayheight / numofrows;
if (this.dragObject == null)
return;
var position = e.GetPosition(sender as IInputElement);
Canvas.SetTop(this.dragObject, position.Y - this.offset.Y);
Canvas.SetLeft(this.dragObject, position.X - this.offset.X);
if (this.dragObject !=null)
{
System.Windows.Point offset = e.GetPosition(this.CanvasMain);

//Calculates position for object to snap to
double SnapX = (offset.X / cellwidth) * cellwidth + cellheight / 2;
double SnapY = (offset.Y / cellheight) * cellheight + cellwidth / 2;

}

}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Modify delegate for ILGPU acceptance
C#CC# / help
3y ago
Delegate type mismatch
C#CC# / help
3y ago
✅ Use() Extension Overload
C#CC# / help
2y ago
Delegate with Task problem
C#CC# / help
2y ago