DisfunctionalCucumber
DisfunctionalCucumber
CC#
Created by DisfunctionalCucumber on 10/22/2023 in #help
❔ 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; } }
2 replies
CC#
Created by DisfunctionalCucumber on 9/16/2023 in #help
❔ How can I make it so an array saves changes when I turn off the program
Basically I'm making an array of strings that can be removed or added to - how can I make it so if say I add the string "Dog" to it, when I come back to the code it will still have "Dog" in it without me having to re-add it. I'm in college so I have very little knowledge of C# but I am trying to learn. I use Visual Studio Community. Thanks
15 replies