status knap i C# .NET
Jeg er i gang med at lave en GUI der indeholder en listbox, som er en liste over bestemte servere og deres ip-adresse. I denne listboks ønsker jeg også at have en slags knap der lyser rød hvis serveren er offline og grøn hvis den er online. Jeg havde bare tænkt mig at indsætte radiobuttons men da de jo kommer med text kan jeg ikke bruge dem da jeg skal kun bruge den lille knap.Så er der nogen der har en ide hvad jeg kan bruge i stedet for.
Her er koden for den foreløbige form:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
namespace Database_Replication_Service
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox serverBox;
private System.Windows.Forms.ListBox serverList;
private System.Windows.Forms.Label dnsLabel;
private System.Windows.Forms.TextBox dnsText;
private System.Windows.Forms.Label ipLabel;
private System.Windows.Forms.Label ipLabelText;
private System.Windows.Forms.Button checkButton;
private System.Windows.Forms.Button addButton;
private System.Windows.Forms.Button removeButton;
private System.Windows.Forms.Button refreshButton;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.StatusBar statusBar1;
public System.Windows.Forms.MainMenu mainMenu1;
public System.Windows.Forms.MenuItem File;
private System.Windows.Forms.MenuItem Click;
public System.Windows.Forms.MenuItem Help;
private System.Windows.Forms.MenuItem Overview;
private System.Windows.Forms.MenuItem Hypermedia;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
Thread th = new Thread(new ThreadStart(DoSplash));
//th.ApartmentState = ApartmentState.STA;
//th.IsBackground=true;
th.Start();
Thread.Sleep(2000);
th.Abort();
Thread.Sleep(1000);
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void DoSplash()
{
splash sp = new splash();
sp.ShowDialog();
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.serverBox = new System.Windows.Forms.GroupBox();
this.serverList = new System.Windows.Forms.ListBox();
this.dnsLabel = new System.Windows.Forms.Label();
this.dnsText = new System.Windows.Forms.TextBox();
this.ipLabel = new System.Windows.Forms.Label();
this.ipLabelText = new System.Windows.Forms.Label();
this.checkButton = new System.Windows.Forms.Button();
this.addButton = new System.Windows.Forms.Button();
this.removeButton = new System.Windows.Forms.Button();
this.refreshButton = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.statusBar1 = new System.Windows.Forms.StatusBar();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.File = new System.Windows.Forms.MenuItem();
this.Click = new System.Windows.Forms.MenuItem();
this.Help = new System.Windows.Forms.MenuItem();
this.Overview = new System.Windows.Forms.MenuItem();
this.Hypermedia = new System.Windows.Forms.MenuItem();
this.serverBox.SuspendLayout();
this.SuspendLayout();
//
// serverBox
//
this.serverBox.Controls.Add(this.serverList);
this.serverBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.serverBox.Location = new System.Drawing.Point(16, 48);
this.serverBox.Name = "serverBox";
this.serverBox.Size = new System.Drawing.Size(408, 344);
this.serverBox.TabIndex = 0;
this.serverBox.TabStop = false;
this.serverBox.Text = "DNS Name";
//
// serverList
//
this.serverList.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.serverList.HorizontalScrollbar = true;
this.serverList.ItemHeight = 16;
this.serverList.Items.AddRange(new object[] {
"Ribe Filial\t\t192.168.1.1",
"Ribe Filial\t\t192.168.1.1",
"Ribe Filial\t\t192.168.1.1",
"Ribe Filial\t\t192.168.1.1",
"Ribe Filial\t\t192.168.1.1",
"Ribe Filial\t\t192.168.1.1",
"Ribe Filial\t\t192.168.1.1",
"Ribe Filial\t\t192.168.1.1",
"Ribe Filial\t\t192.168.1.1",
"Ribe Filial\t\t192.168.1.1",
"Ribe Filial\t\t192.168.1.1",
"Ribe Filial\t\t192.168.1.1"});
this.serverList.Location = new System.Drawing.Point(8, 40);
this.serverList.Name = "serverList";
this.serverList.ScrollAlwaysVisible = true;
this.serverList.Size = new System.Drawing.Size(376, 244);
this.serverList.TabIndex = 0;
this.serverList.SelectedIndexChanged += new System.EventHandler(this.serverList_SelectedIndexChanged);
//
// dnsLabel
//
this.dnsLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.dnsLabel.Location = new System.Drawing.Point(448, 64);
this.dnsLabel.Name = "dnsLabel";
this.dnsLabel.TabIndex = 1;
this.dnsLabel.Text = "&DNS Name";
this.dnsLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// dnsText
//
this.dnsText.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.dnsText.Location = new System.Drawing.Point(568, 64);
this.dnsText.Name = "dnsText";
this.dnsText.Size = new System.Drawing.Size(152, 20);
this.dnsText.TabIndex = 2;
this.dnsText.Text = "";
//
// ipLabel
//
this.ipLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.ipLabel.Location = new System.Drawing.Point(456, 104);
this.ipLabel.Name = "ipLabel";
this.ipLabel.TabIndex = 3;
this.ipLabel.Text = "&IP - Address";
this.ipLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// ipLabelText
//
this.ipLabelText.BackColor = System.Drawing.SystemColors.Window;
this.ipLabelText.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.ipLabelText.Location = new System.Drawing.Point(568, 104);
this.ipLabelText.Name = "ipLabelText";
this.ipLabelText.Size = new System.Drawing.Size(152, 20);
this.ipLabelText.TabIndex = 5;
//
// checkButton
//
this.checkButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.checkButton.Location = new System.Drawing.Point(456, 160);
this.checkButton.Name = "checkButton";
this.checkButton.Size = new System.Drawing.Size(104, 32);
this.checkButton.TabIndex = 6;
this.checkButton.Text = "&Check Name";
//
// addButton
//
this.addButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.addButton.Location = new System.Drawing.Point(16, 408);
this.addButton.Name = "addButton";
this.addButton.Size = new System.Drawing.Size(104, 32);
this.addButton.TabIndex = 7;
this.addButton.Text = "&Add";
this.addButton.Click += new System.EventHandler(this.addButton_Click);
//
// removeButton
//
this.removeButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.removeButton.Location = new System.Drawing.Point(144, 408);
this.removeButton.Name = "removeButton";
this.removeButton.Size = new System.Drawing.Size(104, 32);
this.removeButton.TabIndex = 8;
this.removeButton.Text = "&Remove";
this.removeButton.Click += new System.EventHandler(this.removeButton_Click);
//
// refreshButton
//
this.refreshButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.refreshButton.Location = new System.Drawing.Point(272, 408);
this.refreshButton.Name = "refreshButton";
this.refreshButton.Size = new System.Drawing.Size(104, 32);
this.refreshButton.TabIndex = 9;
this.refreshButton.Text = "&Refresh";
this.refreshButton.Click += new System.EventHandler(this.refreshButton_Click);
//
// pictureBox1
//
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(480, 264);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(264, 248);
this.pictureBox1.TabIndex = 10;
this.pictureBox1.TabStop = false;
//
// statusBar1
//
this.statusBar1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.statusBar1.Location = new System.Drawing.Point(0, 515);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Size = new System.Drawing.Size(784, 22);
this.statusBar1.TabIndex = 11;
this.statusBar1.Text = "Klar.....";
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.File,
this.Help});
//
// File
//
this.File.Index = 0;
this.File.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.Click});
this.File.Text = "File";
//
// Click
//
this.Click.Index = 0;
this.Click.Text = "Click";
//
// Help
//
this.Help.Index = 1;
this.Help.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.Overview,
this.Hypermedia});
this.Help.Text = "Help";
//
// Overview
//
this.Overview.Index = 0;
this.Overview.Text = "Overview";
//
// Hypermedia
//
this.Hypermedia.Index = 1;
this.Hypermedia.Text = "Hypermedia";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.SystemColors.Control;
this.ClientSize = new System.Drawing.Size(784, 537);
this.Controls.Add(this.statusBar1);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.refreshButton);
this.Controls.Add(this.removeButton);
this.Controls.Add(this.addButton);
this.Controls.Add(this.checkButton);
this.Controls.Add(this.ipLabelText);
this.Controls.Add(this.ipLabel);
this.Controls.Add(this.dnsText);
this.Controls.Add(this.dnsLabel);
this.Controls.Add(this.serverBox);
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Database Replication Service";
this.TopMost = true;
this.Load += new System.EventHandler(this.Form1_Load);
this.serverBox.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void serverList_SelectedIndexChanged(object sender, System.EventArgs e)
{
int intIndex = 0;
serverList.SelectedIndex = intIndex;
/*
serverList.Items.Insert(0,"Ribe Filial 192.168.1.1");
serverList.Items.Add("Ribe Filial 192.168.1.1");
serverList.Items.Add("Ribe Filial 192.168.1.1");
*/
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
private void addButton_Click(object sender, System.EventArgs e)
{
MessageBox.Show("The server is now added to the list");
}
private void removeButton_Click(object sender, System.EventArgs e)
{
MessageBox.Show("The server is now removed from the list");
}
private void refreshButton_Click(object sender, System.EventArgs e)
{
MessageBox.Show("The server list has been updated");
}
private void File_Popup(object sender, System.EventArgs e)
{
}
}
}
