FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

passing data to an event

 
Post new topic   Reply to topic     Forum Index -> DFL
View previous topic :: View next topic  
Author Message
jicman



Joined: 22 Dec 2004
Posts: 298
Location: Rochester, NY

PostPosted: Mon Jul 23, 2007 4:56 pm    Post subject: passing data to an event Reply with quote

I have these functions,
Code:
  private void CreateProjectAndChildren()
  {
    PClassStr =
      [
        " ",
        " Project",
        "Quote",
        "Language",
        "Technical",
        "TimeKeeper"
      ];
    PSubClassStr =
      [
        " ",
        " Project",
        "PM",
        "SW-Trans",
        "DOC-Trans",
        "DTP",
        "Validation",
        "Proofing",
        "In-Context",
        "XTranslate",
        "QA",
        "Pre-Proc",
        "Post-Proc",
        "Analysis",
        "VoiceOver",
        "Interpretation",
        "Support",
        "TimeTrack"
      ];

    with(EmailForm = new Form)
    {
      text = "Choose SubProject Category";
      GroupBox myGroup;
      RadioButton[char[]] SubProjRadio;
      TextBox myTextBox;
      Button Done;

      width = 270;
      startPosition = FormStartPosition.CENTER_SCREEN;
      formBorderStyle = FormBorderStyle.FIXED_DIALOG; // Don't allow resize.
      maximizeBox = false;
     
      // Add a GroupBox.
      with(myGroup = new GroupBox)
      {
        bounds = Rect(4, 4, EmailForm.clientSize.width - 8, 120); // Set the x, y, width, and height.
        text = "Choose one of these SubProject options..."; // Text displayed at the top of the box.
        parent = EmailForm; // Set myGroup's parent to this Form.
      }
     
      // Add some RadioButton`s to the GroupBox myGroup..
      int pcY = 18;
      char[] lastpc;
      foreach (char[] pc; PClassStr)
      {
        if (pc == " " || pc == " Project")
          continue;
        else
        {
          with(SubProjRadio[pc] = new RadioButton)
          {
            bounds = Rect(6, pcY, 160, 13); // x, y, width and height within the GroupBox.
            text = pc; // Text displayed next to the selector thing.
            checked = false; //
            parent = myGroup; // Set parent to the GroupBox.
          }
          pcY += 18;
          lastpc = pc;
        }
      }
     
      // Update myGroup's height to fit all the RadioButtons.
      // The client size is the area inside the control, excluding the border.
      myGroup.clientSize = Size(myGroup.clientSize.width, SubProjRadio[lastpc].bottom + 6);
     
      // Add a button and a click event handler.
      with(Done = new Button)
      {
        location = Point(EmailForm.clientSize.width - Done.width - 4, myGroup.bottom + 4); // width/height are default.
        text = "&Done";
        parent = EmailForm;
        click ~= &Done_click;
      }
 
      // Update the Form's height to fit all the controls.
      // The client size is the area inside the Form, excluding the border and caption.
      clientSize = Size(clientSize.width, Done.bottom + 6);
      show();
    }
  }
   
  // Click handler for voteBtn.
  private void Done_click(Object sender, EventArgs ea)
  {
    char[] s;
    char[][] comments;
    RadioButton voteOption;
         
    // See which option they voted for.
    foreach (char[] pc; PClassStr)
    {
      if (myGroup.SubProjRadio[pc].checked)
      {
        msgBox(pc);
        break;
      }
    }
    error.text = "Must choose one of the options...";
  }


which works fine until I click the Done button. I need to know what option the user chose, but I can not seem to find a way to do this. I guess I could use buttons and create a click function for each button, but there is gotta be an easier way. How can I pass "myGroup.SubProjRadio" array to the Done_click event? I have spent a few hours on this and I can not seem to find a way. Of course, I am new to this Windows Programming Idea, but it should not be that hard!

thanks,

jose
Back to top
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Tue Jul 24, 2007 9:10 am    Post subject: Re: passing data to an event Reply with quote

Your event handler delegate (Done_click) should be in a context where you can access what you need. It might be wise to move your form creation stuff outside a function. Or a quick way would be to derive from Button for your Done button and have it hold references to what you need.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DFL All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group