Results 1 to 18 of 18

Thread: Quick Question: Object to display a form in a window?

  1. #1

    Thread Starter
    Lively Member Mugsy323's Avatar
    Join Date
    Oct 2014
    Posts
    83

    Question Quick Question: Object to display a form in a window?

    Is there a VB.Net object that let's you easily display a form in a scrollable window? TIA

  2. #2
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    845

    Re: Quick Question: Object to display a form in a window?

    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Quick Question: Object to display a form in a window?

    You want to host a third party form within a form?
    Have a look at the SetParent api...

    Code:
    Declare Auto Function SetParent Lib "user32" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr

  4. #4

    Thread Starter
    Lively Member Mugsy323's Avatar
    Join Date
    Oct 2014
    Posts
    83

    Re: Quick Question: Object to display a form in a window?

    Quote Originally Posted by Delaney View Post
    Hey! That worked! Huge thanks!

    (Now to figure out how to incorporate it into my own program.)

  5. #5

    Thread Starter
    Lively Member Mugsy323's Avatar
    Join Date
    Oct 2014
    Posts
    83

    Re: Quick Question: Object to display a form in a window?

    Quote Originally Posted by .paul. View Post
    You want to host a third party form within a form?
    Thx for the reply. Not 3rd party form. Just a form of my own making.

    It appears the MdiChildForm can do what I need. Thx.

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

    Re: Quick Question: Object to display a form in a window?

    Quote Originally Posted by Mugsy323 View Post
    It appears the MdiChildForm can do what I need.
    To be clear, there's no such thing as an MdiChildForm as a distinct type. They're just forms. If you set the IsMdiContainer property of a form to True then it will automatically host an MdiClient control. That control is the reason the form's background changes colour. If you then assign that form to the MdiParent property of another form, that other form becomes a child control of that MdiClient and is thus hosted within it. The other form is then an MDI child form but to write it as "MdiChildForm" implies that that is the name of a specific type, which it is not. That is, unless you name your own form that, which would be a mistake.

  7. #7

    Thread Starter
    Lively Member Mugsy323's Avatar
    Join Date
    Oct 2014
    Posts
    83

    Re: Quick Question: Object to display a form in a window?

    A quick follow-up for anyone who might come across this in the future:

    The "MdiChild" method didn't give me exactly what I needed b/c it turns the ENTIRE form into a window for another form/forms, whereas I simply needed to display a form in a window within my form.

    I found a way to place everything on a form laid out exactly as I like, then display that form in a window using the "Panel" object:

    Code:
    FormIWantToDisplay.TopLevel = False                   ' Required to prevent an error.
    MyPanelObject.Controls.Add(FormIWantToDisplay)        ' Loads form into Panel.
    FormIWantToDisplay.Show()                             ' Show results.
    Hope this helps someone.

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

    Re: Quick Question: Object to display a form in a window?

    Why are you using a child form in the first place? If you want to display a set of controls as a unit then why not just use a user control. You add a user control to your project the same way you add a form and you then design it and add code the same way too, but then you use it like any other control. If you want to add an instance to a form at run time then you do so, just like you would any other controls. No Panel required and no pointless forms.

  9. #9

    Thread Starter
    Lively Member Mugsy323's Avatar
    Join Date
    Oct 2014
    Posts
    83

    Re: Quick Question: Object to display a form in a window?

    Quote Originally Posted by jmcilhinney View Post
    Why are you using a child form in the first place?
    I needed a way to display a form (icons with labels & checkboxes) in a scrollable window. The method I finally landed upon allows me far more customization than trying to configure any existing control.

    If the method you describe has any advantages over simply displaying a form, please provide a code snippet.
    Last edited by Mugsy323; Oct 5th, 2020 at 07:15 AM.

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

    Re: Quick Question: Object to display a form in a window?

    Quote Originally Posted by Mugsy323 View Post
    I needed a way to display a form (icons with labels & checkboxes) in a scrollable window.
    Did you really, or did you actually just need a way to display icons with Labels and CheckBoxes and you assumed - incorrectly - that that would require a form?
    Quote Originally Posted by Mugsy323 View Post
    If the method you describe has any advantages over simply displaying a form, please provide a code snippet.
    How am I supposed to provide a code snippet of adding an item to your project in the Solution Explorer and then adding controls to it in the designer? Did you actually read my post?
    Quote Originally Posted by Mugsy323 View Post
    The method I finally landed upon allows me far more customization than trying to configure any existing control.
    It would appear that you didn't read it. What I'm suggesting is the proper way to do it. If you want to do things the right way, read what I posted and do what I said. If you don't care, don't do it.

  11. #11

    Thread Starter
    Lively Member Mugsy323's Avatar
    Join Date
    Oct 2014
    Posts
    83

    Re: Quick Question: Object to display a form in a window?

    Quote Originally Posted by jmcilhinney View Post
    Did you really, or did you actually just need a way to display icons with Labels and CheckBoxes and you assumed - incorrectly - that that would require a form?
    Why are we having this discussion? You seem somehow personally offended.

    In an earlier version of my project, I used a ListView. But I found I needed something that offered more customization. Visually creating a form and positioning objects is far superior to trying to create/position objects via code.

    Quote Originally Posted by jmcilhinney View Post
    How am I supposed to provide a code snippet of adding an item to your project in the Solution Explorer and then adding controls to it in the designer? Did you actually read my post?
    Aye! Isn't that the point? You have no idea what my project does and criticizing me for not doing things a particular way.

    Quote Originally Posted by jmcilhinney View Post
    It would appear that you didn't read it. What I'm suggesting is the proper way to do it. If you want to do things the right way, read what I posted and do what I said. If you don't care, don't do it.
    Unless "the proper way" (as you put it) has some substantial advantage over the method I landed upon, you haven't explained why.

  12. #12
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Quick Question: Object to display a form in a window?

    Quote Originally Posted by Mugsy323 View Post
    Visually creating a form and positioning objects is far superior to trying to create/position objects via code.
    You visually design a UserControl too... Project-->Add UserControl

  13. #13
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Quick Question: Object to display a form in a window?

    I think the issue comes down to one of perspective. Ultimately, you NEVER have a window. You have pixels displayed on a monitor. Everything else is just there to make it easier to get the RIGHT pixels in the right places. At any step of the process, you are free to cheat, and it is often a very good idea to cheat. For example, back when there were PDAs (pre-smart phone), there was the CE edition of Visual Studio. This was stripped down in many ways. For example, it had no listbox. So, to create a list, you could add a panel, a series of labels, and a scrollbar. If you did it right (filling the labels based on the value of the scrollbar), this looked and felt like a listbox....because that's what a listbox really is: A series of strings where what is displayed is based on the setting of a scrollbar which may or may not be visible.

    Even those elements aren't real, either, because a scrollbar is a visual way to tell where a person left the mouse in a certain region, and strings are just pixels drawn to the screen following some font and scaled in a certain way. The scrollbar is just there so that you don't have to work out the graphics required, and fonts are there so you don't have to work out the graphics required to display them. You COULD, but that would be tedious.

    So, when you are talking about displaying a form in a scollable window, what do you really want? A form is just a class that has a bit of UI associated with it. You'd REALLY want a form if you want that class to have multiple instances, or want it to be displayed in multiple places (in that window, in other windows, off on its own, etc.). If you don't want to use it in multiple places, then you should consider that you might be better off building your own display that looks the way you want. There are good reasons to do that, as well, though primarily so that you can make it look/act in a very specific way, possibly so that you could use it again (a user control...which rarely do get reused, in my experience), and for the fun of it.

    Still, whichever choice you make, you should keep in mind that it is all about getting pixels on the screen. Don't limit yourself by saying, "these are the complete set of tools at my disposal." You have MANY more tools than the controls and objects in VS, so long as you see it as putting pixels on the screen.
    My usual boring signature: Nothing

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

    Re: Quick Question: Object to display a form in a window?

    Quote Originally Posted by Mugsy323 View Post
    Visually creating a form and positioning objects is far superior to trying to create/position objects via code.
    That might be relevant if I had suggested creating and/or positioning objects via code. What I actually said - what it still seems you didn't read - is this:
    Quote Originally Posted by jmcilhinney View Post
    You add a user control to your project the same way you add a form and you then design it and add code the same way too
    Designing a user control is the same as designing a form so what's the problem?

  15. #15

    Thread Starter
    Lively Member Mugsy323's Avatar
    Join Date
    Oct 2014
    Posts
    83

    Re: Quick Question: Object to display a form in a window?

    Quote Originally Posted by jmcilhinney View Post
    Designing a user control is the same as designing a form so what's the problem?
    The "problem" is the lack of an explanation how using your method over mine is easier, faster, or in any way beneficial.

  16. #16
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Quick Question: Object to display a form in a window?

    Quote Originally Posted by Mugsy323 View Post
    The "problem" is the lack of an explanation how using your method over mine is easier, faster, or in any way beneficial.
    A usercontrol Is a control. You put it on a form. You can create multiple instances of it in your form(s). There’s no need for an MDI form...

  17. #17
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Quick Question: Object to display a form in a window?

    What I would say is that there is a benefit to a user control over an MDI form, which is that MDI forms can be....weird. I can't go into more detail than that because I use them infrequently, but they can have some strange and unexpected behavior, though mostly around showing other forms from them.

    Beyond that, I feel that there isn't all that much real advantage of one over the other. A user controls should, in theory, be FAR more re-usable than an MDI form, but in practice, neither one is likely to be reused. After all, the whole concept behind classes is that you could build one and then use it wherever you need that particular functionality. Of course, if it isn't highly specialized to your needs, then there is likely an off the shelf option, which means that both forms and user controls tend to be highly focused on a particular problem...which means that the number of places that they could, even theoretically, be reused is fairly small.

    I do think that a user control might have a lighter impact on form creation, but I'm not sure that is true, and even if it is, you won't notice it in almost any scenario.
    My usual boring signature: Nothing

  18. #18

    Thread Starter
    Lively Member Mugsy323's Avatar
    Join Date
    Oct 2014
    Posts
    83

    Re: Quick Question: Object to display a form in a window?

    Quote Originally Posted by .paul. View Post
    There’s no need for an MDI form...
    Then I guess it's a good thing I didn't use one then, huh?

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