netmonitor/NetOpenVPNGUI/Form1.cs

119 lines
3.7 KiB
C#
Raw Permalink Normal View History

2011-01-27 11:19:41 +01:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace NetOpenVpnGui
{
public partial class Form1 : Form
{
private Runner sr;
public Form1()
{
InitializeComponent();
sr = new Runner(this.servicename.Text);
this.setIcon();
}
private void EventHandler_Resize(object sender, System.EventArgs e)
{
if (this.WindowState == FormWindowState.Minimized)
{
this.ShowInTaskbar = false;
this.WindowState = FormWindowState.Minimized;
}
}
private void setIcon()
{
if (sr.check_service())
{
this.trayMenu_isRunning(true);
this.trayIcon.Icon = Resources.icon_ok;
this.Icon = Resources.icon_ok;
}
else
{
this.trayMenu_isRunning(false);
this.trayIcon.Icon = Resources.icon_no;
this.Icon = Resources.icon_no;
}
}
private void trayMenu_open_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Normal;
this.ShowInTaskbar = true;
}
private void trayMenu_start_Click(object sender, EventArgs e)
{
if (sr.run_service())
{
this.showPopup("OpenVPN-GUI", "Service succesful started", ToolTipIcon.Info);
this.setIcon();
}
else
{
this.showPopup("OpenVPN-GUI", "Error while starting Service", ToolTipIcon.Error);
this.setIcon();
}
this.trayIcon.ShowBalloonTip(100);
}
private void trayMenu_isRunning(bool p)
{
this.trayMenu_start.Enabled = !p;
this.trayMenu_stop.Enabled = p;
}
private void trayMenu_stop_Click(object sender, EventArgs e)
{
if (sr.stop_service())
{
this.showPopup("OpenVPN-GUI", "Service succesful stopped", ToolTipIcon.Info);
this.setIcon();
}
else
{
this.showPopup("OpenVPN-GUI", "Error while stopping Service", ToolTipIcon.Error);
this.setIcon();
}
this.trayIcon.ShowBalloonTip(100);
}
private void trayMenu_close_Click(object sender, EventArgs e)
{
sr.stop_service();
Application.Exit();
}
private void Application_Closed(object sender, FormClosedEventArgs e)
{
this.trayMenu_close_Click(sender, (EventArgs)e);
}
private void trayIcon_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (this.trayMenu_start.Enabled)
this.trayMenu_start_Click(sender, e);
else if (this.trayMenu_stop.Enabled)
this.trayMenu_stop_Click(sender, e);
}
private void servicename_TextChanged(object sender, EventArgs e)
{
this.sr.service = this.servicename.Text;
this.setIcon();
}
private void showPopup(string title, string text, ToolTipIcon toolTipIcon)
{
this.Statuslog.Items.Add(text);
this.trayIcon.BalloonTipIcon = toolTipIcon;
2011-01-28 21:30:32 +01:00
this.trayIcon.BalloonTipText = sr.service + " " + text;
2011-01-27 11:19:41 +01:00
this.trayIcon.BalloonTipTitle = title;
}
}
}