locked
Arguments for Custom Controls RRS feed

  • Question

  • Hey Guys,

    I've created custom buttons in a .dll and they work fine, so I thought I'd have a go at creating my own sort of listbox to replace the standard one in my applications. It's basically a panel with a few labels and a button (eliminating the need to select an item in standard listbox then click a seperate button). I want to add these panels to a panel on a form, at run-time, based on rows in a db.
    If I try adding any arguments in the New() section of the class file it won't let me use the panel in my toolbox. Is there a way to pass arguments to custom controls, I need a new custom panel for each row in a db so need to pass an id to it to specify records; or even load the records in my application and create a new panel for each record, using info passed to it to fill in the labels on it. Or can I create the panel at run-time and refer to labels within the custom controls, setting their .text properties that way?
    Hope I've been clear enough and thanks in advance for any help :)
    VB.net VS2008

    Shaun

    Thursday, November 24, 2011 5:25 PM

Answers

  • Hi JohnWein,

    I just meant that I couldn't load the control to use it, when adding the .dll it isn't in the toolbox like the buttons are.
    I'm wanting to read a db in my app, then add a new custom panel to the form, passing it details with which it can change the various labels in it to the different details.

    So If I had 2 rows, I would get 2 different panels, in each panel there would be labels showing the data in each field of that row; for example.

    Thanks


    Why would you expect it to be in the toolbox if it expects arguments?  If you want it in the toolbox, it should load without arguments.  If you want to pass arguments in the constructor, you'll have to load it in code that supplies the arguments.
    • Marked as answer by Shaun4 Thursday, November 24, 2011 6:44 PM
    Thursday, November 24, 2011 6:29 PM
  • Sorry, I'm new to creating my own controls. So I can include arguments in the New() part of the class, I just write the code in my app like: Form1.controls.add(new CustomPanel(text1, text2)) etc?

    Thanks

    • Marked as answer by Shaun4 Thursday, November 24, 2011 6:44 PM
    Thursday, November 24, 2011 6:37 PM

All replies

  • If the control appears in the toolbox, how would arguments be passed to it?
    Thursday, November 24, 2011 5:47 PM
  • Hi JohnWein,

    I just meant that I couldn't load the control to use it, when adding the .dll it isn't in the toolbox like the buttons are.
    I'm wanting to read a db in my app, then add a new custom panel to the form, passing it details with which it can change the various labels in it to the different details.

    So If I had 2 rows, I would get 2 different panels, in each panel there would be labels showing the data in each field of that row; for example.

    Thanks

    Thursday, November 24, 2011 6:03 PM
  • Hi JohnWein,

    I just meant that I couldn't load the control to use it, when adding the .dll it isn't in the toolbox like the buttons are.
    I'm wanting to read a db in my app, then add a new custom panel to the form, passing it details with which it can change the various labels in it to the different details.

    So If I had 2 rows, I would get 2 different panels, in each panel there would be labels showing the data in each field of that row; for example.

    Thanks


    Why would you expect it to be in the toolbox if it expects arguments?  If you want it in the toolbox, it should load without arguments.  If you want to pass arguments in the constructor, you'll have to load it in code that supplies the arguments.
    • Marked as answer by Shaun4 Thursday, November 24, 2011 6:44 PM
    Thursday, November 24, 2011 6:29 PM
  • Sorry, I'm new to creating my own controls. So I can include arguments in the New() part of the class, I just write the code in my app like: Form1.controls.add(new CustomPanel(text1, text2)) etc?

    Thanks

    • Marked as answer by Shaun4 Thursday, November 24, 2011 6:44 PM
    Thursday, November 24, 2011 6:37 PM
  • Yep, that works. Sorry for getting confused, I see what you mean now about not needing it in the ToolBox, I thought with it not being there it wasn't added with the .dll or something (again, new to this =p) but it is available for me to type the code and accepts the arguments. Cheers for the help dude :)

     

    Thursday, November 24, 2011 6:44 PM