dcsimg
Results 1 to 3 of 3

Thread: [RESOLVED] how to auto change the location of a label wheen button is click

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    69

    Resolved [RESOLVED] how to auto change the location of a label wheen button is click

    hi Sir,

    I want to auto change the location of my label every time i click PLAY AGAIN button.
    how can i code that ?

    as of now my code below set another new point when button is click, but after that it will not change anymore.
    I want every time i click the playagain button it will change. i have about 20 labels in my form. sample below i show only 3.

    Code:
        private void btnPlayAgain_Click(object sender, EventArgs e)
            {    
                lblI_Me.Location = new Point(380, 198);
                lblWe.Location = new Point(839, 498);
                lblYou.Location = new Point(187, 387);
            }
    thanks in advance.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    99,788

    Re: how to auto change the location of a label wheen button is click

    Are you saying that you want to use a different value each time you click the Button? If so then you obviously need to provide a different value each time. How you do that is up to you. We don't know what you want so we can't tell you.

    If you want the Labels to move to random locations then maybe you should tell us that. In that case, as is always the case when you want to do something random, you will use an instance of the Random class. You then need to decide what the rules are for generating the values, e.g. the X value should not be such that the Label will disappear off the right edge of the form.

    Put some thought into the rules - write them down if you need to - and then look at writing code to implement those rules specifically. This is what you should always be doing, i.e. getting a clear idea of what the code needs to do first - that means the steps it has to perform, not just the end result - and then implement that algorithm rather than just trying to pull a big wad of code out of thin air.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2018
    Posts
    69

    Re: how to auto change the location of a label wheen button is click

    thanks for the advise Sir JM.

    i got it using code below:

    Code:
       void xLocation()
            {
                Random rX = new Random();
              lblI_Me.Location=new Point(rX.Next(0,1000),rX.Next(0,600));
              lblWe.Location = new Point(rX.Next(0, 1000), rX.Next(0, 600));
              lblYou.Location = new Point(rX.Next(0, 1000), rX.Next(0, 600));
    
            }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width