I want to make a custom button in an UserControl... Like with a hover animation. But in the usercontrol it won't let me execute the events?!
EDIT: I tried taking it out of the user control but that doesn't change anything...
My code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Title_Bar : UserControl
{
public Title_Bar()
{
InitializeComponent();
}
private void cross_idle_MouseEnter(object sender, EventArgs e)
{
cross_hover.Show();
}
private void cross_hover_MouseLeave(object sender, EventArgs e)
{
cross_hover.Hide();
}
private void max_idle_MouseEnter(object sender, EventArgs e)
{
max_hover.Show();
}
private void max_hover_MouseLeave(object sender, EventArgs e)
{
max_hover.Hide();
}
private void min_idle_MouseEnter(object sender, EventArgs e)
{
min_hover.Show();
}
private void min_hover_MouseLeave(object sender, EventArgs e)
{
min_hover.Hide();
}
private void cross_hover_Click(object sender, EventArgs e)
{
this.ParentForm.Close();
}
}
}
Designer Code:
namespace WindowsFormsApplication1
{
partial class Title_Bar
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component 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.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Title_Bar));
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.pictureBox3 = new System.Windows.Forms.PictureBox();
this.cross_idle = new System.Windows.Forms.PictureBox();
this.max_idle = new System.Windows.Forms.PictureBox();
this.max_hover = new System.Windows.Forms.PictureBox();
this.min_idle = new System.Windows.Forms.PictureBox();
this.min_hover = new System.Windows.Forms.PictureBox();
this.cross_hover = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.cross_idle)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.max_idle)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.max_hover)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.min_idle)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.min_hover)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.cross_hover)).BeginInit();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(49, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(272, 10);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// pictureBox2
//
this.pictureBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.pictureBox2.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox2.Image")));
this.pictureBox2.Location = new System.Drawing.Point(318, 0);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(50, 10);
this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox2.TabIndex = 1;
this.pictureBox2.TabStop = false;
//
// pictureBox3
//
this.pictureBox3.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox3.Image")));
this.pictureBox3.Location = new System.Drawing.Point(0, 0);
this.pictureBox3.Name = "pictureBox3";
this.pictureBox3.Size = new System.Drawing.Size(50, 10);
this.pictureBox3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox3.TabIndex = 2;
this.pictureBox3.TabStop = false;
//
// cross_idle
//
this.cross_idle.Image = ((System.Drawing.Image)(resources.GetObject("cross_idle.Image")));
this.cross_idle.Location = new System.Drawing.Point(358, 0);
this.cross_idle.Name = "cross_idle";
this.cross_idle.Size = new System.Drawing.Size(10, 10);
this.cross_idle.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.cross_idle.TabIndex = 3;
this.cross_idle.TabStop = false;
this.cross_idle.MouseEnter += new System.EventHandler(this.cross_idle_MouseEnter);
//
// max_idle
//
this.max_idle.Image = ((System.Drawing.Image)(resources.GetObject("max_idle.Image")));
this.max_idle.Location = new System.Drawing.Point(349, 0);
this.max_idle.Name = "max_idle";
this.max_idle.Size = new System.Drawing.Size(10, 10);
this.max_idle.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.max_idle.TabIndex = 4;
this.max_idle.TabStop = false;
this.max_idle.MouseEnter += new System.EventHandler(this.max_idle_MouseEnter);
//
// max_hover
//
this.max_hover.Image = ((System.Drawing.Image)(resources.GetObject("max_hover.Image")));
this.max_hover.Location = new System.Drawing.Point(267, 0);
this.max_hover.Name = "max_hover";
this.max_hover.Size = new System.Drawing.Size(10, 10);
this.max_hover.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.max_hover.TabIndex = 5;
this.max_hover.TabStop = false;
this.max_hover.Visible = false;
this.max_hover.MouseLeave += new System.EventHandler(this.max_hover_MouseLeave);
//
// min_idle
//
this.min_idle.Image = ((System.Drawing.Image)(resources.GetObject("min_idle.Image")));
this.min_idle.Location = new System.Drawing.Point(340, 0);
this.min_idle.Name = "min_idle";
this.min_idle.Size = new System.Drawing.Size(10, 10);
this.min_idle.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.min_idle.TabIndex = 6;
this.min_idle.TabStop = false;
this.min_idle.MouseEnter += new System.EventHandler(this.min_idle_MouseEnter);
//
// min_hover
//
this.min_hover.Image = ((System.Drawing.Image)(resources.GetObject("min_hover.Image")));
this.min_hover.Location = new System.Drawing.Point(237, 0);
this.min_hover.Name = "min_hover";
this.min_hover.Size = new System.Drawing.Size(10, 10);
this.min_hover.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.min_hover.TabIndex = 7;
this.min_hover.TabStop = false;
this.min_hover.Visible = false;
this.min_hover.MouseLeave += new System.EventHandler(this.min_hover_MouseLeave);
//
// cross_hover
//
this.cross_hover.Image = ((System.Drawing.Image)(resources.GetObject("cross_hover.Image")));
this.cross_hover.Location = new System.Drawing.Point(302, 0);
this.cross_hover.Name = "cross_hover";
this.cross_hover.Size = new System.Drawing.Size(10, 10);
this.cross_hover.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.cross_hover.TabIndex = 8;
this.cross_hover.TabStop = false;
this.cross_hover.Visible = false;
this.cross_hover.Click += new System.EventHandler(this.cross_hover_Click);
this.cross_hover.MouseLeave += new System.EventHandler(this.cross_hover_MouseLeave);
//
// Title_Bar
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.cross_hover);
this.Controls.Add(this.min_hover);
this.Controls.Add(this.min_idle);
this.Controls.Add(this.max_hover);
this.Controls.Add(this.max_idle);
this.Controls.Add(this.cross_idle);
this.Controls.Add(this.pictureBox3);
this.Controls.Add(this.pictureBox2);
this.Controls.Add(this.pictureBox1);
this.Name = "Title_Bar";
this.Size = new System.Drawing.Size(368, 10);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.cross_idle)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.max_idle)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.max_hover)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.min_idle)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.min_hover)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.cross_hover)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.PictureBox pictureBox2;
private System.Windows.Forms.PictureBox pictureBox3;
private System.Windows.Forms.PictureBox cross_idle;
private System.Windows.Forms.PictureBox max_idle;
private System.Windows.Forms.PictureBox max_hover;
private System.Windows.Forms.PictureBox min_idle;
private System.Windows.Forms.PictureBox min_hover;
private System.Windows.Forms.PictureBox cross_hover;
}
}
I have put in all the picture boxes, but nothing happens!
this.cross_hover.Visible is set to false in the designer file, and calling Show is not going to change that value. Hence, the PictureBox is never shown.
Instead of calling Show(), set Visible to true:
private void cross_idle_MouseEnter(object sender, EventArgs e)
{
this.cross_hover.Visible = true;
}
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 13 days ago.
Improve this question
I know I'm butchering the transaction class. I just have no idea what to do. Nothing gets displayed when I run the form and hit add new transaction. I appreciate any help here's my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AccountBalance
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnNewTran_Click(object sender, EventArgs e)
{
string strTransactionType = "";
if (rbDeposit.Checked)
{
strTransactionType = rbDeposit.Text;
}
else
{
strTransactionType = rbWithdrawal.Text;
}
Transaction newTransaction = new Transaction();
newTransaction.Amount = decimal.Parse(txtTAmount.Text);
newTransaction.Type = strTransactionType;
newTransaction.Date = txtTDate.Text;
lstTransactions.Items.Add(newTransaction);
decimal decBalance = decimal.Parse(lblCBalance.Text);
if (newTransaction.Type == "Deposit")
{
decBalance += newTransaction.Amount;
lblCBalance.Text = decBalance.ToString("c");
}
else
{
decBalance -= newTransaction.Amount;
lblCBalance.Text = decBalance.ToString("c");
}
if (decBalance < 0)
{
lblCBalance.ForeColor = Color.Red;
}
rbDeposit.Checked = false;
rbWithdrawal.Checked = false;
txtTAmount.Clear();
txtTDate.Clear();
txtTAmount.Focus();
}
private void btnRemTran_Click(object sender, EventArgs e)
{
int intSelectedIndex = lstTransactions.SelectedIndex;
Transaction selectedTransaction = (Transaction)lstTransactions.SelectedItem;
lstTransactions.Items.RemoveAt(intSelectedIndex);
decimal decBalance = decimal.Parse(lblCBalance.Text);
if (selectedTransaction.Type == "Deposit")
{
decBalance -= selectedTransaction.Amount;
lblCBalance.Text = decBalance.ToString("c");
}
else
{
decBalance += selectedTransaction.Amount;
lblCBalance.Text = decBalance.ToString("c");
}
if (decBalance >= 0)
{
lblCBalance.ForeColor = Color.Black;
}
}
private void btnClear_Click(object sender, EventArgs e)
{
rbDeposit.Checked = false;
rbWithdrawal.Checked = false;
txtTAmount.Clear();
txtTDate.Clear();
txtTAmount.Focus();
}
private void lstTransactions_Click(object sender, EventArgs e)
{
Transaction selectedTransaction = (Transaction)lstTransactions.SelectedItem;
if (selectedTransaction.Type == "Deposit")
{
rbDeposit.Checked = true;
}
else
{
rbWithdrawal.Checked = true;
}
txtTAmount.Text = selectedTransaction.Amount.ToString("c");
txtTDate.Text = selectedTransaction.Date;
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
public class Transaction
{
internal decimal Amount;
internal string Type;
internal string Date;
}
}
namespace AccountBalance
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#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()
{
this.lblTDate = new System.Windows.Forms.Label();
this.txtTDate = new System.Windows.Forms.TextBox();
this.lblTAmount = new System.Windows.Forms.Label();
this.txtTAmount = new System.Windows.Forms.TextBox();
this.lblTType = new System.Windows.Forms.Label();
this.rbDeposit = new System.Windows.Forms.RadioButton();
this.rbWithdrawal = new System.Windows.Forms.RadioButton();
this.rbServFee = new System.Windows.Forms.RadioButton();
this.lblPayee = new System.Windows.Forms.Label();
this.txtPayee = new System.Windows.Forms.TextBox();
this.lblCheckNum = new System.Windows.Forms.Label();
this.txtCheckNum = new System.Windows.Forms.TextBox();
this.lblCBalance = new System.Windows.Forms.Label();
this.txtCBalance = new System.Windows.Forms.TextBox();
this.lstTransactions = new System.Windows.Forms.ListBox();
this.btnNewTran = new System.Windows.Forms.Button();
this.btnRemTran = new System.Windows.Forms.Button();
this.btnClear = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// lblTDate
//
this.lblTDate.AutoSize = true;
this.lblTDate.Location = new System.Drawing.Point(12, 9);
this.lblTDate.Name = "lblTDate";
this.lblTDate.Size = new System.Drawing.Size(104, 13);
this.lblTDate.TabIndex = 0;
this.lblTDate.Text = "Date of Transaction:";
//
// txtTDate
//
this.txtTDate.Location = new System.Drawing.Point(15, 25);
this.txtTDate.Name = "txtTDate";
this.txtTDate.Size = new System.Drawing.Size(100, 20);
this.txtTDate.TabIndex = 1;
//
// lblTAmount
//
this.lblTAmount.AutoSize = true;
this.lblTAmount.Location = new System.Drawing.Point(263, 9);
this.lblTAmount.Name = "lblTAmount";
this.lblTAmount.Size = new System.Drawing.Size(105, 13);
this.lblTAmount.TabIndex = 0;
this.lblTAmount.Text = "Transaction Amount:";
//
// txtTAmount
//
this.txtTAmount.Location = new System.Drawing.Point(266, 25);
this.txtTAmount.Name = "txtTAmount";
this.txtTAmount.Size = new System.Drawing.Size(100, 20);
this.txtTAmount.TabIndex = 2;
//
// lblTType
//
this.lblTType.AutoSize = true;
this.lblTType.Location = new System.Drawing.Point(473, 9);
this.lblTType.Name = "lblTType";
this.lblTType.Size = new System.Drawing.Size(93, 13);
this.lblTType.TabIndex = 0;
this.lblTType.Text = "Transaction Type:";
//
// rbDeposit
//
this.rbDeposit.AutoSize = true;
this.rbDeposit.Location = new System.Drawing.Point(481, 28);
this.rbDeposit.Name = "rbDeposit";
this.rbDeposit.Size = new System.Drawing.Size(61, 17);
this.rbDeposit.TabIndex = 3;
this.rbDeposit.TabStop = true;
this.rbDeposit.Text = "Deposit";
this.rbDeposit.UseVisualStyleBackColor = true;
//
// rbWithdrawal
//
this.rbWithdrawal.AutoSize = true;
this.rbWithdrawal.Location = new System.Drawing.Point(481, 51);
this.rbWithdrawal.Name = "rbWithdrawal";
this.rbWithdrawal.Size = new System.Drawing.Size(78, 17);
this.rbWithdrawal.TabIndex = 4;
this.rbWithdrawal.TabStop = true;
this.rbWithdrawal.Text = "Withdrawal";
this.rbWithdrawal.UseVisualStyleBackColor = true;
//
// rbServFee
//
this.rbServFee.AutoSize = true;
this.rbServFee.Location = new System.Drawing.Point(481, 74);
this.rbServFee.Name = "rbServFee";
this.rbServFee.Size = new System.Drawing.Size(82, 17);
this.rbServFee.TabIndex = 5;
this.rbServFee.TabStop = true;
this.rbServFee.Text = "Service Fee";
this.rbServFee.UseVisualStyleBackColor = true;
//
// lblPayee
//
this.lblPayee.AutoSize = true;
this.lblPayee.Location = new System.Drawing.Point(12, 53);
this.lblPayee.Name = "lblPayee";
this.lblPayee.Size = new System.Drawing.Size(40, 13);
this.lblPayee.TabIndex = 0;
this.lblPayee.Text = "Payee:";
//
// txtPayee
//
this.txtPayee.Location = new System.Drawing.Point(15, 71);
this.txtPayee.Name = "txtPayee";
this.txtPayee.Size = new System.Drawing.Size(230, 20);
this.txtPayee.TabIndex = 6;
//
// lblCheckNum
//
this.lblCheckNum.AutoSize = true;
this.lblCheckNum.Location = new System.Drawing.Point(263, 53);
this.lblCheckNum.Name = "lblCheckNum";
this.lblCheckNum.Size = new System.Drawing.Size(81, 13);
this.lblCheckNum.TabIndex = 0;
this.lblCheckNum.Text = "Check Number:";
//
// txtCheckNum
//
this.txtCheckNum.Location = new System.Drawing.Point(266, 71);
this.txtCheckNum.Name = "txtCheckNum";
this.txtCheckNum.Size = new System.Drawing.Size(100, 20);
this.txtCheckNum.TabIndex = 7;
//
// lblCBalance
//
this.lblCBalance.AutoSize = true;
this.lblCBalance.Location = new System.Drawing.Point(12, 109);
this.lblCBalance.Name = "lblCBalance";
this.lblCBalance.Size = new System.Drawing.Size(86, 13);
this.lblCBalance.TabIndex = 0;
this.lblCBalance.Text = "Current Balance:";
//
// txtCBalance
//
this.txtCBalance.Location = new System.Drawing.Point(145, 102);
this.txtCBalance.Name = "txtCBalance";
this.txtCBalance.ReadOnly = true;
this.txtCBalance.Size = new System.Drawing.Size(100, 20);
this.txtCBalance.TabIndex = 0;
//
// lstTransactions
//
this.lstTransactions.FormattingEnabled = true;
this.lstTransactions.Location = new System.Drawing.Point(15, 125);
this.lstTransactions.Name = "lstTransactions";
this.lstTransactions.Size = new System.Drawing.Size(439, 316);
this.lstTransactions.TabIndex = 0;
//
// btnNewTran
//
this.btnNewTran.Location = new System.Drawing.Point(460, 171);
this.btnNewTran.Name = "btnNewTran";
this.btnNewTran.Size = new System.Drawing.Size(99, 23);
this.btnNewTran.TabIndex = 8;
this.btnNewTran.Text = "New Transaction";
this.btnNewTran.UseVisualStyleBackColor = true;
//
// btnRemTran
//
this.btnRemTran.Location = new System.Drawing.Point(460, 252);
this.btnRemTran.Name = "btnRemTran";
this.btnRemTran.Size = new System.Drawing.Size(99, 23);
this.btnRemTran.TabIndex = 9;
this.btnRemTran.Text = "Remove";
this.btnRemTran.UseVisualStyleBackColor = true;
//
// btnClear
//
this.btnClear.Location = new System.Drawing.Point(460, 333);
this.btnClear.Name = "btnClear";
this.btnClear.Size = new System.Drawing.Size(99, 23);
this.btnClear.TabIndex = 10;
this.btnClear.Text = "Clear";
this.btnClear.UseVisualStyleBackColor = true;
//
// btnExit
//
this.btnExit.Location = new System.Drawing.Point(460, 414);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(99, 23);
this.btnExit.TabIndex = 11;
this.btnExit.Text = "Exit";
this.btnExit.UseVisualStyleBackColor = true;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(578, 450);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnClear);
this.Controls.Add(this.btnRemTran);
this.Controls.Add(this.btnNewTran);
this.Controls.Add(this.lstTransactions);
this.Controls.Add(this.txtCBalance);
this.Controls.Add(this.lblCBalance);
this.Controls.Add(this.txtCheckNum);
this.Controls.Add(this.lblCheckNum);
this.Controls.Add(this.txtPayee);
this.Controls.Add(this.lblPayee);
this.Controls.Add(this.rbServFee);
this.Controls.Add(this.rbWithdrawal);
this.Controls.Add(this.rbDeposit);
this.Controls.Add(this.lblTType);
this.Controls.Add(this.txtTAmount);
this.Controls.Add(this.lblTAmount);
this.Controls.Add(this.txtTDate);
this.Controls.Add(this.lblTDate);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label lblTDate;
private System.Windows.Forms.TextBox txtTDate;
private System.Windows.Forms.Label lblTAmount;
private System.Windows.Forms.TextBox txtTAmount;
private System.Windows.Forms.Label lblTType;
private System.Windows.Forms.RadioButton rbDeposit;
private System.Windows.Forms.RadioButton rbWithdrawal;
private System.Windows.Forms.RadioButton rbServFee;
private System.Windows.Forms.Label lblPayee;
private System.Windows.Forms.TextBox txtPayee;
private System.Windows.Forms.Label lblCheckNum;
private System.Windows.Forms.TextBox txtCheckNum;
private System.Windows.Forms.Label lblCBalance;
private System.Windows.Forms.TextBox txtCBalance;
private System.Windows.Forms.ListBox lstTransactions;
private System.Windows.Forms.Button btnNewTran;
private System.Windows.Forms.Button btnRemTran;
private System.Windows.Forms.Button btnClear;
private System.Windows.Forms.Button btnExit;
}
}
I pretty much tried to use quick fixes and watched some random videos and came up with nothing.
Don't add your items to the ListBox directly. Create an appropriate list and bind that to the ListBox, then add your items to that list. If you use a BindingList<Transaction> then adding an item to the list will automatically update the bound control, which will not happen with a List<Transaction>.
var transactions = new BindingList<Transaction>();
myListBox.DataSource = transactions;
By default, when you add an item to a ListBox, ToString is called on that object and the result displayed. If you don't override the ToString method, that will just be the name of the type. You can set the DisplayMember of the ListBox and the specified property value will be displayed, e.g.
var transactions = new BindingList<Transaction>();
myListBox.DisplayMember = nameof(Transaction.Amount);
myListBox.DataSource = transactions;
Note that only properties can be specified as the DisplayMember or ValueMember. Fields will not work.
If you want some custom text displayed then you need to override the ToString method and have it return the desired text.
I have some code that starts a new thread every time a button is clicked. Each new thread draws a randomly colored circle in a random location in a primitive graphics engine and is added to a Listview. The link to this engine is https://github.com/NAIT-CNT/GDIDrawer.
I need to find a way to remove and abort a thread based on whatever Listview item the user clicks.
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using GDIDrawer;
using System.Threading;
namespace ica7
{
public partial class Form1 : Form
{
CDrawer _gdi = new CDrawer();
List<Thread> _threads = new List<Thread>();
Random _rng = new Random();
Point _coords;
int _diameter;
bool _isRunning;
public Form1()
{
InitializeComponent();
_diameter = 10;
_isRunning = true;
btnStopThreads.Enabled = false;
}
private Color RandomColor()
{
return Color.FromArgb(_rng.Next(256), _rng.Next(256), _rng.Next(256));
}
private void DrawCircle(int diameter, Point coords, CDrawer gdi)
{
gdi.AddCenteredEllipse(coords, diameter, diameter, RandomColor());
}
private void btnStartThread_Click(object sender, EventArgs e)
{
btnStopThreads.Enabled = true;
Thread t = new Thread(() =>
{
int diameter = _diameter;
while (_isRunning)
{
_coords.X = _rng.Next(800);
_coords.Y = _rng.Next(600);
DrawCircle(diameter, _coords, _gdi);
Thread.Sleep(10);
}
});
_threads.Add(t);
ListViewItem lvi = new ListViewItem(t.ToString());
lboxThreads.Items.Add(lvi);
t.Start();
}
private void btnStopThreads_Click(object sender, EventArgs e)
{
_threads.ElementAt(lboxThreads.SelectedIndex).Abort();
lboxThreads.Items.RemoveAt(lboxThreads.SelectedIndex);
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
_diameter = trackBar1.Value;
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
_threads.ForEach(x => x.Abort());
}
}
}
Here is the designer file, in case it's needed:
namespace ica7
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#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()
{
this.components = new System.ComponentModel.Container();
this.btnStartThread = new System.Windows.Forms.Button();
this.btnStopThreads = new System.Windows.Forms.Button();
this.lboxThreads = new System.Windows.Forms.ListBox();
this.trackBar1 = new System.Windows.Forms.TrackBar();
this.lblTbMin = new System.Windows.Forms.Label();
this.lblTbMax = new System.Windows.Forms.Label();
this.timer1 = new System.Windows.Forms.Timer(this.components);
((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();
this.SuspendLayout();
//
// btnStartThread
//
this.btnStartThread.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
this.btnStartThread.Location = new System.Drawing.Point(9, 11);
this.btnStartThread.Name = "btnStartThread";
this.btnStartThread.Size = new System.Drawing.Size(121, 23);
this.btnStartThread.TabIndex = 0;
this.btnStartThread.Text = "Start a Thread";
this.btnStartThread.UseVisualStyleBackColor = true;
this.btnStartThread.Click += new System.EventHandler(this.btnStartThread_Click);
//
// btnStopThreads
//
this.btnStopThreads.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
this.btnStopThreads.Location = new System.Drawing.Point(9, 40);
this.btnStopThreads.Name = "btnStopThreads";
this.btnStopThreads.Size = new System.Drawing.Size(121, 23);
this.btnStopThreads.TabIndex = 1;
this.btnStopThreads.Text = "Stop Selected Thread";
this.btnStopThreads.UseVisualStyleBackColor = true;
this.btnStopThreads.Click += new System.EventHandler(this.btnStopThreads_Click);
//
// lboxThreads
//
this.lboxThreads.FormattingEnabled = true;
this.lboxThreads.Location = new System.Drawing.Point(138, 11);
this.lboxThreads.Name = "lboxThreads";
this.lboxThreads.Size = new System.Drawing.Size(303, 134);
this.lboxThreads.TabIndex = 2;
//
// trackBar1
//
this.trackBar1.Location = new System.Drawing.Point(9, 69);
this.trackBar1.Maximum = 50;
this.trackBar1.Minimum = 10;
this.trackBar1.Name = "trackBar1";
this.trackBar1.Size = new System.Drawing.Size(121, 45);
this.trackBar1.TabIndex = 3;
this.trackBar1.Value = 10;
this.trackBar1.Scroll += new System.EventHandler(this.trackBar1_Scroll);
//
// lblTbMin
//
this.lblTbMin.AutoSize = true;
this.lblTbMin.Location = new System.Drawing.Point(6, 101);
this.lblTbMin.Name = "lblTbMin";
this.lblTbMin.Size = new System.Drawing.Size(19, 13);
this.lblTbMin.TabIndex = 4;
this.lblTbMin.Text = "10";
//
// lblTbMax
//
this.lblTbMax.AutoSize = true;
this.lblTbMax.Location = new System.Drawing.Point(111, 101);
this.lblTbMax.Name = "lblTbMax";
this.lblTbMax.Size = new System.Drawing.Size(19, 13);
this.lblTbMax.TabIndex = 5;
this.lblTbMax.Text = "50";
//
// timer1
//
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.ClientSize = new System.Drawing.Size(453, 157);
this.Controls.Add(this.lblTbMax);
this.Controls.Add(this.lblTbMin);
this.Controls.Add(this.trackBar1);
this.Controls.Add(this.lboxThreads);
this.Controls.Add(this.btnStopThreads);
this.Controls.Add(this.btnStartThread);
this.ForeColor = System.Drawing.SystemColors.ActiveCaption;
this.Name = "Form1";
this.Text = "Form1";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Form1_FormClosed);
((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button btnStartThread;
private System.Windows.Forms.Button btnStopThreads;
private System.Windows.Forms.ListBox lboxThreads;
private System.Windows.Forms.TrackBar trackBar1;
private System.Windows.Forms.Label lblTbMin;
private System.Windows.Forms.Label lblTbMax;
private System.Windows.Forms.Timer timer1;
}
}
If there are superior ways of doing any of this, please let me know. This is my first foray into threads. This is homework.
I'm using Nlog in my project, and now there's a problem, here it is:
I want to write logs into a RichTextBox, everything is OK at first, but when I clear the lines in RTB, and then restart to write logs, it goes wrong, it will not show any line in the RTB.
But, if I use
log.Error("Error\n"); // there is a "\n" in the end
instead of
log.Error("Error");
it will be OK, I don't know why is that...
any clue of this? thanks very much for any suggestion.
BTW I'm using Win7 X64, VS 2013, C# WinForm, .NET 4.0, NLog 3.2.0
using System;
using System.Windows.Forms;
using NLog;
using NLog.Targets;
namespace RTBLogDemo
{
public partial class LogForm : Form
{
#region Designer
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#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()
{
this.components = new System.ComponentModel.Container();
this.logRichTextBox = new System.Windows.Forms.RichTextBox();
this.btnStart = new System.Windows.Forms.Button();
this.btnStop = new System.Windows.Forms.Button();
this.btnClear = new System.Windows.Forms.Button();
this.logTimer = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// logRichTextBox
//
this.logRichTextBox.Dock = System.Windows.Forms.DockStyle.Bottom;
this.logRichTextBox.Location = new System.Drawing.Point(0, 173);
this.logRichTextBox.Name = "logRichTextBox";
this.logRichTextBox.Size = new System.Drawing.Size(656, 299);
this.logRichTextBox.TabIndex = 0;
this.logRichTextBox.Text = "";
//
// btnStart
//
this.btnStart.Location = new System.Drawing.Point(100, 48);
this.btnStart.Name = "btnStart";
this.btnStart.Size = new System.Drawing.Size(75, 39);
this.btnStart.TabIndex = 1;
this.btnStart.Text = "start";
this.btnStart.UseVisualStyleBackColor = true;
this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
//
// btnStop
//
this.btnStop.Location = new System.Drawing.Point(261, 48);
this.btnStop.Name = "btnStop";
this.btnStop.Size = new System.Drawing.Size(75, 39);
this.btnStop.TabIndex = 2;
this.btnStop.Text = "stop";
this.btnStop.UseVisualStyleBackColor = true;
this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
//
// btnClear
//
this.btnClear.Location = new System.Drawing.Point(417, 48);
this.btnClear.Name = "btnClear";
this.btnClear.Size = new System.Drawing.Size(75, 39);
this.btnClear.TabIndex = 3;
this.btnClear.Text = "Clear";
this.btnClear.UseVisualStyleBackColor = true;
this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
//
// logTimer
//
this.logTimer.Tick += new System.EventHandler(this.logTimer_Tick);
//
// LogForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(656, 472);
this.Controls.Add(this.btnClear);
this.Controls.Add(this.btnStop);
this.Controls.Add(this.btnStart);
this.Controls.Add(this.logRichTextBox);
this.Name = "LogForm";
this.Text = "Log Form";
this.Load += new System.EventHandler(this.LogForm_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.RichTextBox logRichTextBox;
private System.Windows.Forms.Button btnStart;
private System.Windows.Forms.Button btnStop;
private System.Windows.Forms.Button btnClear;
private System.Windows.Forms.Timer logTimer;
#endregion
public LogForm()
{
InitializeComponent();
}
private Logger log;
private void logTimer_Tick(object sender, EventArgs e)
{
log.Error("Error"); // WRONG
// log.Error("Error\n"); // OK
}
private void btnStart_Click(object sender, EventArgs e)
{
logTimer.Start();
}
private void btnStop_Click(object sender, EventArgs e)
{
logTimer.Stop();
}
private void btnClear_Click(object sender, EventArgs e)
{
logRichTextBox.Clear();
}
private void InitLogger()
{
RichTextBoxTarget target = new RichTextBoxTarget();
target.Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}";
target.ControlName = logRichTextBox.Name;
target.FormName = this.Name;
target.UseDefaultRowColoringRules = true;
target.AutoScroll = true;
target.MaxLines = 50;
NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Trace);
log = LogManager.GetCurrentClassLogger();
}
private void LogForm_Load(object sender, EventArgs e)
{
InitLogger();
}
}
}
Ok I have been at this for awhile. I have a program that monitors one file "lab.txt" for changes, and when it changes, I want it to reload the contents of the file into a listbox that is displayed. I can get it to display and tell me when there is a change, but I cant get the listbox to refresh. any help would be apprieciated. There is alot of code not being used now because I have been trying different methods so please disregard.
namespace FileChangeNotifier
{
public partial class frmNotifier : Form
{
private StringBuilder m_Sb;
private bool m_bDirty;
private System.IO.FileSystemWatcher m_Watcher;
private bool m_bIsWatching;
public static string txtPath = "E:/lab.txt";
List<string> list;
BindingList<string> bindingList;
public frmNotifier()
{
InitializeComponent();
m_Sb = new StringBuilder();
m_bDirty = false;
m_bIsWatching = false;
//BindingSource bindingSource = (BindingSource)listBox1.DataSource;
// List SourceList = (List)bindingSource.List;
list= new List<string>(File.ReadLines(txtPath));
bindingList = new BindingList<string>(list);
listBox1.DataSource = bindingList;
//listBox1.SelectedIndex = -1;
m_bIsWatching = true;
btnWatchFile.BackColor = Color.Red;
m_Watcher = new System.IO.FileSystemWatcher();
m_Watcher.Filter = "lab.txt";
m_Watcher.Path = "E:\\";
m_Watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
m_Watcher.Changed += new FileSystemEventHandler(OnChanged);
m_Watcher.Created += new FileSystemEventHandler(OnChanged);
m_Watcher.Deleted += new FileSystemEventHandler(OnChanged);
m_Watcher.Renamed += new RenamedEventHandler(OnRenamed);
m_Watcher.EnableRaisingEvents = true;
}
private void btnWatchFile_Click(object sender, EventArgs e)
{
if (m_bIsWatching)
{
m_bIsWatching = false;
m_Watcher.EnableRaisingEvents = false;
m_Watcher.Dispose();
btnWatchFile.BackColor = Color.LightSkyBlue;
btnWatchFile.Text = "Start Watching";
}
else
{
m_bIsWatching = true;
btnWatchFile.BackColor = Color.Red;
btnWatchFile.Text = "Stop Watching";
m_Watcher = new System.IO.FileSystemWatcher();
//if (rdbDir.Checked)
//
m_Watcher.Filter = "lab.txt";
m_Watcher.Path = "E:\\";
//
/*lse
{
m_Watcher.Filter = txtFile.Text.Substring(txtFile.Text.LastIndexOf('\\') + 1);
m_Watcher.Path = txtFile.Text.Substring(0, txtFile.Text.Length - m_Watcher.Filter.Length);
}
if (chkSubFolder.Checked)
{
m_Watcher.IncludeSubdirectories = true;
}*/
m_Watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
m_Watcher.Changed += new FileSystemEventHandler(OnChanged);
m_Watcher.Created += new FileSystemEventHandler(OnChanged);
m_Watcher.Deleted += new FileSystemEventHandler(OnChanged);
m_Watcher.Renamed += new RenamedEventHandler(OnRenamed);
m_Watcher.EnableRaisingEvents = true;
}
}
private void OnChanged(object sender, FileSystemEventArgs e)
{
if (!m_bDirty)
{
m_Sb.Remove(0, m_Sb.Length);
m_Sb.Append(e.FullPath);
m_Sb.Append(" ");
m_Sb.Append(e.ChangeType.ToString());
m_Sb.Append(" ");
m_Sb.Append(DateTime.Now.ToString());
m_bDirty = true;
}
}
private void OnRenamed(object sender, RenamedEventArgs e)
{
if (!m_bDirty)
{
m_Sb.Remove(0, m_Sb.Length);
m_Sb.Append(e.OldFullPath);
m_Sb.Append(" ");
m_Sb.Append(e.ChangeType.ToString());
m_Sb.Append(" ");
m_Sb.Append("to ");
m_Sb.Append(e.Name);
m_Sb.Append(" ");
m_Sb.Append(DateTime.Now.ToString());
m_bDirty = true;
}
}
private void tmrEditNotify_Tick(object sender, EventArgs e)
{
if (m_bDirty)
{
lstNotification.BeginUpdate();
lstNotification.Items.Add(m_Sb.ToString());
lstNotification.EndUpdate();
m_bDirty = false;
}
}
private void btnBrowseFile_Click(object sender, EventArgs e)
{
}
private void btnLog_Click(object sender, EventArgs e)
{
DialogResult resDialog = dlgSaveFile.ShowDialog();
if (resDialog.ToString() == "OK")
{
FileInfo fi = new FileInfo(dlgSaveFile.FileName);
StreamWriter sw = fi.CreateText();
foreach (string sItem in lstNotification.Items)
{
sw.WriteLine(sItem);
}
sw.Close();
}
}
public void bindData()
{
listBox1.DataSource = null;
bindingList=null;
list = new List<string>(File.ReadLines(txtPath));
bindingList = new BindingList<string>(list);
listBox1.DataSource = bindingList;
}
private void Execute(object sender, EventArgs e)
{
string task = TaskQue.Pop();
//execute task;
listBox1.DataSource = TaskQue.GetTasks();
}
private void AddTask(object sender, EventArgs e)
{
TaskQue.Push(listBox1.Text);
listBox1.DataSource = TaskQue.GetTasks();
}
private void txtFile_TextChanged(object sender, EventArgs e)
{
}
private void lstNotification_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
public class TaskQue
{
public static string txtPath = "E:/lab.txt";
public static string Pop()
{
StreamReader sr = new StreamReader(txtPath);
string result = sr.ReadLine();
string remaining = sr.ReadToEnd();
sr.Close();
StreamWriter sw = new StreamWriter(txtPath, false);
sw.Write(remaining);
sw.Close();
return result;
}
public static void Push(string s)
{
StreamWriter sw = new StreamWriter(txtPath, true);
sw.WriteLine(s);
sw.Close();
}
public static IEnumerable<string> GetTasks()
{
return new List<string>(File.ReadLines(txtPath));
}
}
}
EDIT:
This is what I have changed and still no go
private void OnChanged(object sender, FileSystemEventArgs e)
{
if (!m_bDirty)
{
m_Sb.Remove(0, m_Sb.Length);
m_Sb.Append(e.FullPath);
m_Sb.Append(" ");
m_Sb.Append(e.ChangeType.ToString());
m_Sb.Append(" ");
m_Sb.Append(DateTime.Now.ToString());
m_bDirty = true;
list = new List<string>(File.ReadAllLines(txtPath));
bindingList = new BindingList<string>(list);
listBox1.DataSource = bindingList;
}
}
This is my Form.Designer.cs file
namespace FileChangeNotifier
{
partial class frmNotifier
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#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()
{
this.components = new System.ComponentModel.Container();
this.btnWatchFile = new System.Windows.Forms.Button();
this.lstNotification = new System.Windows.Forms.ListBox();
this.label3 = new System.Windows.Forms.Label();
this.tmrEditNotify = new System.Windows.Forms.Timer(this.components);
this.dlgOpenFile = new System.Windows.Forms.OpenFileDialog();
this.dlgOpenDir = new System.Windows.Forms.FolderBrowserDialog();
this.btnLog = new System.Windows.Forms.Button();
this.dlgSaveFile = new System.Windows.Forms.SaveFileDialog();
this.listBox1 = new System.Windows.Forms.ListBox();
this.frmNotifierBindingSource = new System.Windows.Forms.BindingSource(this.components);
((System.ComponentModel.ISupportInitialize)(this.frmNotifierBindingSource)).BeginInit();
this.SuspendLayout();
//
// btnWatchFile
//
this.btnWatchFile.BackColor = System.Drawing.Color.LightSkyBlue;
this.btnWatchFile.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnWatchFile.ForeColor = System.Drawing.SystemColors.ControlText;
this.btnWatchFile.Location = new System.Drawing.Point(15, 165);
this.btnWatchFile.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.btnWatchFile.Name = "btnWatchFile";
this.btnWatchFile.Size = new System.Drawing.Size(159, 28);
this.btnWatchFile.TabIndex = 4;
this.btnWatchFile.Text = "Start Watching";
this.btnWatchFile.UseVisualStyleBackColor = false;
this.btnWatchFile.Click += new System.EventHandler(this.btnWatchFile_Click);
//
// lstNotification
//
this.lstNotification.FormattingEnabled = true;
this.lstNotification.ItemHeight = 16;
this.lstNotification.Location = new System.Drawing.Point(15, 228);
this.lstNotification.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.lstNotification.Name = "lstNotification";
this.lstNotification.Size = new System.Drawing.Size(613, 276);
this.lstNotification.TabIndex = 5;
this.lstNotification.SelectedIndexChanged += new System.EventHandler(this.lstNotification_SelectedIndexChanged);
//
// label3
//
this.label3.AutoSize = true;
this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label3.Location = new System.Drawing.Point(15, 208);
this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(158, 17);
this.label3.TabIndex = 6;
this.label3.Text = "Change Notifications";
//
// tmrEditNotify
//
this.tmrEditNotify.Enabled = true;
this.tmrEditNotify.Tick += new System.EventHandler(this.tmrEditNotify_Tick);
//
// dlgOpenDir
//
this.dlgOpenDir.RootFolder = System.Environment.SpecialFolder.MyComputer;
//
// btnLog
//
this.btnLog.BackColor = System.Drawing.SystemColors.Highlight;
this.btnLog.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnLog.Location = new System.Drawing.Point(15, 519);
this.btnLog.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.btnLog.Name = "btnLog";
this.btnLog.Size = new System.Drawing.Size(159, 28);
this.btnLog.TabIndex = 9;
this.btnLog.Text = "Dump To Log";
this.btnLog.UseVisualStyleBackColor = false;
this.btnLog.Click += new System.EventHandler(this.btnLog_Click);
//
// dlgSaveFile
//
this.dlgSaveFile.DefaultExt = "log";
this.dlgSaveFile.Filter = "LogFiles|*.log";
//
// listBox1
//
this.listBox1.DataSource = this.frmNotifierBindingSource;
this.listBox1.FormattingEnabled = true;
this.listBox1.ItemHeight = 16;
this.listBox1.Location = new System.Drawing.Point(807, 74);
this.listBox1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(277, 388);
this.listBox1.TabIndex = 10;
this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
//
// frmNotifierBindingSource
//
this.frmNotifierBindingSource.DataSource = typeof(FileChangeNotifier.frmNotifier);
//
// frmNotifier
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1207, 562);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.btnLog);
this.Controls.Add(this.label3);
this.Controls.Add(this.lstNotification);
this.Controls.Add(this.btnWatchFile);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.MaximizeBox = false;
this.Name = "frmNotifier";
this.Text = "File/Directory Change Notifier";
((System.ComponentModel.ISupportInitialize)(this.frmNotifierBindingSource)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button btnWatchFile;
private System.Windows.Forms.ListBox lstNotification;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Timer tmrEditNotify;
private System.Windows.Forms.OpenFileDialog dlgOpenFile;
private System.Windows.Forms.FolderBrowserDialog dlgOpenDir;
private System.Windows.Forms.Button btnLog;
private System.Windows.Forms.SaveFileDialog dlgSaveFile;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.BindingSource frmNotifierBindingSource;
}
}
Your current code is not compiled. ReadLine should be ReadAllLines.
And there is no code that will set the listbox value, so the listbox value is not changed.
Try to using this code:
private void OnChanged(object sender, FileSystemEventArgs e)
{
if (!m_bDirty)
{
m_Sb.Remove(0, m_Sb.Length);
m_Sb.Append(e.FullPath);
m_Sb.Append(" ");
m_Sb.Append(e.ChangeType.ToString());
m_Sb.Append(" ");
m_Sb.Append(DateTime.Now.ToString());
m_bDirty = true;
list = new List<string>(File.ReadAllLines(txtPath));
bindingList = new BindingList<string>(list);
listBox1.DataSource = bindingList;
}
}
UPDATE
After check your full code, seems you've wrong in this code (frmNotifier.cs):
m_bIsWatching = true;
That code will be cause your FileWatcher event handler not registered.
Try to debug it..
I get an unhandled exception that says:
System.NullReferenceException: Object reference not set to an instance of an object.
at Eagle_Eye_Class_Finder.GetSchedule.GetDataFromNumber(String ID) in C:\Users\Joshua Banks\Desktop\EET Project\Eagle Eye Class Finder\GetSchedule.cs:line 24
at Eagle_Eye_Class_Finder.Form1.button2_Click(Object sender, EventArgs e) in C:\Users\Joshua Banks\Desktop\EET Project\Eagle Eye Class Finder\Form1.cs:line 196
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.PerformClick()
at System.Windows.Forms.Form.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.Control.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.TextBoxBase.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.Control.PreProcessMessage(Message& msg)
at System.Windows.Forms.Control.PreProcessControlMessageInternal(Control target, Message& msg)
at System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)
Here is my get schedule class:
using System;
using System.IO;
using System.Data;
using System.Text;
using System.Drawing;
using System.Data.OleDb;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing.Printing;
using System.Collections.Generic;
namespace Eagle_Eye_Class_Finder
{
public class GetSchedule
{
public string GetDataFromNumber(string ID)
{
IDnumber[] IDnumbers = new IDnumber[3];
foreach (IDnumber IDCandidateMatch in IDnumbers)
{
if (IDCandidateMatch.ID == ID)
{
StringBuilder myData = new StringBuilder();
myData.AppendLine(IDCandidateMatch.Name);
myData.AppendLine(": ");
myData.AppendLine(IDCandidateMatch.ID);
myData.AppendLine(IDCandidateMatch.year);
myData.AppendLine(IDCandidateMatch.class1);
myData.AppendLine(IDCandidateMatch.class2);
myData.AppendLine(IDCandidateMatch.class3);
myData.AppendLine(IDCandidateMatch.class4);
//return myData;
return myData.ToString();
}
}
return "";
}
public GetSchedule()
{
IDnumber[] IDnumbers = new IDnumber[3];
IDnumbers[0] = new IDnumber() { Name = "Joshua Banks", ID = "900456317", year = "Senior", class1 = "TEET 4090", class2 = "TEET 3020", class3 = "TEET 3090", class4 = "TEET 4290" };
IDnumbers[1] = new IDnumber() { Name = "Sean Ward", ID = "900456318", year = "Junior", class1 = "ENGNR 4090", class2 = "ENGNR 3020", class3 = "ENGNR 3090", class4 = "ENGNR 4290" };
IDnumbers[2] = new IDnumber() { Name = "Terrell Johnson", ID = "900456319", year = "Sophomore", class1 = "BUS 4090", class2 = "BUS 3020", class3 = "BUS 3090", class4 = "BUS 4290" };
}
public class IDnumber
{
public string Name { get; set; }
public string ID { get; set; }
public string year { get; set; }
public string class1 { get; set; }
public string class2 { get; set; }
public string class3 { get; set; }
public string class4 { get; set; }
public static void ProcessNumber(IDnumber myNum)
{
StringBuilder myData = new StringBuilder();
myData.AppendLine(myNum.Name);
myData.AppendLine(": ");
myData.AppendLine(myNum.ID);
myData.AppendLine(myNum.year);
myData.AppendLine(myNum.class1);
myData.AppendLine(myNum.class2);
myData.AppendLine(myNum.class3);
myData.AppendLine(myNum.class4);
MessageBox.Show(myData.ToString());
}
}
}
}
Here is my Form 1 class:
using System;
using System.IO;
using System.Data;
using System.Text;
using System.Drawing;
using System.Data.OleDb;
using System.Collections;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing.Printing;
using System.Collections.Generic;
namespace Eagle_Eye_Class_Finder
{
/// This form is the entry form, it is the first form the user will see when the app is run.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.ProgressBar progressBar1;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.DateTimePicker dateTimePicker1;
private IContainer components;
private Timer timer1;
private BindingSource form1BindingSource;
public static Form Mainform = null;
// creates new instance of second form
YOURCLASSSCHEDULE SecondForm = new YOURCLASSSCHEDULE();
public Form1()
{
InitializeComponent();
// TODO: Add any constructor code after InitializeComponent call
}
/// Clean up any resources being used.
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#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()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.textBox1 = new System.Windows.Forms.TextBox();
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.button2 = new System.Windows.Forms.Button();
this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.form1BindingSource = new System.Windows.Forms.BindingSource(this.components);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.form1BindingSource)).BeginInit();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.textBox1.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.form1BindingSource, "Text", true, System.Windows.Forms.DataSourceUpdateMode.OnValidation, null, "900456317"));
this.textBox1.Location = new System.Drawing.Point(328, 280);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(208, 20);
this.textBox1.TabIndex = 2;
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
//
// progressBar1
//
this.progressBar1.Location = new System.Drawing.Point(258, 410);
this.progressBar1.MarqueeAnimationSpeed = 10;
this.progressBar1.Name = "progressBar1";
this.progressBar1.Size = new System.Drawing.Size(344, 8);
this.progressBar1.TabIndex = 3;
this.progressBar1.Click += new System.EventHandler(this.progressBar1_Click);
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(680, 400);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(120, 112);
this.pictureBox1.TabIndex = 4;
this.pictureBox1.TabStop = false;
this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
//
// button2
//
this.button2.Font = new System.Drawing.Font("Mistral", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.button2.Image = ((System.Drawing.Image)(resources.GetObject("button2.Image")));
this.button2.Location = new System.Drawing.Point(699, 442);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(78, 28);
this.button2.TabIndex = 5;
this.button2.Text = "OK";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// dateTimePicker1
//
this.dateTimePicker1.Location = new System.Drawing.Point(336, 104);
this.dateTimePicker1.Name = "dateTimePicker1";
this.dateTimePicker1.Size = new System.Drawing.Size(200, 20);
this.dateTimePicker1.TabIndex = 6;
this.dateTimePicker1.ValueChanged += new System.EventHandler(this.dateTimePicker1_ValueChanged);
//
// timer1
//
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// form1BindingSource
//
this.form1BindingSource.DataSource = typeof(Eagle_Eye_Class_Finder.Form1);
//
// Form1
//
this.AcceptButton = this.button2;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.ClientSize = new System.Drawing.Size(856, 556);
this.Controls.Add(this.dateTimePicker1);
this.Controls.Add(this.button2);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.progressBar1);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Eagle Eye Class Finder";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.form1BindingSource)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
/// The main entry point for the application.
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
public void Form1_Load(object sender, System.EventArgs e)
{
}
public void textBox1_TextChanged(object sender, System.EventArgs e)
{
//allows only numbers to be entered in textbox
string Str = textBox1.Text.Trim();
double Num;
bool isNum = double.TryParse(Str, out Num);
if (isNum)
Console.ReadLine();
else
MessageBox.Show("Enter A Valid ID Number!");
}
public void button2_Click(object sender, System.EventArgs e)
{
string text = textBox1.Text;
Mainform = this;
this.Hide();
GetSchedule myScheduleFinder = new GetSchedule();
string result = myScheduleFinder.GetDataFromNumber(text);
if (!string.IsNullOrEmpty(result))
{
MessageBox.Show(result);
}
else
{
MessageBox.Show("Enter A Valid ID Number!");
}
}
public void dateTimePicker1_ValueChanged(object sender, System.EventArgs e)
{
}
public void pictureBox1_Click(object sender, System.EventArgs e)
{
}
public void progressBar1_Click(object sender, EventArgs e)
{
//this.progressBar1 = new System.progressBar1();
//progressBar1.Maximum = 200;
//progressBar1.Minimum = 0;
//progressBar1.Step = 20;
}
private void timer1_Tick(object sender, EventArgs e)
{
//if (progressBar1.Value >= 200 )
//{
//progressBar1.Value = 0;
//}
//return;
//}
//progressBar1.Value != 20;
}
}
}
Here is my form 2 class:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace Eagle_Eye_Class_Finder
{
/// <summary>
/// Summary description for Form2.
/// </summary>
public class YOURCLASSSCHEDULE : System.Windows.Forms.Form
{
public System.Windows.Forms.LinkLabel linkLabel1;
public System.Windows.Forms.LinkLabel linkLabel2;
public System.Windows.Forms.LinkLabel linkLabel3;
public System.Windows.Forms.LinkLabel linkLabel4;
private Button button1;
/// Required designer variable.
public System.ComponentModel.Container components = null;
public YOURCLASSSCHEDULE()
{
//
InitializeComponent();
// TODO: Add any constructor code after InitializeComponent call
}
/// Clean up any resources being used.
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#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.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(YOURCLASSSCHEDULE));
this.linkLabel1 = new System.Windows.Forms.LinkLabel();
this.linkLabel2 = new System.Windows.Forms.LinkLabel();
this.linkLabel3 = new System.Windows.Forms.LinkLabel();
this.linkLabel4 = new System.Windows.Forms.LinkLabel();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// linkLabel1
//
this.linkLabel1.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.linkLabel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.linkLabel1.Font = new System.Drawing.Font("Times New Roman", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.linkLabel1.LinkArea = new System.Windows.Forms.LinkArea(0, 7);
this.linkLabel1.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline;
this.linkLabel1.Location = new System.Drawing.Point(41, 123);
this.linkLabel1.Name = "linkLabel1";
this.linkLabel1.Size = new System.Drawing.Size(288, 32);
this.linkLabel1.TabIndex = 1;
this.linkLabel1.TabStop = true;
this.linkLabel1.Text = "Class 1";
this.linkLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
//
// linkLabel2
//
this.linkLabel2.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.linkLabel2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.linkLabel2.Font = new System.Drawing.Font("Times New Roman", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.linkLabel2.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline;
this.linkLabel2.Location = new System.Drawing.Point(467, 123);
this.linkLabel2.Name = "linkLabel2";
this.linkLabel2.Size = new System.Drawing.Size(288, 32);
this.linkLabel2.TabIndex = 2;
this.linkLabel2.TabStop = true;
this.linkLabel2.Text = "Class 2";
this.linkLabel2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.linkLabel2.VisitedLinkColor = System.Drawing.Color.Navy;
this.linkLabel2.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel2_LinkClicked);
//
// linkLabel3
//
this.linkLabel3.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.linkLabel3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.linkLabel3.Font = new System.Drawing.Font("Times New Roman", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.linkLabel3.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline;
this.linkLabel3.Location = new System.Drawing.Point(41, 311);
this.linkLabel3.Name = "linkLabel3";
this.linkLabel3.Size = new System.Drawing.Size(288, 32);
this.linkLabel3.TabIndex = 3;
this.linkLabel3.TabStop = true;
this.linkLabel3.Text = "Class 3";
this.linkLabel3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.linkLabel3.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel3_LinkClicked);
//
// linkLabel4
//
this.linkLabel4.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.linkLabel4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.linkLabel4.Font = new System.Drawing.Font("Times New Roman", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.linkLabel4.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline;
this.linkLabel4.Location = new System.Drawing.Point(467, 311);
this.linkLabel4.Name = "linkLabel4";
this.linkLabel4.Size = new System.Drawing.Size(288, 32);
this.linkLabel4.TabIndex = 4;
this.linkLabel4.TabStop = true;
this.linkLabel4.Text = "Class 4";
this.linkLabel4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.linkLabel4.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel4_LinkClicked);
//
// button1
//
this.button1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.button1.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(64)))));
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.button1.Font = new System.Drawing.Font("Pristina", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.button1.ForeColor = System.Drawing.SystemColors.ActiveCaption;
this.button1.ImageAlign = System.Drawing.ContentAlignment.TopCenter;
this.button1.Location = new System.Drawing.Point(358, 206);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(101, 25);
this.button1.TabIndex = 5;
this.button1.Text = "Go Back";
this.button1.UseVisualStyleBackColor = false;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// YOURCLASSSCHEDULE
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.ClientSize = new System.Drawing.Size(790, 482);
this.Controls.Add(this.button1);
this.Controls.Add(this.linkLabel4);
this.Controls.Add(this.linkLabel3);
this.Controls.Add(this.linkLabel2);
this.Controls.Add(this.linkLabel1);
this.Font = new System.Drawing.Font("OldDreadfulNo7 BT", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Name = "YOURCLASSSCHEDULE";
this.Text = "Your Classes";
this.Load += new System.EventHandler(this.Form2_Load);
this.ResumeLayout(false);
}
#endregion
public void Form2_Load(object sender, System.EventArgs e)
{
// if (text == "900456317")
// {
//}
}
public void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("http://www.georgiasouthern.edu/map/");
}
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("http://www.georgiasouthern.edu/map/");
}
private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("http://www.georgiasouthern.edu/map/");
}
private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("http://www.georgiasouthern.edu/map/");
}
private void button1_Click(object sender, EventArgs e)
{
Form1 form1 = new Form1();
form1.Show();
this.Hide();
}
}
}
The problem is on this if statement:
IDnumber[] IDnumbers = new IDnumber[3];
foreach (IDnumber IDCandidateMatch in IDnumbers)
{
if (IDCandidateMatch.ID == ID)
You created array with three elements, but all elements are null. When you loop through them, the reference to IDCandidateMatch.ID generates the NullReferenceException.
Compiling perfectly has nothing to do with Exceptions. I would suggest looking at the stacktrace on the Exception, trying to find the line where the error is occuring, and going from there.
It looks like line 24 of GetSchedule.cs is a good place to start!
You're creating 2 different arrays, one in the constructor and another one in the method. if you move the line
IDnumber[] IDnumbers = new IDnumber[3];
outside of the method, and delete the identical one in the constructor it should work