Windows Forms: Open SettingsWindow (popup)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mikkel Trebbien
    New Member
    • Sep 2010
    • 4

    Windows Forms: Open SettingsWindow (popup)

    I'm trying to play a little bit with Windows Forms, to make a little application.

    But here's how I'd like it to be:

    I've made a little link named "SettingsLi nk" (file is named SettingsWindow. cs" (Type: LabelLink).
    The text on the link is "Settings".

    How can I make the window popup?
    I've tried several things, but nothing has helped so far.

    Current code from the link:

    Code:
                // SettingsLink
                // 
                this.SettingsLink.AutoSize = true;
                this.SettingsLink.Location = new System.Drawing.Point(1066, 85);
                this.SettingsLink.Name = "SettingsLink";
                this.SettingsLink.Size = new System.Drawing.Size(45, 13);
                this.SettingsLink.TabIndex = 2;
                this.SettingsLink.TabStop = true;
                this.SettingsLink.Text = "Settings";
  • Airslash
    New Member
    • Nov 2007
    • 221

    #2
    Assign the onClick event handler for your label. In the event, create & show the settings window.

    When the user closes the window, you update the mainform with the settings applied in the SettingsWindows .

    I think the easiest way of doing this, is by showing the SettingsWindow as a Modal form on your main windows when clicking the link and then extracting the data you need from the settings form.

    From the top of my head:

    Code:
    // Add this
    this.SettingsLink.OnClick += new EventHandler<EventArgs>(new_func_name);
    
    // create the event function
    void new_func_name(object sender, EventArgs e)
    {
          SettingsForm form = new SettingsForm();
          if(SettingsForm.ShowModel() == ModalResponse.OK)
          {
                 // DO stuff with settings
          }
    }
    This is sort of the code you're looking for. I think it should be fairly easy to find sufficient examples about using forms as Modal Forms.

    Comment

    • Mikkel Trebbien
      New Member
      • Sep 2010
      • 4

      #3
      Well.
      Just by watching the code You posted (I'm PHP developer), then it doesn't seem to be what I've been looking for, but I'll give it a try later (I'm in school right now).

      But as said, all I want it to do, is to pop up the window, like if You selected "Tools" > "Settings" in either Internet Explorer or Firefox.

      In that window, I'll make some content etc.

      Comment

      • Airslash
        New Member
        • Nov 2007
        • 221

        #4
        Ah you should have told that from the start.
        So if I understand your question correctly, you have a small application, created in Windows Forms, and you wish to open a browser to a specific URL that will show you a page with settings?

        If that's the case, you require still the onClick event for the linkLabel, but instead of that form code, you need to inform windows to open the default browser and redirect it to the specific URL you wish to display.

        I'm not 100% sure if this is actually safe to perform, or if there is a better way of doing this, but if you pass the URL directly into the WindowsShell, it should open the default browser to that address:

        Code:
        // Assign the eventhandler for the onClick event.
        this.SettingsLink.OnClick += new EventHandler<EventArgs>(link_onClick);
        
        // This is the function that will be raised
        void link_onClick(object sender, EventArgs e)
        {
            // Open the default browser and point to your URL      System.Diagnostics.Process.Start("http://www.google.com");
        }
        I think this should do the trick, but I don't guarantee it to be safe or working 100%.

        Comment

        • Mikkel Trebbien
          New Member
          • Sep 2010
          • 4

          #5
          It wasn't what I've been looking for (but it was helpful anyways!).
          I also needed a way to link to my website, and this helped me.

          Look.
          This is how I want it to be.
          Let's take WLM/MSN Messenger as example.
          What I need is something like "Tools" > "Options... "

          I want to create such window.
          Last edited by Niheel; Jan 12 '12, 11:41 PM. Reason: Changed URL, image no longer exists

          Comment

          • Airslash
            New Member
            • Nov 2007
            • 221

            #6
            then you require what I wrote in my first post normally. A second form in your application that represents the configuration form, which gets called by the onClick event of the linklabel you have on the mainform.

            When you show the configuration form as a ModalForm (google it), you prevent the user from performing actions on the mainform untill he has closed the configuration form, just like MSN messenger does.

            By using delegates (callback functions) you can trigger actions in the mainform by doing stuff on the configuration form.

            Comment

            • Mikkel Trebbien
              New Member
              • Sep 2010
              • 4

              #7
              The first post You wrote, just came up with tons of red lines (functions not defined)...

              I will take a look at it later, the project has been postponed atm.

              Comment

              • Airslash
                New Member
                • Nov 2007
                • 221

                #8
                You'll need to find the correct declarations ofcourse. The code posted was mearly a guideline to get you on the right track and the terms you'll need to look up.

                Comment

                Working...