locked
change button location inside this method RRS feed

  • Question

  • hello evryone

    after searching for 1 month i found one class that called helper and to use it i just call it in my int function and pass control name as parameter to it

    this class allow you to move the control like drag and drop on your form at run time

    what i want is : when the control move to new location will move another control or controls with him

    so i made a n arraylist to save controls name inside it and made a faunction to pass parameters location x,y and control name to move it ,it is called MoveMe()

    i want to call this function in the event mouseup in this helper class so what i did is i take the code from this class and add it to my form2 class to be part of my class

    this is the code:

    public static void Init(Control control)
            {
                Init(control, Direction.Any);
            }
    
            public static void Init(Control control, Direction direction)
            {
                Init(control, control, direction);
            }
    
            public static void Init(Control control, Control container, Direction direction)
            {
                bool Dragging = false;
                Point DragStart = Point.Empty;
                control.MouseDown += delegate(object sender, MouseEventArgs e)
                {
                    Dragging = true;
                    DragStart = new Point(e.X, e.Y);
                    control.Capture = true;
                };
                control.MouseUp += delegate(object sender, MouseEventArgs e)
                {
                    Dragging = false;
                    control.Capture = false;
                    
                };
                control.MouseMove += delegate(object sender, MouseEventArgs e)
                {
                    if (Dragging)
                    {
                        if (direction != Direction.Vertical)
                            container.Left = Math.Max(0, e.X + container.Left - DragStart.X);
                        if (direction != Direction.Horizontal)
                            container.Top = Math.Max(0, e.Y + container.Top - DragStart.Y);
                    }
                };
                
    
            }
    

    when i call my funaction MoveMe inside control.MouseUp it is not recognaizing and i canot find it as normal.

    this is my funaction

     public void MoveMe(string con, int x, int y)
            {
                int space;
                Point npoint;
                npoint = new Point();
                space = x + 85;
    
                npoint.Offset(space, y);
                //con.Capture = true;
                this.Controls.Find(con, true)[0].Location = npoint;
                this.Controls.Find(con, true)[0].BackColor = Color.Empty;
                //con.Location = npoint;
                //con.Capture = false;
    
            }

    where is my mistake and how can i corract it?


    Thanks for any help :) my blog is: http://www.waelk.com

    Sunday, November 11, 2012 6:55 AM

Answers

  • Let me show you an example of an event hendler.  I have a DataGridview with a combobox column.  Here is the code I use to handle the event

               static void SummaryDataGridCntl_EditingControlShowing
                                     (object sender
                                      , DataGridViewEditingControlShowingEventArgs e)
               {
                   var comboControl = e.Control as ComboBox;
                   var DGV = sender as DataGridView;
                   var cell = DGV.CurrentCell;

    The object that is selected is sent to the interupt handler in the sender and e variables.  Only objects that at selected are sent and only one at a time.  If you are trying to move more than one object I would assume you would use the control key to highlight the two objects and they would be sent to the mouse event handler as a group so you wouldn't need to handle multiple objects.  Not sure what you are trying to accomplish by making a List<> of multiple objects. I'm not sure how that would work.


    jdweng

    Sunday, November 11, 2012 11:58 AM