Move the control through the panels

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Prajaktaj
    New Member
    • Apr 2008
    • 34

    Move the control through the panels

    Hi All,
    I have one control which i want to move through the various panels? how can i do so without setting the sendToBack() proprty? Please Help me out.
    Thanks for your help :)
  • balame2004
    New Member
    • Mar 2008
    • 142

    #2
    Originally posted by Prajaktaj
    Hi All,
    I have one control which i want to move through the various panels? how can i do so without setting the sendToBack() proprty? Please Help me out.
    Thanks for your help :)


    Hi,

    Set parent property of control to be a panel that you want.

    Eg: this.button1.Pa rent=panel3;


    Try this:

    //Global variable
    private int time=1;

    private void timer1_Tick(obj ect sender, System.EventArg s e)
    {
    time+=1;
    if(time%3==0)
    {
    this.button1.Pa rent=panel3;
    }
    else if(time%2==0)
    {
    this.button1.Pa rent=panel2;
    }
    else if(time%1==0)
    {
    this.button1.Pa rent=panel1;
    }

    }
    }


    Regards,
    Balaji U

    Comment

    • Prajaktaj
      New Member
      • Apr 2008
      • 34

      #3
      Originally posted by balame2004
      Hi,

      Set parent property of control to be a panel that you want.

      Eg: this.button1.Pa rent=panel3;


      Try this:

      //Global variable
      private int time=1;

      private void timer1_Tick(obj ect sender, System.EventArg s e)
      {
      time+=1;
      if(time%3==0)
      {
      this.button1.Pa rent=panel3;
      }
      else if(time%2==0)
      {
      this.button1.Pa rent=panel2;
      }
      else if(time%1==0)
      {
      this.button1.Pa rent=panel1;
      }

      }
      }


      Regards,
      Balaji U

      Hi Balaji,
      Thanks alot for your reply. But by doing so the control e.g in your example Button1 gets disappear from current panel. So what could be the solution you think? And If I want to move it anywhere without knowing runtime what the parent control could be then which control be set as parent?
      Thanks

      Comment

      • balame2004
        New Member
        • Mar 2008
        • 142

        #4
        Originally posted by Prajaktaj
        Hi Balaji,
        Thanks alot for your reply. But by doing so the control e.g in your example Button1 gets disappear from current panel. So what could be the solution you think? And If I want to move it anywhere without knowing runtime what the parent control could be then which control be set as parent?
        Thanks
        Hi,

        1. Sorry I forgot to let you know that you should also change the location of the button control.

        Eg:
        button1.Locatio n=new Point(panel1.Lo cation.X+2, panel1.Location .Y+2);
        button1.Parent= panel1;

        2.By default control is added to the container in which you drag and drop your control. So the parent of your control is the container in which you added your control. Eg : if you drag and drop a button control in the form, it is added to the form and the following source code is automatically added. You can see the below code under InititalizeComp onent() method after you added button1 in your windows form.

        this.Controls.A dd(this.button1 ); // So the form is set to be parent for button1



        So form object is the best container in which you can move your controls without knowing runtime.

        Eg: this.button1.Pa rent=this;

        Regards,
        Balaji U

        Comment

        • Prajaktaj
          New Member
          • Apr 2008
          • 34

          #5
          Originally posted by balame2004
          Hi,

          1. Sorry I forgot to let you know that you should also change the location of the button control.

          Eg:
          button1.Locatio n=new Point(panel1.Lo cation.X+2, panel1.Location .Y+2);
          button1.Parent= panel1;

          2.By default control is added to the container in which you drag and drop your control. So the parent of your control is the container in which you added your control. Eg : if you drag and drop a button control in the form, it is added to the form and the following source code is automatically added. You can see the below code under InititalizeComp onent() method after you added button1 in your windows form.

          this.Controls.A dd(this.button1 ); // So the form is set to be parent for button1



          So form object is the best container in which you can move your controls without knowing runtime.

          Eg: this.button1.Pa rent=this;

          Regards,
          Balaji U

          Hi
          Ya I have done that. Ihave changed the X and Y co-ordinates according to the mouse movement. That has done. But the problem is on my form there are 3 panels and in the remaning space there is a form on which dynamically the frames or picturecontrol gets displayed. so how i could recognize which control should be the parent?

          Comment

          • Prajaktaj
            New Member
            • Apr 2008
            • 34

            #6
            Originally posted by Prajaktaj
            Hi
            Ya I have done that. Ihave changed the X and Y co-ordinates according to the mouse movement. That has done. But the problem is on my form there are 3 panels and in the remaning space there is a form on which dynamically the frames or picturecontrol gets displayed. so how i could recognize which control should be the parent?

            Hey Hi All

            Thanks alot for your help. I have found the solution. What I have done is that i have set the transparent property of my control
            e.g
            Button1.BackCol or = System.Drawing. Color.Transpare nt

            Thanks

            Comment

            Working...