GUI/PortForm.cs
author StephaneLenclud
Thu, 18 Apr 2013 23:25:10 +0200
branchMiniDisplay
changeset 444 9b09e2ee0968
parent 348 d8fa1e55acfa
permissions -rw-r--r--
Front View plug-in does not init if no sensor added.
Fixing some format to make strings shorter.
Now trying to start SoundGraphAccess.exe process from same directory.
Packed mode now can display three sensors along with the current time.
moel@348
     1
/*
moel@348
     2
 
moel@348
     3
  This Source Code Form is subject to the terms of the Mozilla Public
moel@348
     4
  License, v. 2.0. If a copy of the MPL was not distributed with this
moel@348
     5
  file, You can obtain one at http://mozilla.org/MPL/2.0/.
moel@348
     6
 
moel@348
     7
	Copyright (C) 2012 Prince Samuel <prince.samuel@gmail.com>
moel@348
     8
moel@348
     9
*/
moel@348
    10
moel@348
    11
using System;
moel@348
    12
using System.Collections.Generic;
moel@348
    13
using System.ComponentModel;
moel@348
    14
using System.Drawing;
moel@348
    15
using System.Text;
moel@348
    16
using System.Windows.Forms;
moel@348
    17
using System.Net;
moel@348
    18
using System.Net.Sockets;
moel@348
    19
using System.Diagnostics;
moel@348
    20
moel@348
    21
namespace OpenHardwareMonitor.GUI {
moel@348
    22
  public partial class PortForm : Form {
moel@348
    23
    private MainForm parent;
moel@348
    24
    private string localIP;
moel@348
    25
    public PortForm(MainForm m) {
moel@348
    26
      InitializeComponent();
moel@348
    27
      parent = m;
moel@348
    28
moel@348
    29
      localIP = getLocalIP();
moel@348
    30
    }
moel@348
    31
moel@348
    32
    private void portTextBox_TextChanged(object sender, EventArgs e) {
moel@348
    33
moel@348
    34
    }
moel@348
    35
moel@348
    36
    private string getLocalIP() {
moel@348
    37
      IPHostEntry host;
moel@348
    38
      string localIP = "?";
moel@348
    39
      host = Dns.GetHostEntry(Dns.GetHostName());
moel@348
    40
      foreach (IPAddress ip in host.AddressList) {
moel@348
    41
        if (ip.AddressFamily == AddressFamily.InterNetwork) {
moel@348
    42
          localIP = ip.ToString();
moel@348
    43
        }
moel@348
    44
      }
moel@348
    45
      return localIP;
moel@348
    46
    }
moel@348
    47
moel@348
    48
    private void portNumericUpDn_ValueChanged(object sender, EventArgs e) {
moel@348
    49
      string url = "http://" + localIP + ":" + portNumericUpDn.Value + "/";
moel@348
    50
      webServerLinkLabel.Text = url;
moel@348
    51
      webServerLinkLabel.Links.Remove(webServerLinkLabel.Links[0]);
moel@348
    52
      webServerLinkLabel.Links.Add(0, webServerLinkLabel.Text.Length, url);
moel@348
    53
    }
moel@348
    54
moel@348
    55
    private void portOKButton_Click(object sender, EventArgs e) {
moel@348
    56
      parent.Server.ListenerPort = (int)portNumericUpDn.Value;
moel@348
    57
      this.Close();
moel@348
    58
    }
moel@348
    59
moel@348
    60
    private void portCancelButton_Click(object sender, EventArgs e) {
moel@348
    61
      this.Close();
moel@348
    62
    }
moel@348
    63
moel@348
    64
    private void PortForm_Load(object sender, EventArgs e) {
moel@348
    65
      portNumericUpDn.Value = parent.Server.ListenerPort;
moel@348
    66
      portNumericUpDn_ValueChanged(null, null);
moel@348
    67
    }
moel@348
    68
moel@348
    69
    private void webServerLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
moel@348
    70
      try {
moel@348
    71
        Process.Start(new ProcessStartInfo(e.Link.LinkData.ToString()));
moel@348
    72
      } catch { }
moel@348
    73
    }
moel@348
    74
moel@348
    75
  }
moel@348
    76
}