Results 1 to 4 of 4

Thread: [RESOLVED] How would I access a button on another form?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2014
    Posts
    80

    Resolved [RESOLVED] How would I access a button on another form?

    I have a class 'WeaponSelection' which needs to check if the radio button on my menuselection form is checked.

    example:

    Weapon Class:

    Code:
    if (rdbRyu.checked == true)
    {
    do this..
    }
    the rdbRyu radio button is located in the menuselection form

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,348

    Re: How would I access a button on another form?

    To be frank, it would be wrong for that class to do that. It's possible but it's not good practice.

    Presumably the form is creating this object in the first place so the form should be passing the Boolean value to the object rather than the object retrieving it from the form. If you can provide more information about the relationship between the form and the object then we can provide more information on what might be the best way to move the data.

    If you really want the object to retrieve the data then it is possible. In order for the object to use the RadioButton, it must have a reference to that RadioButton. That is almost certainly going to come from the form that contains it. The form is going to have to pass the object a reference to the RadioButton or a reference to itself that the object can then use to access the RadioButton. That second option also requires that the RadioButton be exposed publicly, which makes things even worse. If the form is going to passing a reference anyway, why not just pass the Boolean in the first place?

  3. #3
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,660

    Re: How would I access a button on another form?

    Yeh as JMC said i would avoid doing it.

    Get the value of your radiobutton (true/false) and pass it in to your class probably via a property.
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  4. #4

    Thread Starter
    Lively Member
    Join Date
    Apr 2014
    Posts
    80

    Re: How would I access a button on another form?

    Ok thanks a lot.

Posting Permissions

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



Click Here to Expand Forum to Full Width