본문 바로가기
Programing/C#

c# 여러개의 오브젝트와의 충돌검사

by 고니피즈 2017. 2. 15.
반응형

         int _y = 300;

        public void check ()  // 여러개 오브젝트 충돌검사

        {

            int rx = radioButton1.Left;

            int ry = radioButton1.Top;

            radioButton1.Top = _y;

            _y -= 1;


            for (int i = 0; i < this.Controls.Count; i++) //콘트롤의 갯수만큼 for

            {

                if (this.Controls[i] is Button) // 버튼이면 

                {

                    if (this.Controls[i].Bounds.Contains(rx,ry)) { //충돌되었다면

                        radioButton1.Text = this.Controls[i].Text;

                    }

                }

            }


        }


        private void timer1_Tick(object sender, EventArgs e)

        {

            check();

        }


반응형