Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How can i get i ShowDialog method in UserControl???

How can i get i ShowDialog method in UserControl???

Scheduled Pinned Locked Moved C#
questioncsharpwinforms
10 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lupa_8421
    wrote on last edited by
    #1

    I want to extend then .net framewok's usercontrol,to make it has a showdialog like windows forms. How Can i get it??? Thanks a lot!!

    U 1 Reply Last reply
    0
    • L lupa_8421

      I want to extend then .net framewok's usercontrol,to make it has a showdialog like windows forms. How Can i get it??? Thanks a lot!!

      U Offline
      U Offline
      User 260964
      wrote on last edited by
      #2

      Just like you would do it when not working on an UserControl:

      MainForm frm = new MainForm();
      frm.ShowDialog(this);

      L 1 Reply Last reply
      0
      • U User 260964

        Just like you would do it when not working on an UserControl:

        MainForm frm = new MainForm();
        frm.ShowDialog(this);

        L Offline
        L Offline
        lupa_8421
        wrote on last edited by
        #3

        Hi! I think you maybe mistake what i said! I mean the UserControl has the ShowDialog() method acts as the showdialog() method of the window forms. For example,there is a userControl instance: "usercontrol1",When I click a button,I call The usercontrol1's method usercontrol1.Showdialog(),and the usercontrol1 will be showed just like we show a Form instance with then showdialog() method.

        N H U 3 Replies Last reply
        0
        • L lupa_8421

          Hi! I think you maybe mistake what i said! I mean the UserControl has the ShowDialog() method acts as the showdialog() method of the window forms. For example,there is a userControl instance: "usercontrol1",When I click a button,I call The usercontrol1's method usercontrol1.Showdialog(),and the usercontrol1 will be showed just like we show a Form instance with then showdialog() method.

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          Even I'm confused(not unusal). You want usercontrol1 to call showdialog on itself :confused: What's the point?

          1 Reply Last reply
          0
          • L lupa_8421

            Hi! I think you maybe mistake what i said! I mean the UserControl has the ShowDialog() method acts as the showdialog() method of the window forms. For example,there is a userControl instance: "usercontrol1",When I click a button,I call The usercontrol1's method usercontrol1.Showdialog(),and the usercontrol1 will be showed just like we show a Form instance with then showdialog() method.

            H Offline
            H Offline
            Heath Stewart
            wrote on last edited by
            #5

            A control can't show itself as a dialog. This comes down to Windows styles and messages, since the System.Windows.Forms controls are just wrappers for native controls (Common Controls). You could add a ShowDialog method that adds the control to a borderless form and shows the form, but you can't show the control itself. It just isn't possible - it needs a Windows frame to host it. So you could do something like this:

            public void ShowDialog()
            {
            Form f = new Form();
            f.FormBorderStyle = FormBorderStyle.None;
            f.Size = this.Size;
            f.Controls.Add(this);
            f.ShowInTaskbar = false;
            f.ShowDialog();
            // Set properties or something.
            f.Dispose(); // Always dispose modal dialogs when you're done with them
            }

            -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

            L 1 Reply Last reply
            0
            • L lupa_8421

              Hi! I think you maybe mistake what i said! I mean the UserControl has the ShowDialog() method acts as the showdialog() method of the window forms. For example,there is a userControl instance: "usercontrol1",When I click a button,I call The usercontrol1's method usercontrol1.Showdialog(),and the usercontrol1 will be showed just like we show a Form instance with then showdialog() method.

              U Offline
              U Offline
              User 260964
              wrote on last edited by
              #6

              If you just want to show or hide a UserControl, than you can use one of the following:

              • Call Show[^] to show the control, and Hide[^] to hide it again.
              • Set Visible[^] to true to show the control, and to false to hide it again.

              If you want to do something else, then please clarify it. - Daniƫl Pelsmaeker


              This is Linux country. On a quiet night, you can hear NT re-boot.

              1 Reply Last reply
              0
              • H Heath Stewart

                A control can't show itself as a dialog. This comes down to Windows styles and messages, since the System.Windows.Forms controls are just wrappers for native controls (Common Controls). You could add a ShowDialog method that adds the control to a borderless form and shows the form, but you can't show the control itself. It just isn't possible - it needs a Windows frame to host it. So you could do something like this:

                public void ShowDialog()
                {
                Form f = new Form();
                f.FormBorderStyle = FormBorderStyle.None;
                f.Size = this.Size;
                f.Controls.Add(this);
                f.ShowInTaskbar = false;
                f.ShowDialog();
                // Set properties or something.
                f.Dispose(); // Always dispose modal dialogs when you're done with them
                }

                -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

                L Offline
                L Offline
                leppie
                wrote on last edited by
                #7

                Hi Heath I have been trying this method to get access to the UITypeEditors, but I keep on gettting SEHExceptions, any ideas? Cheers :) leppie::AllocCPArticle("Zee blog");
                Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.

                H 1 Reply Last reply
                0
                • L leppie

                  Hi Heath I have been trying this method to get access to the UITypeEditors, but I keep on gettting SEHExceptions, any ideas? Cheers :) leppie::AllocCPArticle("Zee blog");
                  Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.

                  H Offline
                  H Offline
                  Heath Stewart
                  wrote on last edited by
                  #8

                  Not really. The description, "Represents Structured Exception Handler (SEH) errors.", doesn't even help much. I take it you're talking about the UITypeEditors like the ColorEditor (or whatever that nifty one is) that are internal to the .NET BCL? Or just to host your own in a control?

                  -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

                  L 2 Replies Last reply
                  0
                  • H Heath Stewart

                    Not really. The description, "Represents Structured Exception Handler (SEH) errors.", doesn't even help much. I take it you're talking about the UITypeEditors like the ColorEditor (or whatever that nifty one is) that are internal to the .NET BCL? Or just to host your own in a control?

                    -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

                    L Offline
                    L Offline
                    leppie
                    wrote on last edited by
                    #9

                    Heath Stewart wrote: I take it you're talking about the UITypeEditors like the ColorEditor (or whatever that nifty one is) that are internal to the .NET BCL? Or just to host your own in a control? Well both, so I can use an existing infrastructure. And reuse my custom editors in the propertygrid again. Have a look at the nightmare of the propertygrid thru a disassembler. Things just dont make sense anymore. Like the "dropdownui" is a control hosted in a form hosted in a control. I mean crazy, and funny unsafe calls... maybe they made it intentionally like that! :mad: Also things like: TypeConvertor.EditValue() returns immediately, so u to somehow block it, without having access to the code, i say man, its a nitemare (R18) X| leppie::AllocCPArticle("Zee blog");
                    Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.

                    1 Reply Last reply
                    0
                    • H Heath Stewart

                      Not really. The description, "Represents Structured Exception Handler (SEH) errors.", doesn't even help much. I take it you're talking about the UITypeEditors like the ColorEditor (or whatever that nifty one is) that are internal to the .NET BCL? Or just to host your own in a control?

                      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

                      L Offline
                      L Offline
                      leppie
                      wrote on last edited by
                      #10

                      The problem has been solved. Application.EnableVisualStyles() causes that error: http://groups.google.com/groups?num=20&hl=en&lr=lang_en&ie=UTF-8&oe=UTF-8&q=SEHException[^] :) leppie::AllocCPArticle("Zee blog");
                      Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups