8 Replies - 1843 Views - Last Post: 27 February 2011 - 12:13 PM Rate Topic: -----

#1 gardiann   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 31-October 09

Table Layout Panel Mistake Please :(

Posted 25 February 2011 - 11:03 AM

Hi everyone , i have a truble with this problem. Firtsly, i created 1 tablelayoutpanel and i inserted 6x6 rows and colums then, i added random button inside the controls location. example random place for table layour is : tablelayoutpanel1.controls.add(button1,1,1); and i created like a random. so , my mistake coming for this reason .when i created button after anorther created sometime re-added into the button and when i click the button dont visible because second button re-added into it, and i must click 2 times some location:S. how can i fix this problem? when created a button if there is a button there , it has to add another location?

This post has been edited by gardiann: 25 February 2011 - 11:05 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Table Layout Panel Mistake Please :(

#2 poncho4all   User is offline

  • D.I.C Head!
  • member icon

Reputation: 123
  • View blog
  • Posts: 1,422
  • Joined: 15-July 09

Re: Table Layout Panel Mistake Please :(

Posted 25 February 2011 - 11:17 AM

You should do a check up if there is a button there or, do it in order
Could you post your code?
Was This Post Helpful? 0
  • +
  • -

#3 gardiann   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 31-October 09

Re: Table Layout Panel Mistake Please :(

Posted 25 February 2011 - 11:27 AM

private void timer1_Tick(object sender, EventArgs e)
        {


            Button btn1 = new Button();
            btn1.Width = 65;
            btn1.Height = 45;
            btn1.Text = "X";

            btn1.Click += new EventHandler(button3_Click);

            //------------------------------------------------------
            Random ram = new Random();

            mycolumn = ram.Next(0, 5);
            myrow = ram.Next(0, 5);
          

            for (int i = 0; i < 5; i++)
            {
                for (int y = 0; y < 5; y++)
                {   
                   
                    if ( "how can i write here for check if there is a location there ," )
                    {
                        tableLayoutPanel1.Controls.Add(btn1, mycolumn, myrow);
                    }
                    else
                    {
                        "if there is a button same place go to else "
                    }

                }
            }
        }


http://img687.images...s/i/adszfcl.png

http://img687.imageshack.us/ i/adszfcl.png/

when i click this button dont visible because random button location insert in to this button and i must click 2 times not 1 :(

This post has been edited by gardiann: 25 February 2011 - 11:29 AM

Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Table Layout Panel Mistake Please :(

Posted 25 February 2011 - 05:53 PM

Every time your timer ticks it creates another button and subscribes to it.
Is that your intention?

You problem is hard to understand because of the language barrier.
Are you saying that sometimes you have more than one button in the same location?
When you make the new button you should add it to a list. That way you can reference it later.
When you make a new button you should loop through the list to see if there is a button with that location already present.
Was This Post Helpful? 0
  • +
  • -

#5 gardiann   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 31-October 09

Re: Table Layout Panel Mistake Please :(

Posted 26 February 2011 - 02:00 AM

View PosttlhIn`toq, on 25 February 2011 - 05:53 PM, said:

Every time your timer ticks it creates another button and subscribes to it.
Is that your intention?

You problem is hard to understand because of the language barrier.
Are you saying that sometimes you have more than one button in the same location?
When you make the new button you should add it to a list. That way you can reference it later.
When you make a new button you should loop through the list to see if there is a button with that location already present.



""Are you saying that sometimes you have more than one button in the same location?"" Yea friend, exactly this question . i created this algorthm but cant write in c# :S
So, i ll try your opinion
Was This Post Helpful? 0
  • +
  • -

#6 gardiann   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 31-October 09

Re: Table Layout Panel Mistake Please :(

Posted 27 February 2011 - 11:22 AM

how to delete if there is button in the same location ??
Was This Post Helpful? 0
  • +
  • -

#7 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Table Layout Panel Mistake Please :(

Posted 27 February 2011 - 11:41 AM

Doesn't clicking on the button cause it to delete itself?

If not you can put a click handler method in your main program, then subscribe the .Click event of each new button you make to that handler. The handler method will know *which* button raised the click event because that is the 'sender' object parameter sent to the method.


void Xbutton_Click(object sender, eventargs e)
{
   // Take the button out of your list
   // Then dispose of it
}

Was This Post Helpful? 0
  • +
  • -

#8 gardiann   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 31-October 09

Re: Table Layout Panel Mistake Please :(

Posted 27 February 2011 - 11:59 AM

View PosttlhIn`toq, on 27 February 2011 - 11:41 AM, said:

Doesn't clicking on the button cause it to delete itself?

If not you can put a click handler method in your main program, then subscribe the .Click event of each new button you make to that handler. The handler method will know *which* button raised the click event because that is the 'sender' object parameter sent to the method.


void Xbutton_Click(object sender, eventargs e)
{
   // Take the button out of your list
   // Then dispose of it
}



 private void timer1_Tick(object sender, EventArgs e)
        { 
            Random ram = new Random();


            Button btn1 = new Button();
            btn1.Width = 65;
            btn1.Height = 45;
            btn1.Text = "X";

            btn1.Click += new EventHandler(button3_Click);

            //------------------------------------------------------
           
            mycolumn = ram.Next(0, 5);
            myrow = ram.Next(0, 5);

            Hesap(mycolumn, myrow, btn1);
             
        }
        public void Hesap(int a, int b, Button btn1)
        {
           
            if (tableLayoutPanel1.Controls.Count < 36)
            {

                if (myarray[a, b] == null)
                {

                    myarray[a, b] = "have";
              
                    tableLayoutPanel1.Controls.Add(btn1, a, B)/>;
                }
                else if (myarray[a, b] == "have")
                {
                    
                 
                    // Control mycont = new Control(tableLayoutPanel1.Controls.ToString());
                    Control c = null;
                 
                    myarray[a, b] = null;
                    tableLayoutPanel1.Controls.Add(btn1, a, B)/>;
                    c = this.tableLayoutPanel1.GetControlFromPosition(a, B)/>;
              
                    tableLayoutPanel1.GetCellPosition(c);
                    if (c != null)
                    {
                        this.tableLayoutPanel1.Controls.Remove(c);
                        c = null;
              

                    }

                }


            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
        
            ((Button)sender).Dispose();
          
        }
    }
}



i do this code but in the tablelayout panel create random button location and add.when i start the game, sometimes it create a button same location .i m bored to click 2 times because of this.
Was This Post Helpful? 0
  • +
  • -

#9 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Table Layout Panel Mistake Please :(

Posted 27 February 2011 - 12:13 PM

View PosttlhIn`toq, on 25 February 2011 - 06:53 PM, said:

When you make the new button you should add it to a list. That way you can reference it later.
When you make a new button you should loop through the list to see if there is a button with that location already present.


Looking at your code I don't see where you have tried the suggestion made.
If you're not going to bother taking the advice of those trying to help I see no reason I should waste my time making more suggestions that you aren't going to try.

I have no idea what your logic behind "hesap()" is. What does "hesap" mean in English? I have no idea what you are trying to accomplish with all the 'getcontrolfromlocation' BS.

  • Make a List<button> to hold all your buttons for future reference.
  • In your timer_tick handler, Make a new location randomonly
  • Loop through your List<button> to see if any of the elements are already at that location. Just check the .Location property of the List<button> element. There is no need to go looping through the Panel controls.
  • If there isn't a button in your List<button> with that location then place it there.

Make the button.
Add the button to a List<button>

Please try to code that and post it back here and I'll try to help you clean it up. But I'm not writing it for you. You at least need to make the effort to code the suggestions made.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1