I was trying to create a custom form designer with this article:
http://www.developerfusion.com/article/4351/hosting-windows-forms-designers/
that lets you create a custom form, visual studio alike.
but I can't figure out how to get all the controls in the created form, does someone know how to do this?
I used this code from the article:
using System;
using System.Drawing;
using System.Drawing.Design;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Data;
namespace Hosting
{
public class frmMain : System.Windows.Forms.Form
{
private System.Windows.Forms.PropertyGrid propertyGrid;
private System.Windows.Forms.Splitter splitter1;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Panel pnlViewHost;
private System.Windows.Forms.Splitter splitter2;
private ToolboxService lstToolbox;
private System.Windows.Forms.Label lblSelectedComponent;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem mnuDelete;
private MenuItem menuItem2;
private IContainer components;
public frmMain()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
Initialize();
}
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();
this.propertyGrid = new System.Windows.Forms.PropertyGrid();
this.splitter1 = new System.Windows.Forms.Splitter();
this.panel1 = new System.Windows.Forms.Panel();
this.splitter2 = new System.Windows.Forms.Splitter();
this.lblSelectedComponent = new System.Windows.Forms.Label();
this.pnlViewHost = new System.Windows.Forms.Panel();
this.mainMenu1 = new System.Windows.Forms.MainMenu(this.components);
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.mnuDelete = new System.Windows.Forms.MenuItem();
this.lstToolbox = new Hosting.ToolboxService();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// propertyGrid
//
this.propertyGrid.Dock = System.Windows.Forms.DockStyle.Bottom;
this.propertyGrid.LineColor = System.Drawing.SystemColors.ScrollBar;
this.propertyGrid.Location = new System.Drawing.Point(0, 182);
this.propertyGrid.Name = "propertyGrid";
this.propertyGrid.Size = new System.Drawing.Size(224, 312);
this.propertyGrid.TabIndex = 0;
//
// splitter1
//
this.splitter1.Dock = System.Windows.Forms.DockStyle.Right;
this.splitter1.Location = new System.Drawing.Point(596, 0);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(4, 518);
this.splitter1.TabIndex = 1;
this.splitter1.TabStop = false;
//
// panel1
//
this.panel1.Controls.Add(this.lstToolbox);
this.panel1.Controls.Add(this.splitter2);
this.panel1.Controls.Add(this.propertyGrid);
this.panel1.Controls.Add(this.lblSelectedComponent);
this.panel1.Dock = System.Windows.Forms.DockStyle.Right;
this.panel1.Location = new System.Drawing.Point(600, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(224, 518);
this.panel1.TabIndex = 2;
//
// splitter2
//
this.splitter2.Dock = System.Windows.Forms.DockStyle.Bottom;
this.splitter2.Location = new System.Drawing.Point(0, 178);
this.splitter2.Name = "splitter2";
this.splitter2.Size = new System.Drawing.Size(224, 4);
this.splitter2.TabIndex = 1;
this.splitter2.TabStop = false;
//
// lblSelectedComponent
//
this.lblSelectedComponent.Dock = System.Windows.Forms.DockStyle.Bottom;
this.lblSelectedComponent.Location = new System.Drawing.Point(0, 494);
this.lblSelectedComponent.Name = "lblSelectedComponent";
this.lblSelectedComponent.Size = new System.Drawing.Size(224, 24);
this.lblSelectedComponent.TabIndex = 3;
this.lblSelectedComponent.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// pnlViewHost
//
this.pnlViewHost.BackColor = System.Drawing.SystemColors.Window;
this.pnlViewHost.Dock = System.Windows.Forms.DockStyle.Fill;
this.pnlViewHost.Location = new System.Drawing.Point(0, 0);
this.pnlViewHost.Name = "pnlViewHost";
this.pnlViewHost.Size = new System.Drawing.Size(596, 518);
this.pnlViewHost.TabIndex = 3;
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnuDelete,
this.menuItem2});
this.menuItem1.Text = "&Edit";
//
// mnuDelete
//
this.mnuDelete.Index = 0;
this.mnuDelete.Shortcut = System.Windows.Forms.Shortcut.Del;
this.mnuDelete.Text = "&Delete";
this.mnuDelete.Click += new System.EventHandler(this.mnuDelete_Click);
//
// lstToolbox
//
this.lstToolbox.BackColor = System.Drawing.SystemColors.Control;
this.lstToolbox.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.lstToolbox.Dock = System.Windows.Forms.DockStyle.Fill;
this.lstToolbox.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lstToolbox.IntegralHeight = false;
this.lstToolbox.ItemHeight = 16;
this.lstToolbox.Location = new System.Drawing.Point(0, 0);
this.lstToolbox.Name = "lstToolbox";
this.lstToolbox.SelectedCategory = null;
this.lstToolbox.Size = new System.Drawing.Size(224, 178);
this.lstToolbox.Sorted = true;
this.lstToolbox.TabIndex = 2;
//
// menuItem2
//
this.menuItem2.Index = 1;
this.menuItem2.Text = "Save";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// frmMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
this.ClientSize = new System.Drawing.Size(824, 518);
this.Controls.Add(this.pnlViewHost);
this.Controls.Add(this.splitter1);
this.Controls.Add(this.panel1);
this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Menu = this.mainMenu1;
this.Name = "frmMain";
this.Text = "Designer Hosting Sample";
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new frmMain());
}
private ServiceContainer serviceContainer = null;
private MenuCommandService menuService = null;
Control view;
private void Initialize()
{
IDesignerHost host;
Form form;
IRootDesigner rootDesigner;
// Initialise service container and designer host
serviceContainer = new ServiceContainer();
serviceContainer.AddService(typeof(INameCreationService), new NameCreationService());
serviceContainer.AddService(typeof(IUIService), new UIService(this));
host = new DesignerHost(serviceContainer);
// Add toolbox service
serviceContainer.AddService(typeof(IToolboxService), lstToolbox);
lstToolbox.designPanel = pnlViewHost;
PopulateToolbox(lstToolbox);
// Add menu command service
menuService = new MenuCommandService();
serviceContainer.AddService(typeof(IMenuCommandService), menuService);
// Start the designer host off with a Form to design
form = (Form)host.CreateComponent(typeof(Form));
form.TopLevel = false;
form.Text = "Form1";
// Get the root designer for the form and add its design view to this form
rootDesigner = (IRootDesigner)host.GetDesigner(form);
view = (Control)rootDesigner.GetView(ViewTechnology.Default);
view.Dock = DockStyle.Fill;
pnlViewHost.Controls.Add(view);
// Subscribe to the selectionchanged event and activate the designer
ISelectionService s = (ISelectionService)serviceContainer.GetService(typeof(ISelectionService));
s.SelectionChanged += new EventHandler(OnSelectionChanged);
host.Activate();
}
private void PopulateToolbox(IToolboxService toolbox)
{
toolbox.AddToolboxItem(new ToolboxItem(typeof(Button)));
toolbox.AddToolboxItem(new ToolboxItem(typeof(ListView)));
toolbox.AddToolboxItem(new ToolboxItem(typeof(TreeView)));
toolbox.AddToolboxItem(new ToolboxItem(typeof(TextBox)));
toolbox.AddToolboxItem(new ToolboxItem(typeof(Label)));
toolbox.AddToolboxItem(new ToolboxItem(typeof(TabControl)));
toolbox.AddToolboxItem(new ToolboxItem(typeof(OpenFileDialog)));
toolbox.AddToolboxItem(new ToolboxItem(typeof(CheckBox)));
toolbox.AddToolboxItem(new ToolboxItem(typeof(ComboBox)));
toolbox.AddToolboxItem(new ToolboxItem(typeof(GroupBox)));
toolbox.AddToolboxItem(new ToolboxItem(typeof(ImageList)));
toolbox.AddToolboxItem(new ToolboxItem(typeof(Panel)));
toolbox.AddToolboxItem(new ToolboxItem(typeof(ProgressBar)));
toolbox.AddToolboxItem(new ToolboxItem(typeof(ToolBar)));
toolbox.AddToolboxItem(new ToolboxItem(typeof(ToolTip)));
toolbox.AddToolboxItem(new ToolboxItem(typeof(StatusBar)));
}
private void OnSelectionChanged(object sender, System.EventArgs e)
{
ISelectionService s = (ISelectionService)serviceContainer.GetService(typeof(ISelectionService));
object[] selection;
if (s.SelectionCount == 0)
propertyGrid.SelectedObject = null;
else
{
selection = new object[s.SelectionCount];
s.GetSelectedComponents().CopyTo(selection, 0);
propertyGrid.SelectedObjects = selection;
}
if (s.PrimarySelection == null)
lblSelectedComponent.Text = "";
else
{
IComponent component = (IComponent)s.PrimarySelection;
lblSelectedComponent.Text = component.Site.Name + " (" + component.GetType().Name + ")";
}
}
private void mnuDelete_Click(object sender, System.EventArgs e)
{
menuService.GlobalInvoke(StandardCommands.Delete);
}
}
}
Here is what I tried:
// And then i tried this to get all the controls and write them to a python tkinter file:
private void menuItem2_Click(object sender, EventArgs e)
{
System.IO.StreamWriter sw = new System.IO.StreamWriter("output.py");
sw.WriteLine("from tkinter import *\n");
sw.WriteLine("# Main form");
sw.WriteLine(this.Name + " = Tk()\n");
foreach (IComponent b in components.Components)
{
MessageBox.Show(b.GetType().ToString());
if (b.GetType() == typeof(Button))
{
Button but = (Button)b;
sw.WriteLine("# " + but.Name);
sw.WriteLine(but.Name + " = Button(" + this.Name + #"fg=""" + but.ForeColor.Name + #"""bg=""" + but.BackColor.Name + #"""" + ")");
}
}
sw.Close();
}
thanks in advance.
You get add control by use for loop.
foreach(Control c in form.Controls)
{
//You can save all attribute for each control on file or database
//c.Left, c.Top, c.Name,...
}
When you reload control in to form, use by code:
TextBox textbox = (TextBox)host.CreateComponent(typeof(TextBox));
textbox.Left = your value save before;
textbox.Top = your value save before;
textbox.Text = your text save before;
form.Controls.Add(textbox);
..Similar for orther controls
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 want to acces a combobox, a chart,... form my form. This is automatically added in my Form1. But now I need the combobox, chart... in another class. How can I reference this to the class DeviceClass? Do I have to make the combobox and others public in my form? Thanks for the help by advance. I tried in DeviceClass to put it like this:
private System.Windows.Forms.ComboBox cboChannels; bit it doesn' work. I think I need to make public it in other way in my from. or do I have to use a return in form?
public class Form1 : System.Windows.Forms.Form
{
DeviceClass d = new DeviceClass();
#region "Windows Form Designer generated code"
public void InitializeComponent()
{
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.grpDevice = new System.Windows.Forms.GroupBox();
this.btnInitialise = new System.Windows.Forms.Button();
this.cmbdevice = new System.Windows.Forms.ComboBox();
this.lblDevice = new System.Windows.Forms.Label();
this.grpAnalogOut = new System.Windows.Forms.GroupBox();
this.btnApplyOutputSettings = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.txtClockFreqFile = new System.Windows.Forms.TextBox();
this.lblClockFreqFile = new System.Windows.Forms.Label();
this.lblChListSize = new System.Windows.Forms.Label();
this.txtCglSize = new System.Windows.Forms.Label();
this.lblChListEntry = new System.Windows.Forms.Label();
this.cboEntry = new System.Windows.Forms.ComboBox();
this.lblOutputSignal = new System.Windows.Forms.Label();
this.cboSignalType = new System.Windows.Forms.ComboBox();
this.btnAddModifyOutputChannels = new System.Windows.Forms.Button();
this.cboChannels = new System.Windows.Forms.ComboBox();
this.lblOutputChannel = new System.Windows.Forms.Label();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.lblWaveClockFreq = new System.Windows.Forms.Label();
this.txtDaClockFreq = new System.Windows.Forms.TextBox();
this.txtBufferSize = new System.Windows.Forms.TextBox();
this.lblOutputBufferSize = new System.Windows.Forms.Label();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.lblOutputFreq = new System.Windows.Forms.Label();
this.txtOutputFrequency = new System.Windows.Forms.TextBox();
this.grpAnalogInput = new System.Windows.Forms.GroupBox();
this.lblNumOfCh = new System.Windows.Forms.Label();
this.btnApplyInputSettings = new System.Windows.Forms.Button();
this.grpDataAcqMode = new System.Windows.Forms.GroupBox();
this.lblSyncMode = new System.Windows.Forms.Label();
this.cmbSyncMode = new System.Windows.Forms.ComboBox();
this.btnSetNumOfCh = new System.Windows.Forms.Button();
this.cmbNumOfCh = new System.Windows.Forms.ComboBox();
this.grpChSettings = new System.Windows.Forms.GroupBox();
((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.OlBufferDataGrid)).BeginInit();
this.SuspendLayout();
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Location = new System.Drawing.Point(12, 12);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(1054, 625);
this.tabControl1.TabIndex = 92;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.grpDevice);
this.tabPage1.Controls.Add(this.grpAnalogOut);
this.tabPage1.Controls.Add(this.grpAnalogInput);
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
this.tabPage1.Size = new System.Drawing.Size(1046, 599);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "Setup";
this.tabPage1.UseVisualStyleBackColor = true;
//
// grpDevice
//
this.grpDevice.Controls.Add(this.btnInitialise);
this.grpDevice.Controls.Add(this.cmbdevice);
this.grpDevice.Controls.Add(this.lblDevice);
this.grpDevice.Location = new System.Drawing.Point(5, 5);
this.grpDevice.Name = "grpDevice";
this.grpDevice.Size = new System.Drawing.Size(467, 46);
this.grpDevice.TabIndex = 97;
this.grpDevice.TabStop = false;
this.grpDevice.Text = "Device settings";
//
// btnInitialise
//
this.btnInitialise.Location = new System.Drawing.Point(351, 16);
this.btnInitialise.Name = "btnInitialise";
this.btnInitialise.Size = new System.Drawing.Size(96, 25);
this.btnInitialise.TabIndex = 21;
this.btnInitialise.Text = "Initialize";
this.btnInitialise.Click += new System.EventHandler(this.btnInitialise_Click_1);
//
// cmbdevice
//
this.cmbdevice.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbdevice.Location = new System.Drawing.Point(197, 18);
this.cmbdevice.Name = "cmbdevice";
this.cmbdevice.Size = new System.Drawing.Size(117, 21);
this.cmbdevice.TabIndex = 63;
//
// lblDevice
//
this.lblDevice.AutoSize = true;
this.lblDevice.Location = new System.Drawing.Point(21, 22);
this.lblDevice.Name = "lblDevice";
this.lblDevice.Size = new System.Drawing.Size(44, 13);
this.lblDevice.TabIndex = 62;
this.lblDevice.Text = "Device:";
this.lblDevice.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// grpAnalogOut
//
this.grpAnalogOut.Controls.Add(this.btnApplyOutputSettings);
this.grpAnalogOut.Controls.Add(this.groupBox1);
this.grpAnalogOut.Controls.Add(this.groupBox2);
this.grpAnalogOut.Controls.Add(this.groupBox3);
this.grpAnalogOut.Location = new System.Drawing.Point(478, 56);
this.grpAnalogOut.Name = "grpAnalogOut";
this.grpAnalogOut.Size = new System.Drawing.Size(467, 298);
this.grpAnalogOut.TabIndex = 96;
this.grpAnalogOut.TabStop = false;
this.grpAnalogOut.Text = "Analog Output";
//
// btnApplyOutputSettings
//
this.btnApplyOutputSettings.Location = new System.Drawing.Point(5, 255);
this.btnApplyOutputSettings.Name = "btnApplyOutputSettings";
this.btnApplyOutputSettings.Size = new System.Drawing.Size(142, 32);
this.btnApplyOutputSettings.TabIndex = 109;
this.btnApplyOutputSettings.Text = "Apply Output Settings";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.txtClockFreqFile);
this.groupBox1.Controls.Add(this.lblClockFreqFile);
this.groupBox1.Controls.Add(this.lblChListSize);
this.groupBox1.Controls.Add(this.txtCglSize);
this.groupBox1.Controls.Add(this.lblChListEntry);
this.groupBox1.Controls.Add(this.cboEntry);
this.groupBox1.Controls.Add(this.lblOutputSignal);
this.groupBox1.Controls.Add(this.cboSignalType);
this.groupBox1.Controls.Add(this.btnAddModifyOutputChannels);
this.groupBox1.Controls.Add(this.cboChannels);
this.groupBox1.Controls.Add(this.lblOutputChannel);
this.groupBox1.Location = new System.Drawing.Point(7, 114);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(434, 136);
this.groupBox1.TabIndex = 108;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Channel List Setup";
//
// txtClockFreqFile
//
this.txtClockFreqFile.Location = new System.Drawing.Point(342, 55);
this.txtClockFreqFile.Name = "txtClockFreqFile";
this.txtClockFreqFile.Size = new System.Drawing.Size(80, 20);
this.txtClockFreqFile.TabIndex = 110;
//
// lblClockFreqFile
//
this.lblClockFreqFile.Location = new System.Drawing.Point(228, 49);
this.lblClockFreqFile.Name = "lblClockFreqFile";
this.lblClockFreqFile.Size = new System.Drawing.Size(104, 31);
this.lblClockFreqFile.TabIndex = 109;
this.lblClockFreqFile.Text = "Clock frequency output file:";
//
// lblChListSize
//
this.lblChListSize.Location = new System.Drawing.Point(228, 25);
this.lblChListSize.Name = "lblChListSize";
this.lblChListSize.Size = new System.Drawing.Size(104, 16);
this.lblChListSize.TabIndex = 107;
this.lblChListSize.Text = "Channel List Size :";
//
// txtCglSize
//
this.txtCglSize.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtCglSize.Location = new System.Drawing.Point(342, 26);
this.txtCglSize.Name = "txtCglSize";
this.txtCglSize.Size = new System.Drawing.Size(80, 16);
this.txtCglSize.TabIndex = 106;
//
// lblChListEntry
//
this.lblChListEntry.Location = new System.Drawing.Point(9, 24);
this.lblChListEntry.Name = "lblChListEntry";
this.lblChListEntry.Size = new System.Drawing.Size(56, 16);
this.lblChListEntry.TabIndex = 105;
this.lblChListEntry.Text = "Entry :";
this.lblChListEntry.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// cboEntry
//
this.cboEntry.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboEntry.Location = new System.Drawing.Point(115, 24);
this.cboEntry.Name = "cboEntry";
this.cboEntry.Size = new System.Drawing.Size(87, 21);
this.cboEntry.TabIndex = 104;
//
// lblOutputSignal
//
this.lblOutputSignal.Location = new System.Drawing.Point(9, 96);
this.lblOutputSignal.Name = "lblOutputSignal";
this.lblOutputSignal.Size = new System.Drawing.Size(88, 24);
this.lblOutputSignal.TabIndex = 103;
this.lblOutputSignal.Text = "Signal Type:";
this.lblOutputSignal.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// cboSignalType
//
this.cboSignalType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboSignalType.Location = new System.Drawing.Point(115, 96);
this.cboSignalType.Name = "cboSignalType";
this.cboSignalType.Size = new System.Drawing.Size(87, 21);
this.cboSignalType.TabIndex = 102;
//
// btnAddModifyOutputChannels
//
this.btnAddModifyOutputChannels.Location = new System.Drawing.Point(326, 85);
this.btnAddModifyOutputChannels.Name = "btnAddModifyOutputChannels";
this.btnAddModifyOutputChannels.Size = new System.Drawing.Size(96, 32);
this.btnAddModifyOutputChannels.TabIndex = 101;
this.btnAddModifyOutputChannels.Text = "Add/Modify";
//
// cboChannels
//
this.cboChannels.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cboChannels.Location = new System.Drawing.Point(115, 59);
this.cboChannels.Name = "cboChannels";
this.cboChannels.Size = new System.Drawing.Size(87, 21);
this.cboChannels.TabIndex = 99;
//
// lblOutputChannel
//
this.lblOutputChannel.Location = new System.Drawing.Point(9, 56);
this.lblOutputChannel.Name = "lblOutputChannel";
this.lblOutputChannel.Size = new System.Drawing.Size(88, 16);
this.lblOutputChannel.TabIndex = 100;
this.lblOutputChannel.Text = "Channel :";
this.lblOutputChannel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// lblWaveClockFreq
//
this.lblWaveClockFreq.Location = new System.Drawing.Point(9, 26);
this.lblWaveClockFreq.Name = "lblWaveClockFreq";
this.lblWaveClockFreq.Size = new System.Drawing.Size(88, 16);
this.lblWaveClockFreq.TabIndex = 7;
this.lblWaveClockFreq.Text = "D/A Clock Freq :";
this.lblWaveClockFreq.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// txtDaClockFreq
//
this.txtDaClockFreq.Location = new System.Drawing.Point(122, 24);
this.txtDaClockFreq.Name = "txtDaClockFreq";
this.txtDaClockFreq.ReadOnly = true;
this.txtDaClockFreq.Size = new System.Drawing.Size(80, 20);
this.txtDaClockFreq.TabIndex = 12;
//
// txtBufferSize
//
this.txtBufferSize.Location = new System.Drawing.Point(122, 49);
this.txtBufferSize.Name = "txtBufferSize";
this.txtBufferSize.ReadOnly = true;
this.txtBufferSize.Size = new System.Drawing.Size(80, 20);
this.txtBufferSize.TabIndex = 103;
//
// lblOutputBufferSize
//
this.lblOutputBufferSize.Location = new System.Drawing.Point(9, 50);
this.lblOutputBufferSize.Name = "lblOutputBufferSize";
this.lblOutputBufferSize.Size = new System.Drawing.Size(72, 16);
this.lblOutputBufferSize.TabIndex = 102;
this.lblOutputBufferSize.Text = "Buffer Size :";
this.lblOutputBufferSize.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// lblSyncMode
//
this.lblSyncMode.AutoSize = true;
this.lblSyncMode.Location = new System.Drawing.Point(13, 23);
this.lblSyncMode.Name = "lblSyncMode";
this.lblSyncMode.Size = new System.Drawing.Size(64, 13);
this.lblSyncMode.TabIndex = 2;
this.lblSyncMode.Text = "Sync Mode:";
//
// cmbSyncMode
//
this.cmbSyncMode.Location = new System.Drawing.Point(87, 21);
this.cmbSyncMode.Name = "cmbSyncMode";
this.cmbSyncMode.Size = new System.Drawing.Size(104, 21);
this.cmbSyncMode.TabIndex = 91;
this.cmbSyncMode.Text = "Not supported";
//
// Form1
//
this.ClientSize = new System.Drawing.Size(1190, 618);
this.Controls.Add(this.tabControl1);
this.Name = "Form1";
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.grpDevice.ResumeLayout(false);
this.grpDevice.PerformLayout();
this.grpAnalogOut.ResumeLayout(false);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.groupBox3.ResumeLayout(false);
this.groupBox3.PerformLayout();
this.grpAnalogInput.ResumeLayout(false);
this.grpAnalogInput.PerformLayout();
this.grpDataAcqMode.ResumeLayout(false);
this.grpDataAcqMode.PerformLayout();
this.grpChSettings.ResumeLayout(false);
this.grpChSettings.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudChGain)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudChNum)).EndInit();
this.grpClock.ResumeLayout(false);
this.grpClock.PerformLayout();
this.grpBuffering.ResumeLayout(false);
this.grpBuffering.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudNumOfBuffers)).EndInit();
this.tabPage2.ResumeLayout(false);
this.tabPage2.PerformLayout();
this.grpAcqVal.ResumeLayout(false);
this.grpAcqVal.PerformLayout();
this.grpAcqDuration.ResumeLayout(false);
this.grpAcqDuration.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudFiniteDuration)).EndInit();
this.grpPlot.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.OlBufferDataGrid)).EndInit();
this.ResumeLayout(false);
}
private TabControl tabControl1;
private TabPage tabPage1;
private GroupBox grpDevice;
private Button btnInitialise;
private ComboBox cmbdevice;
private Label lblDevice;
private GroupBox grpAnalogOut;
private NumericUpDown nudNumOfBuffers;
private Label lblNumOfBuffers;
private Label lblSamplesPerBuffer;
private TextBox txtSamplesPerBuffer;
private TabPage tabPage2;
private CheckBox chkEnableOutput;
private CheckBox chkEnableInput;
private GroupBox grpAcqVal;
private RadioButton rdoHexadecimal;
private RadioButton rdoDecimal;
private RadioButton rdoWriteToFile;
private Label lblStop;
private Label lblStart;
private GroupBox grpAcqDuration;
private NumericUpDown nudFiniteDuration;
private Label lblDuration;
private Label lblTimePassed;
private RadioButton rdoContinuous;
private RadioButton rdoFinite;
private GroupBox grpPlot;
private ComboBox cmbPlotChNum;
public System.Windows.Forms.DataVisualization.Charting.Chart chart1;
private DateTimePicker dtpMeasurementStop;
private DateTimePicker dtpMeasurementStart;
private Button btnSetMeasurementInterval;
private TextBox txtBuffersCompleted;
private Label lblBuffersDone;
private DataGrid OlBufferDataGrid;
private Button btnStart;
private Button btnStop;
#endregion "Windows Form Designer generated code"
#region "variables"
private DataTable OlBufferDataTable;
private Device device = null;
private DeviceMgr deviceMgr = DeviceMgr.Get();
#endregion "variables"
public Form1()
{
InitializeComponent();
CultureInfo english = new CultureInfo("en-US");
CultureInfo.DefaultThreadCurrentCulture = english;
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (device != null)
{
device.Dispose();
}
}
base.Dispose(disposing);
}
[STAThread]
private static void Main()
{
try
{
Application.Run(new Form1());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "Error");
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
string[] deviceNames = deviceMgr.GetDeviceNames();
for (int i = 0; i < deviceNames.Length; ++i)
{
cmbdevice.Items.Add(deviceNames[i]);
}
if (cmbdevice.Items.Count > 0)
{
cmbdevice.SelectedIndex = 0;
}
OlBufferDataTable = new DataTable("OlBuffer");
OlBufferDataGrid.DataSource = OlBufferDataTable;
DataRow newRow;
for (int i = 0; i < 10; i++)
{
newRow = OlBufferDataTable.NewRow();
OlBufferDataTable.Rows.Add(newRow);
}
cboSignalType.Items.Add("Sine");
cboSignalType.Items.Add("Ramp");
cboSignalType.Items.Add("Square");
cboSignalType.Items.Add("txt file");
}
private void btnInitialise_Click_1(object sender, EventArgs e)
{
d.weergeven();
}
}
public class DeviceClass
{
public void weergeven()
{
string deviceName = (string)cmbdevice.SelectedItem;
try
{
if (device != null)
{
device.Dispose();
}
device = deviceMgr.GetDevice(deviceName);
ainSS = device.AnalogInputSubsystem(0);
ainSS.DriverRunTimeErrorEvent += new DriverRunTimeErrorEventHandler(HandleDriverRunTimeErrorEvent);
ainSS.DriverRunTimeErrorEvent += new DriverRunTimeErrorEventHandler(HandleDriverRunTimeErrorEvent);
ainSS.BufferDoneEvent += new BufferDoneHandler(HandleBufferDone);
ainSS.QueueDoneEvent += new QueueDoneHandler(HandleQueueDone);
ainSS.QueueStoppedEvent += new QueueStoppedHandler(HandleQueueStopped);
aoutSS = device.AnalogOutputSubsystem(0);
aoutSS.DataFlow = DataFlow.Continuous;
aoutSS.DriverRunTimeErrorEvent += new DriverRunTimeErrorEventHandler(HandleDriverRunTimeErrorEvent);
aoutSS.BufferDoneEvent += new BufferDoneHandler(HandleBufferDone);
aoutSS.QueueDoneEvent += new QueueDoneHandler(HandleQueueDone);
aoutSS.QueueStoppedEvent += new QueueStoppedHandler(HandleQueueStopped);
aoutSS.IOCompleteEvent += new IOCompleteHandler(HandleIOComplete);
signalList = new short[aoutSS.NumberOfChannels];
for (int i = 0; i < aoutSS.NumberOfChannels; ++i)
{
if (aoutSS.SupportedChannels[i].SubsystemType != SubsystemType.AnalogOutput)
continue;
cboChannels.Items.Add(i.ToString());
cboEntry.Items.Add(i.ToString());
}
cboEntry.SelectedIndex = 0;
cboChannels.SelectedIndex = 0;
statusBarPanel.Text = "Output configured without error";
string name;
cmbCouplingType.Items.Clear();
cmbCurrentSource.Items.Clear();
cmbSyncMode.Items.Clear();
if (ainSS.SupportsSynchronization)
{
string[] names = Enum.GetNames(typeof(SynchronizationModes));
for (int i = 0; i < names.Length; i++)
cmbSyncMode.Items.Add(names[i]);
cmbSyncMode.SelectedIndex = 0;
}
else
{
cmbSyncMode.Items.Add("NotSupported");
this.cmbSyncMode.Enabled = false;
cmbSyncMode.SelectedIndex = 0;
}
if (ainSS.SupportsDCCoupling || ainSS.SupportsACCoupling)
{
if (ainSS.SupportsDCCoupling)
{
name = Enum.GetName(typeof(CouplingType), CouplingType.DC);
cmbCouplingType.Items.Add(name);
cmbCouplingType.SelectedIndex = cmbCouplingType.Items.IndexOf(name);
}
if (ainSS.SupportsACCoupling)
{
name = Enum.GetName(typeof(CouplingType), CouplingType.AC);
cmbCouplingType.Items.Add(name);
cmbCouplingType.SelectedIndex = cmbCouplingType.Items.IndexOf(name);
}
this.cmbCouplingType.Enabled = true;
}
else
{
cmbCouplingType.Items.Add("NotSupported");
this.cmbCouplingType.Enabled = false;
cmbCouplingType.SelectedIndex = 0;
}
if (ainSS.SupportsExternalExcitationCurrentSrc || ainSS.SupportsInternalExcitationCurrentSrc)
{
if (ainSS.SupportsExternalExcitationCurrentSrc)
{
name = Enum.GetName(typeof(ExcitationCurrentSource), ExcitationCurrentSource.External);
cmbCurrentSource.Items.Add(name);
cmbCurrentSource.SelectedIndex = cmbCouplingType.Items.IndexOf(name);
}
if (ainSS.SupportsInternalExcitationCurrentSrc)
{
name = Enum.GetName(typeof(ExcitationCurrentSource), ExcitationCurrentSource.Internal);
cmbCurrentSource.Items.Add(name);
cmbCurrentSource.SelectedIndex = cmbCurrentSource.Items.IndexOf(name);
}
name = Enum.GetName(typeof(ExcitationCurrentSource), ExcitationCurrentSource.Disabled);
cmbCurrentSource.Items.Add(name);
cmbCurrentSource.Enabled = true;
cmbCurrentSource.SelectedItem = "Disabled";
}
else
{
cmbCurrentSource.Items.Add("NotSupported");
cmbCurrentSource.Enabled = false;
cmbCurrentSource.SelectedIndex = 0;
}
if (ainSS.SupportsSimultaneousSampleHold)
{
statusBarPanel.Text = "Analog input subsystem supports simultaneous sample and hold data acquiring";
}
}
catch (OlException ex)
{
string err = ex.Message;
statusBarPanel.Text = err;
return;
}
}
}
What I would do:
Pass your form as an object to the class
In your form make a method for altering the UI
(for example:
public void WriteTextBox(string ToWrite)
{
TextBoxName.Text = ToWrite;
}
)
Call this method from your main form
I have covered many tutorials and articles but can not find exactly what I need to assist me in resolving my issue.
My issue is that my compiled dll does not return rows of data from my SQL database file to the DataGridView.
I have created this project as a windows application for testing and it works fine. However, when I change the output to a class library it runs but does not return any data to the DataGridView. The header is there, because it is declared, but I have a feeling the compiled dll can not establish a connection to the database.
I have experience with C# and ASP but not in creating dll's.
To also clarify further, I can use the dataset or the bindingsource before I compile and view all the records using the Preview Data option. Is there a specific way you have to setup the database connection when creating a class library in my situation?
SQLDatabase.mdf Connection String:
Data Source=(localdb)\v11.0;Initial Catalog=SQLDatabase.mdf;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False
Designer Generated Code: this.itemsTableAdapter.Fill(this.abDataSet.Items);
Please let me know if you would like me to post the Form.Designer.cs which was Designer Generated Code as well. Again, everything works fine as a Windows Application but as a Class Library the rows of data are never displayed in the DataGridView.
namespace AHPriceChecker4Free
{
public class AHPriceChecker : Core
{
private Thread formThread;
public void PluginStop()
{
Log("closed");
}
private AHCheckerForm ahForm;
public bool formIsOpen;
public void PluginRun()
{
formThread = new Thread(RunForm);
formThread.SetApartmentState(ApartmentState.STA);
formThread.Start();
formIsOpen = true;
while (formIsOpen)
{
Thread.Sleep(1000);
}
}
private void RunForm()
{
ahForm = new AHCheckerForm(this, me);
System.Windows.Forms.Application.Run(ahForm);
}
}
}
Form.cs
namespace AHPriceChecker4Free
{
partial class AHCheckerForm
{
/// <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();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AHCheckerForm));
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.tsmMain = new System.Windows.Forms.ToolStripMenuItem();
this.tsmLoad = new System.Windows.Forms.ToolStripMenuItem();
this.tsmSave = new System.Windows.Forms.ToolStripMenuItem();
this.txtItemName = new System.Windows.Forms.TextBox();
this.btnSearch = new System.Windows.Forms.Button();
this.ofdOpen = new System.Windows.Forms.OpenFileDialog();
this.sfdSave = new System.Windows.Forms.SaveFileDialog();
this.btnMassSearch = new System.Windows.Forms.Button();
this.itemPriceHistory = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.itemAveragePrice = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.itemLastPrice = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.itemName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.dgvAuctionTable = new System.Windows.Forms.DataGridView();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.label1 = new System.Windows.Forms.Label();
this.rtbSave = new System.Windows.Forms.RichTextBox();
this.tabPage3 = new System.Windows.Forms.TabPage();
this.label8 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.tabPage4 = new System.Windows.Forms.TabPage();
this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.idDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.itemNameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.goldDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.silverDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.copperDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.perQtyDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.abchristDataSet = new AHPriceChecker4Free.abchristDataSet();
this.itemsTableAdapter = new AHPriceChecker4Free.abchristDataSetTableAdapters.ItemsTableAdapter();
this.itemsBindingSource1 = new System.Windows.Forms.BindingSource(this.components);
this.menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dgvAuctionTable)).BeginInit();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.tabPage2.SuspendLayout();
this.tabPage3.SuspendLayout();
this.tabPage4.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.abchristDataSet)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.itemsBindingSource1)).BeginInit();
this.SuspendLayout();
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.tsmMain});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Padding = new System.Windows.Forms.Padding(7, 2, 0, 2);
this.menuStrip1.Size = new System.Drawing.Size(819, 24);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
this.menuStrip1.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.menuStrip1_ItemClicked);
//
// tsmMain
//
this.tsmMain.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.tsmLoad,
this.tsmSave});
this.tsmMain.Name = "tsmMain";
this.tsmMain.Size = new System.Drawing.Size(41, 20);
this.tsmMain.Text = "&Main";
//
// tsmLoad
//
this.tsmLoad.Name = "tsmLoad";
this.tsmLoad.Size = new System.Drawing.Size(123, 22);
this.tsmLoad.Text = "&Load data";
this.tsmLoad.Click += new System.EventHandler(this.tsmLoad_Click);
//
// tsmSave
//
this.tsmSave.Name = "tsmSave";
this.tsmSave.Size = new System.Drawing.Size(123, 22);
this.tsmSave.Text = "&Save data";
this.tsmSave.Click += new System.EventHandler(this.transferDataToSave);
//
// txtItemName
//
this.txtItemName.BackColor = System.Drawing.Color.LightYellow;
this.txtItemName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtItemName.Location = new System.Drawing.Point(8, 353);
this.txtItemName.Name = "txtItemName";
this.txtItemName.Size = new System.Drawing.Size(203, 20);
this.txtItemName.TabIndex = 2;
//
// btnSearch
//
this.btnSearch.BackColor = System.Drawing.Color.LightYellow;
this.btnSearch.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnSearch.Location = new System.Drawing.Point(217, 351);
this.btnSearch.Name = "btnSearch";
this.btnSearch.Size = new System.Drawing.Size(87, 25);
this.btnSearch.TabIndex = 5;
this.btnSearch.Text = "Search";
this.btnSearch.UseVisualStyleBackColor = false;
this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
//
// ofdOpen
//
this.ofdOpen.FileName = "openFileDialog1";
//
// sfdSave
//
this.sfdSave.FileOk += new System.ComponentModel.CancelEventHandler(this.sfdSave_FileOk);
//
// btnMassSearch
//
this.btnMassSearch.BackColor = System.Drawing.Color.LightYellow;
this.btnMassSearch.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnMassSearch.Location = new System.Drawing.Point(310, 351);
this.btnMassSearch.Name = "btnMassSearch";
this.btnMassSearch.Size = new System.Drawing.Size(105, 25);
this.btnMassSearch.TabIndex = 8;
this.btnMassSearch.Text = "Mass search";
this.btnMassSearch.UseVisualStyleBackColor = false;
this.btnMassSearch.Click += new System.EventHandler(this.btnMassSearch_Click);
//
// itemPriceHistory
//
this.itemPriceHistory.HeaderText = "Price History";
this.itemPriceHistory.Name = "itemPriceHistory";
this.itemPriceHistory.ReadOnly = true;
this.itemPriceHistory.Width = 350;
//
// itemAveragePrice
//
this.itemAveragePrice.HeaderText = "Average price";
this.itemAveragePrice.Name = "itemAveragePrice";
this.itemAveragePrice.ReadOnly = true;
this.itemAveragePrice.Width = 110;
//
// itemLastPrice
//
this.itemLastPrice.HeaderText = "Last price";
this.itemLastPrice.Name = "itemLastPrice";
//
// itemName
//
this.itemName.Frozen = true;
this.itemName.HeaderText = "Name";
this.itemName.Name = "itemName";
this.itemName.ReadOnly = true;
this.itemName.Width = 200;
//
// dgvAuctionTable
//
this.dgvAuctionTable.BackgroundColor = System.Drawing.Color.Cornsilk;
this.dgvAuctionTable.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgvAuctionTable.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.itemName,
this.itemLastPrice,
this.itemAveragePrice,
this.itemPriceHistory});
this.dgvAuctionTable.Dock = System.Windows.Forms.DockStyle.Top;
this.dgvAuctionTable.Location = new System.Drawing.Point(3, 3);
this.dgvAuctionTable.Name = "dgvAuctionTable";
this.dgvAuctionTable.RowHeadersVisible = false;
this.dgvAuctionTable.Size = new System.Drawing.Size(805, 342);
this.dgvAuctionTable.TabIndex = 1;
this.dgvAuctionTable.CurrentCellDirtyStateChanged += new System.EventHandler(this.dgvAuctionTable_CurrentCellDirtyStateChanged);
//
**// *** REMOVED ALL TABS BUT THE ONE I AM HAVING AN ISSUE WITH TO REDUCE SIZE. THIS FORM BODY IS LIMITED TO 30000 CHARACTERS WHEN POSTING *** //
//**
// tabPage4
//
this.tabPage4.Controls.Add(this.dataGridView1);
this.tabPage4.Location = new System.Drawing.Point(4, 23);
this.tabPage4.Name = "tabPage4";
this.tabPage4.Padding = new System.Windows.Forms.Padding(3);
this.tabPage4.Size = new System.Drawing.Size(811, 381);
this.tabPage4.TabIndex = 3;
this.tabPage4.Text = "Database";
this.tabPage4.UseVisualStyleBackColor = true;
//
// dataGridView1
//
this.dataGridView1.AllowUserToAddRows = false;
this.dataGridView1.AllowUserToDeleteRows = false;
this.dataGridView1.AutoGenerateColumns = false;
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.idDataGridViewTextBoxColumn,
this.itemNameDataGridViewTextBoxColumn,
this.goldDataGridViewTextBoxColumn,
this.silverDataGridViewTextBoxColumn,
this.copperDataGridViewTextBoxColumn,
this.perQtyDataGridViewTextBoxColumn});
this.dataGridView1.DataSource = this.itemsBindingSource1;
this.dataGridView1.Location = new System.Drawing.Point(66, 69);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.ReadOnly = true;
this.dataGridView1.RowHeadersVisible = false;
this.dataGridView1.Size = new System.Drawing.Size(669, 194);
this.dataGridView1.TabIndex = 0;
//
// idDataGridViewTextBoxColumn
//
this.idDataGridViewTextBoxColumn.DataPropertyName = "Id";
this.idDataGridViewTextBoxColumn.HeaderText = "Id";
this.idDataGridViewTextBoxColumn.Name = "idDataGridViewTextBoxColumn";
this.idDataGridViewTextBoxColumn.ReadOnly = true;
//
// itemNameDataGridViewTextBoxColumn
//
this.itemNameDataGridViewTextBoxColumn.DataPropertyName = "ItemName";
this.itemNameDataGridViewTextBoxColumn.HeaderText = "ItemName";
this.itemNameDataGridViewTextBoxColumn.Name = "itemNameDataGridViewTextBoxColumn";
this.itemNameDataGridViewTextBoxColumn.ReadOnly = true;
//
// goldDataGridViewTextBoxColumn
//
this.goldDataGridViewTextBoxColumn.DataPropertyName = "Gold";
this.goldDataGridViewTextBoxColumn.HeaderText = "Gold";
this.goldDataGridViewTextBoxColumn.Name = "goldDataGridViewTextBoxColumn";
this.goldDataGridViewTextBoxColumn.ReadOnly = true;
//
// silverDataGridViewTextBoxColumn
//
this.silverDataGridViewTextBoxColumn.DataPropertyName = "Silver";
this.silverDataGridViewTextBoxColumn.HeaderText = "Silver";
this.silverDataGridViewTextBoxColumn.Name = "silverDataGridViewTextBoxColumn";
this.silverDataGridViewTextBoxColumn.ReadOnly = true;
//
// copperDataGridViewTextBoxColumn
//
this.copperDataGridViewTextBoxColumn.DataPropertyName = "Copper";
this.copperDataGridViewTextBoxColumn.HeaderText = "Copper";
this.copperDataGridViewTextBoxColumn.Name = "copperDataGridViewTextBoxColumn";
this.copperDataGridViewTextBoxColumn.ReadOnly = true;
//
// perQtyDataGridViewTextBoxColumn
//
this.perQtyDataGridViewTextBoxColumn.DataPropertyName = "PerQty";
this.perQtyDataGridViewTextBoxColumn.HeaderText = "PerQty";
this.perQtyDataGridViewTextBoxColumn.Name = "perQtyDataGridViewTextBoxColumn";
this.perQtyDataGridViewTextBoxColumn.ReadOnly = true;
//
// abchristDataSet
//
this.abchristDataSet.DataSetName = "abchristDataSet";
this.abchristDataSet.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema;
//
// itemsTableAdapter
//
this.itemsTableAdapter.ClearBeforeFill = true;
//
// itemsBindingSource1
//
this.itemsBindingSource1.DataMember = "Items";
this.itemsBindingSource1.DataSource = this.abchristDataSet;
//
// AHCheckerForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 14F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Cornsilk;
this.ClientSize = new System.Drawing.Size(819, 432);
this.Controls.Add(this.tabControl1);
this.Controls.Add(this.menuStrip1);
this.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MainMenuStrip = this.menuStrip1;
this.Name = "AHCheckerForm";
this.Text = "AHPriceChecker4Free - By Cobras.Club";
this.TopMost = true;
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.AHCheckerForm_FormClosed);
this.Load += new System.EventHandler(this.AHCheckerForm_Load);
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dgvAuctionTable)).EndInit();
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.tabPage1.PerformLayout();
this.tabPage2.ResumeLayout(false);
this.tabPage2.PerformLayout();
this.tabPage3.ResumeLayout(false);
this.tabPage3.PerformLayout();
this.tabPage4.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.abchristDataSet)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.itemsBindingSource1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem tsmMain;
private System.Windows.Forms.ToolStripMenuItem tsmLoad;
private System.Windows.Forms.TextBox txtItemName;
private System.Windows.Forms.Button btnSearch;
private System.Windows.Forms.OpenFileDialog ofdOpen;
private System.Windows.Forms.SaveFileDialog sfdSave;
private System.Windows.Forms.Button btnMassSearch;
private System.Windows.Forms.ToolStripMenuItem tsmSave;
private System.Windows.Forms.DataGridViewTextBoxColumn itemPriceHistory;
private System.Windows.Forms.DataGridViewTextBoxColumn itemAveragePrice;
private System.Windows.Forms.DataGridViewTextBoxColumn itemLastPrice;
private System.Windows.Forms.DataGridViewTextBoxColumn itemName;
private System.Windows.Forms.DataGridView dgvAuctionTable;
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.RichTextBox rtbSave;
private System.Windows.Forms.TabPage tabPage3;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TabPage tabPage4;
private System.Windows.Forms.DataGridView dataGridView1;
private abchristDataSet abchristDataSet;
private abchristDataSetTableAdapters.ItemsTableAdapter itemsTableAdapter;
private System.Windows.Forms.DataGridViewTextBoxColumn idDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn itemNameDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn goldDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn silverDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn copperDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn perQtyDataGridViewTextBoxColumn;
private System.Windows.Forms.BindingSource itemsBindingSource1;
}
}
You have to add code in your class library that will let you set the connection string. The place to set the connection string is in the constructor of your class library. You can manually add the connection string like this in the app.config:
<connectionStrings>
<add name="MyDB" connectionString="Server=.\SQLExpress;
AttachDbFilename=C:\MyFolder\MyDataFile.mdf;Database=dbname;
Trusted_Connection=Yes;" />
</connectionStrings>
Then access the configuration string like this:
var str = ConfigurationManager.ConnectionStrings["MyDb"].ConnectionString
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;
}
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