Trail of Tears Part 2 (i.e. Control Locations)...
-
Guffa: In response to the following response, I need to ask for some further input. I was able to successfully cause a Timer control to trigger when the dragged control was dropped. However, the dragDropTimer_Tick event cannot retrieve any control so that it could modify its location. Here is what I have so far:
private static void ProvideDragPathReturnToParent(Control ctrl, int intX\_end, int intY\_end, int intX\_start, int intY\_start) { Timer dragDropTimer = new Timer(); dragDropTimer.Enabled = true; dragDropTimer.Interval = 2; dragDropTimer.Tick +=new EventHandler(dragDropTimer\_Tick); dragDropTimer.Start(); } private static void dragDropTimer\_Tick(object sender, System.EventArgs e) { int x = 0, y = 0; //Control cthis = ((Control)sender); for (int index = 0; index <= 64; index++) { x = pt\_start.X + (intX\_end - pt\_start.X) \* index / 64; y = pt\_start.Y + (intY\_end - pt\_start.Y) \* index / 64; } //cthis.Location = new System.Drawing.Point(x, y); MessageBox.Show("Hello"); }
The pt_start System.Drawing.Point was moved to become a public variable in the DragDropHandler. The problem is that I cannot access the control itself because the dragDropTimer_tick event handler has a sender object but it is not the same type as the control being dragged or dropped. How would I access the control itself to implement your suggestion? The timer event handler does actually show MessageBoxes saying the word "Hello" every interval. Please provide additional information. P.S. Others may respond as well. *****************Guffa's Message********** We start with this: new_phoenix wrote: and how would a timer be used to get the form to redraw itself? If you use a timer to trigger the movement of the control, the main message pump would handle messages in between the timer events. If you just change the location of the control, both the control and the previous area of the control will be invalidated. This creates messages that will be handled by the message pump. The message pump will call the Paint event of the control and the form, which will repaint the control and the part of the form that was invalidated. new_phoenix wrote: How could it be done in a loop The x position of a point on the line can be interpolated like this: x = startX + (endX - startX) * index / 64 where index is the index of the point from 0 to 64. The y position can be calculated in the same way. You don
-
Guffa: In response to the following response, I need to ask for some further input. I was able to successfully cause a Timer control to trigger when the dragged control was dropped. However, the dragDropTimer_Tick event cannot retrieve any control so that it could modify its location. Here is what I have so far:
private static void ProvideDragPathReturnToParent(Control ctrl, int intX\_end, int intY\_end, int intX\_start, int intY\_start) { Timer dragDropTimer = new Timer(); dragDropTimer.Enabled = true; dragDropTimer.Interval = 2; dragDropTimer.Tick +=new EventHandler(dragDropTimer\_Tick); dragDropTimer.Start(); } private static void dragDropTimer\_Tick(object sender, System.EventArgs e) { int x = 0, y = 0; //Control cthis = ((Control)sender); for (int index = 0; index <= 64; index++) { x = pt\_start.X + (intX\_end - pt\_start.X) \* index / 64; y = pt\_start.Y + (intY\_end - pt\_start.Y) \* index / 64; } //cthis.Location = new System.Drawing.Point(x, y); MessageBox.Show("Hello"); }
The pt_start System.Drawing.Point was moved to become a public variable in the DragDropHandler. The problem is that I cannot access the control itself because the dragDropTimer_tick event handler has a sender object but it is not the same type as the control being dragged or dropped. How would I access the control itself to implement your suggestion? The timer event handler does actually show MessageBoxes saying the word "Hello" every interval. Please provide additional information. P.S. Others may respond as well. *****************Guffa's Message********** We start with this: new_phoenix wrote: and how would a timer be used to get the form to redraw itself? If you use a timer to trigger the movement of the control, the main message pump would handle messages in between the timer events. If you just change the location of the control, both the control and the previous area of the control will be invalidated. This creates messages that will be handled by the message pump. The message pump will call the Paint event of the control and the form, which will repaint the control and the part of the form that was invalidated. new_phoenix wrote: How could it be done in a loop The x position of a point on the line can be interpolated like this: x = startX + (endX - startX) * index / 64 where index is the index of the point from 0 to 64. The y position can be calculated in the same way. You don
The sender object in your dragDropTimer_Tick event is going to be the timer, try creating a public variable of type control and setting it to the calling control in your ProvideDragPathReturnToParent event and use that variable in your dragDropTimer_Tick event Hope that helps
-
Guffa: In response to the following response, I need to ask for some further input. I was able to successfully cause a Timer control to trigger when the dragged control was dropped. However, the dragDropTimer_Tick event cannot retrieve any control so that it could modify its location. Here is what I have so far:
private static void ProvideDragPathReturnToParent(Control ctrl, int intX\_end, int intY\_end, int intX\_start, int intY\_start) { Timer dragDropTimer = new Timer(); dragDropTimer.Enabled = true; dragDropTimer.Interval = 2; dragDropTimer.Tick +=new EventHandler(dragDropTimer\_Tick); dragDropTimer.Start(); } private static void dragDropTimer\_Tick(object sender, System.EventArgs e) { int x = 0, y = 0; //Control cthis = ((Control)sender); for (int index = 0; index <= 64; index++) { x = pt\_start.X + (intX\_end - pt\_start.X) \* index / 64; y = pt\_start.Y + (intY\_end - pt\_start.Y) \* index / 64; } //cthis.Location = new System.Drawing.Point(x, y); MessageBox.Show("Hello"); }
The pt_start System.Drawing.Point was moved to become a public variable in the DragDropHandler. The problem is that I cannot access the control itself because the dragDropTimer_tick event handler has a sender object but it is not the same type as the control being dragged or dropped. How would I access the control itself to implement your suggestion? The timer event handler does actually show MessageBoxes saying the word "Hello" every interval. Please provide additional information. P.S. Others may respond as well. *****************Guffa's Message********** We start with this: new_phoenix wrote: and how would a timer be used to get the form to redraw itself? If you use a timer to trigger the movement of the control, the main message pump would handle messages in between the timer events. If you just change the location of the control, both the control and the previous area of the control will be invalidated. This creates messages that will be handled by the message pump. The message pump will call the Paint event of the control and the form, which will repaint the control and the part of the form that was invalidated. new_phoenix wrote: How could it be done in a loop The x position of a point on the line can be interpolated like this: x = startX + (endX - startX) * index / 64 where index is the index of the point from 0 to 64. The y position can be calculated in the same way. You don