GUI/PortForm.cs
author moel.mich
Sun, 27 May 2012 20:15:32 +0000
changeset 348 d8fa1e55acfa
child 358 7962499f9cd6
permissions -rw-r--r--
Added the remote web enhancement developed by Prince Samuel.
     1 /*
     2  
     3   This Source Code Form is subject to the terms of the Mozilla Public
     4   License, v. 2.0. If a copy of the MPL was not distributed with this
     5   file, You can obtain one at http://mozilla.org/MPL/2.0/.
     6  
     7 	Copyright (C) 2012 Prince Samuel <prince.samuel@gmail.com>
     8 
     9 */
    10 
    11 using System;
    12 using System.Collections.Generic;
    13 using System.ComponentModel;
    14 using System.Data;
    15 using System.Drawing;
    16 using System.Text;
    17 using System.Windows.Forms;
    18 using System.Net;
    19 using System.Net.Sockets;
    20 using System.Diagnostics;
    21 
    22 namespace OpenHardwareMonitor.GUI {
    23   public partial class PortForm : Form {
    24     private MainForm parent;
    25     private string localIP;
    26     public PortForm(MainForm m) {
    27       InitializeComponent();
    28       parent = m;
    29 
    30       localIP = getLocalIP();
    31     }
    32 
    33     private void portTextBox_TextChanged(object sender, EventArgs e) {
    34 
    35     }
    36 
    37     private string getLocalIP() {
    38       IPHostEntry host;
    39       string localIP = "?";
    40       host = Dns.GetHostEntry(Dns.GetHostName());
    41       foreach (IPAddress ip in host.AddressList) {
    42         if (ip.AddressFamily == AddressFamily.InterNetwork) {
    43           localIP = ip.ToString();
    44         }
    45       }
    46       return localIP;
    47     }
    48 
    49     private void portNumericUpDn_ValueChanged(object sender, EventArgs e) {
    50       string url = "http://" + localIP + ":" + portNumericUpDn.Value + "/";
    51       webServerLinkLabel.Text = url;
    52       webServerLinkLabel.Links.Remove(webServerLinkLabel.Links[0]);
    53       webServerLinkLabel.Links.Add(0, webServerLinkLabel.Text.Length, url);
    54     }
    55 
    56     private void portOKButton_Click(object sender, EventArgs e) {
    57       parent.Server.ListenerPort = (int)portNumericUpDn.Value;
    58       this.Close();
    59     }
    60 
    61     private void portCancelButton_Click(object sender, EventArgs e) {
    62       this.Close();
    63     }
    64 
    65     private void PortForm_Load(object sender, EventArgs e) {
    66       portNumericUpDn.Value = parent.Server.ListenerPort;
    67       portNumericUpDn_ValueChanged(null, null);
    68     }
    69 
    70     private void webServerLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
    71       try {
    72         Process.Start(new ProcessStartInfo(e.Link.LinkData.ToString()));
    73       } catch { }
    74     }
    75 
    76   }
    77 }