My ComboBox__SelectedIndexChanged won't start - c#

i have some issues with my ComboBox. when i press or do anything it wont start up. At first i thought it was my code but i have now done a simple Messagebox message and still it wont work, the code that is commented out is the code that has to be runned.
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;
using MySql.Data.MySqlClient;
namespace Dark_Heresy
{
public partial class Talents : Form
{
public Talents()
{
InitializeComponent();
}
private void cb_Talents_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show("Test");
//string constring = "datasource = localhost; port = 3306; username = root; password = Mypass;";
//string Query = "SELECT * FROM dark_heresy.talents WHERE TalentName='" + cb_Talents.Text + "' ;";
//MySqlConnection conDataBase = new MySqlConnection(constring);
//MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase);
//MySqlDataReader myReader;
//try
//{
// conDataBase.Open();
// myReader = cmdDataBase.ExecuteReader();
// while (myReader.Read())
// {
// string description = myReader.GetString("Description");
// string strength = myReader.GetInt32("R_Str").ToString();
// string weaponskill = myReader.GetInt32("R_WS").ToString();
// string ballisticskill = myReader.GetInt32("R_BS").ToString();
// string fellowship = myReader.GetInt32("R_Fel").ToString();
// string perception = myReader.GetInt32("R_Per").ToString();
// string intelligence = myReader.GetInt32("R_Int").ToString();
// string agility = myReader.GetInt32("R_Agi").ToString();
// string willpower = myReader.GetInt32("R_WP").ToString();
// string toughness = myReader.GetInt32("R_Tough").ToString();
// string talentrequired = myReader.GetString("Talent_required");
// string skillrequired = myReader.GetString("Skill_required");
// string classrequired = myReader.GetString("Class_required");
// TextDescription.Text = description;
// TextStrengh.Text = strength;
// TextWeaponskill.Text = weaponskill;
// TextBallisticskill.Text = ballisticskill;
// TextFellowship.Text = fellowship;
// TextPerception.Text = perception;
// TextIntelligence.Text = intelligence;
// TextAgility.Text = agility;
// TextWillpower.Text = willpower;
// TextToughness.Text = toughness;
// TextTalent.Text = talentrequired;
// TextSkill.Text = skillrequired;
// TextClass.Text = classrequired;
// }
//}
// catch (Exception ex)
// {
// MessageBox.Show("Error: \r\n" + ex);
// }
}
private void Talents_Load(object sender, EventArgs e)
{
}
}
}
What is wrong with it? is there a setting that has to be changed?
Talents.Designer.cs
namespace Dark_Heresy
{
partial class Talents
{
/// <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()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Talents));
this.grp_Attributes = new System.Windows.Forms.GroupBox();
this.TextBallisticskill = new System.Windows.Forms.TextBox();
this.TextWeaponskill = new System.Windows.Forms.TextBox();
this.TextFellowship = new System.Windows.Forms.TextBox();
this.TextWillpower = new System.Windows.Forms.TextBox();
this.TextPerception = new System.Windows.Forms.TextBox();
this.TextIntelligence = new System.Windows.Forms.TextBox();
this.TextAgility = new System.Windows.Forms.TextBox();
this.TextToughness = new System.Windows.Forms.TextBox();
this.TextStrengh = new System.Windows.Forms.TextBox();
this.required_Ballisticskill = new System.Windows.Forms.Label();
this.required_Weaponskill = new System.Windows.Forms.Label();
this.required_Fellowship = new System.Windows.Forms.Label();
this.required_Willpower = new System.Windows.Forms.Label();
this.required_Perception = new System.Windows.Forms.Label();
this.required_Intelligence = new System.Windows.Forms.Label();
this.required_Agility = new System.Windows.Forms.Label();
this.required_Toughness = new System.Windows.Forms.Label();
this.required_Strength = new System.Windows.Forms.Label();
this.cb_Talents = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.TextDescription = new System.Windows.Forms.TextBox();
this.TextClass = new System.Windows.Forms.TextBox();
this.TextSkill = new System.Windows.Forms.TextBox();
this.TextTalent = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.grp_Attributes.SuspendLayout();
this.SuspendLayout();
//
// grp_Attributes
//
this.grp_Attributes.Controls.Add(this.TextBallisticskill);
this.grp_Attributes.Controls.Add(this.TextWeaponskill);
this.grp_Attributes.Controls.Add(this.TextFellowship);
this.grp_Attributes.Controls.Add(this.TextWillpower);
this.grp_Attributes.Controls.Add(this.TextPerception);
this.grp_Attributes.Controls.Add(this.TextIntelligence);
this.grp_Attributes.Controls.Add(this.TextAgility);
this.grp_Attributes.Controls.Add(this.TextToughness);
this.grp_Attributes.Controls.Add(this.TextStrengh);
this.grp_Attributes.Controls.Add(this.required_Ballisticskill);
this.grp_Attributes.Controls.Add(this.required_Weaponskill);
this.grp_Attributes.Controls.Add(this.required_Fellowship);
this.grp_Attributes.Controls.Add(this.required_Willpower);
this.grp_Attributes.Controls.Add(this.required_Perception);
this.grp_Attributes.Controls.Add(this.required_Intelligence);
this.grp_Attributes.Controls.Add(this.required_Agility);
this.grp_Attributes.Controls.Add(this.required_Toughness);
this.grp_Attributes.Controls.Add(this.required_Strength);
this.grp_Attributes.Location = new System.Drawing.Point(225, 117);
this.grp_Attributes.Name = "grp_Attributes";
this.grp_Attributes.Size = new System.Drawing.Size(158, 377);
this.grp_Attributes.TabIndex = 4;
this.grp_Attributes.TabStop = false;
this.grp_Attributes.Text = "Required Attributes";
//
// TextBallisticskill
//
this.TextBallisticskill.Location = new System.Drawing.Point(89, 280);
this.TextBallisticskill.Name = "TextBallisticskill";
this.TextBallisticskill.Size = new System.Drawing.Size(21, 20);
this.TextBallisticskill.TabIndex = 17;
//
// TextWeaponskill
//
this.TextWeaponskill.Location = new System.Drawing.Point(89, 251);
this.TextWeaponskill.Name = "TextWeaponskill";
this.TextWeaponskill.Size = new System.Drawing.Size(22, 20);
this.TextWeaponskill.TabIndex = 16;
//
// TextFellowship
//
this.TextFellowship.Location = new System.Drawing.Point(88, 217);
this.TextFellowship.Name = "TextFellowship";
this.TextFellowship.Size = new System.Drawing.Size(23, 20);
this.TextFellowship.TabIndex = 15;
//
// TextWillpower
//
this.TextWillpower.Location = new System.Drawing.Point(89, 191);
this.TextWillpower.Name = "TextWillpower";
this.TextWillpower.Size = new System.Drawing.Size(22, 20);
this.TextWillpower.TabIndex = 14;
//
// TextPerception
//
this.TextPerception.Location = new System.Drawing.Point(89, 158);
this.TextPerception.Name = "TextPerception";
this.TextPerception.Size = new System.Drawing.Size(22, 20);
this.TextPerception.TabIndex = 13;
//
// TextIntelligence
//
this.TextIntelligence.Location = new System.Drawing.Point(89, 124);
this.TextIntelligence.Name = "TextIntelligence";
this.TextIntelligence.Size = new System.Drawing.Size(22, 20);
this.TextIntelligence.TabIndex = 12;
//
// TextAgility
//
this.TextAgility.Location = new System.Drawing.Point(88, 92);
this.TextAgility.Name = "TextAgility";
this.TextAgility.Size = new System.Drawing.Size(23, 20);
this.TextAgility.TabIndex = 11;
//
// TextToughness
//
this.TextToughness.Location = new System.Drawing.Point(88, 65);
this.TextToughness.Name = "TextToughness";
this.TextToughness.Size = new System.Drawing.Size(23, 20);
this.TextToughness.TabIndex = 10;
//
// TextStrengh
//
this.TextStrengh.Location = new System.Drawing.Point(88, 30);
this.TextStrengh.Name = "TextStrengh";
this.TextStrengh.Size = new System.Drawing.Size(23, 20);
this.TextStrengh.TabIndex = 9;
//
// required_Ballisticskill
//
this.required_Ballisticskill.AutoSize = true;
this.required_Ballisticskill.Location = new System.Drawing.Point(19, 283);
this.required_Ballisticskill.Name = "required_Ballisticskill";
this.required_Ballisticskill.Size = new System.Drawing.Size(62, 13);
this.required_Ballisticskill.TabIndex = 8;
this.required_Ballisticskill.Text = "Ballistic skill";
//
// required_Weaponskill
//
this.required_Weaponskill.AutoSize = true;
this.required_Weaponskill.Location = new System.Drawing.Point(19, 251);
this.required_Weaponskill.Name = "required_Weaponskill";
this.required_Weaponskill.Size = new System.Drawing.Size(68, 13);
this.required_Weaponskill.TabIndex = 7;
this.required_Weaponskill.Text = "Weapon skill";
//
// required_Fellowship
//
this.required_Fellowship.AutoSize = true;
this.required_Fellowship.Location = new System.Drawing.Point(19, 222);
this.required_Fellowship.Name = "required_Fellowship";
this.required_Fellowship.Size = new System.Drawing.Size(56, 13);
this.required_Fellowship.TabIndex = 6;
this.required_Fellowship.Text = "Fellowship";
//
// required_Willpower
//
this.required_Willpower.AutoSize = true;
this.required_Willpower.Location = new System.Drawing.Point(19, 194);
this.required_Willpower.Name = "required_Willpower";
this.required_Willpower.Size = new System.Drawing.Size(56, 13);
this.required_Willpower.TabIndex = 5;
this.required_Willpower.Text = "Will power";
//
// required_Perception
//
this.required_Perception.AutoSize = true;
this.required_Perception.Location = new System.Drawing.Point(19, 161);
this.required_Perception.Name = "required_Perception";
this.required_Perception.Size = new System.Drawing.Size(58, 13);
this.required_Perception.TabIndex = 4;
this.required_Perception.Text = "Perception";
//
// required_Intelligence
//
this.required_Intelligence.AutoSize = true;
this.required_Intelligence.Location = new System.Drawing.Point(22, 127);
this.required_Intelligence.Name = "required_Intelligence";
this.required_Intelligence.Size = new System.Drawing.Size(61, 13);
this.required_Intelligence.TabIndex = 3;
this.required_Intelligence.Text = "Intelligence";
//
// required_Agility
//
this.required_Agility.AutoSize = true;
this.required_Agility.Location = new System.Drawing.Point(19, 95);
this.required_Agility.Name = "required_Agility";
this.required_Agility.Size = new System.Drawing.Size(34, 13);
this.required_Agility.TabIndex = 2;
this.required_Agility.Text = "Agility";
//
// required_Toughness
//
this.required_Toughness.AutoSize = true;
this.required_Toughness.Location = new System.Drawing.Point(22, 68);
this.required_Toughness.Name = "required_Toughness";
this.required_Toughness.Size = new System.Drawing.Size(60, 13);
this.required_Toughness.TabIndex = 1;
this.required_Toughness.Text = "Toughness";
//
// required_Strength
//
this.required_Strength.AutoSize = true;
this.required_Strength.Location = new System.Drawing.Point(22, 33);
this.required_Strength.Name = "required_Strength";
this.required_Strength.Size = new System.Drawing.Size(47, 13);
this.required_Strength.TabIndex = 0;
this.required_Strength.Text = "Strength";
//
// cb_Talents
//
this.cb_Talents.FormattingEnabled = true;
this.cb_Talents.Location = new System.Drawing.Point(52, 130);
this.cb_Talents.Name = "cb_Talents";
this.cb_Talents.Size = new System.Drawing.Size(121, 21);
this.cb_Talents.TabIndex = 5;
this.cb_Talents.SelectedIndexChanged += new System.EventHandler(this.cb_Talents_SelectedIndexChanged);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(49, 114);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(35, 13);
this.label1.TabIndex = 6;
this.label1.Text = "Name";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(436, 173);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(78, 13);
this.label2.TabIndex = 7;
this.label2.Text = "Class Required";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(436, 271);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(72, 13);
this.label3.TabIndex = 8;
this.label3.Text = "Skill Required";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(436, 364);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(83, 13);
this.label4.TabIndex = 9;
this.label4.Text = "Talent Required";
//
// TextDescription
//
this.TextDescription.Location = new System.Drawing.Point(607, 133);
this.TextDescription.Multiline = true;
this.TextDescription.Name = "TextDescription";
this.TextDescription.ReadOnly = true;
this.TextDescription.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.TextDescription.Size = new System.Drawing.Size(221, 377);
this.TextDescription.TabIndex = 10;
//
// TextClass
//
this.TextClass.Location = new System.Drawing.Point(439, 189);
this.TextClass.Name = "TextClass";
this.TextClass.ReadOnly = true;
this.TextClass.Size = new System.Drawing.Size(100, 20);
this.TextClass.TabIndex = 11;
//
// TextSkill
//
this.TextSkill.Location = new System.Drawing.Point(439, 288);
this.TextSkill.Name = "TextSkill";
this.TextSkill.ReadOnly = true;
this.TextSkill.Size = new System.Drawing.Size(100, 20);
this.TextSkill.TabIndex = 12;
//
// TextTalent
//
this.TextTalent.Location = new System.Drawing.Point(439, 381);
this.TextTalent.Name = "TextTalent";
this.TextTalent.ReadOnly = true;
this.TextTalent.Size = new System.Drawing.Size(100, 20);
this.TextTalent.TabIndex = 13;
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(607, 114);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(60, 13);
this.label5.TabIndex = 14;
this.label5.Text = "Description";
//
// button1
//
this.button1.Image = ((System.Drawing.Image)(resources.GetObject("button1.Image")));
this.button1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.button1.Location = new System.Drawing.Point(439, 524);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(54, 23);
this.button1.TabIndex = 15;
this.button1.Text = "Add";
this.button1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
this.button1.UseVisualStyleBackColor = true;
//
// Talents
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(881, 590);
this.Controls.Add(this.button1);
this.Controls.Add(this.label5);
this.Controls.Add(this.TextTalent);
this.Controls.Add(this.TextSkill);
this.Controls.Add(this.TextClass);
this.Controls.Add(this.TextDescription);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.cb_Talents);
this.Controls.Add(this.grp_Attributes);
this.Name = "Talents";
this.Text = "Talents";
this.Load += new System.EventHandler(this.Talents_Load);
this.grp_Attributes.ResumeLayout(false);
this.grp_Attributes.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.GroupBox grp_Attributes;
private System.Windows.Forms.TextBox TextBallisticskill;
private System.Windows.Forms.TextBox TextWeaponskill;
private System.Windows.Forms.TextBox TextFellowship;
private System.Windows.Forms.TextBox TextWillpower;
private System.Windows.Forms.TextBox TextPerception;
private System.Windows.Forms.TextBox TextIntelligence;
private System.Windows.Forms.TextBox TextAgility;
private System.Windows.Forms.TextBox TextToughness;
private System.Windows.Forms.TextBox TextStrengh;
private System.Windows.Forms.Label required_Ballisticskill;
private System.Windows.Forms.Label required_Weaponskill;
private System.Windows.Forms.Label required_Fellowship;
private System.Windows.Forms.Label required_Willpower;
private System.Windows.Forms.Label required_Perception;
private System.Windows.Forms.Label required_Intelligence;
private System.Windows.Forms.Label required_Agility;
private System.Windows.Forms.Label required_Toughness;
private System.Windows.Forms.Label required_Strength;
private System.Windows.Forms.ComboBox cb_Talents;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox TextDescription;
private System.Windows.Forms.TextBox TextClass;
private System.Windows.Forms.TextBox TextSkill;
private System.Windows.Forms.TextBox TextTalent;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Button button1;
}
}

Related

can i register for neobux from my windows form application

i tired this namespace Adds
i don't know how to connect my project with neobux server.
{
partial class Register
{
/// <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.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.checkBox2 = new System.Windows.Forms.CheckBox();
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.textBox4 = new System.Windows.Forms.TextBox();
this.textBox5 = new System.Windows.Forms.TextBox();
this.textBox6 = new System.Windows.Forms.TextBox();
this.textBox7 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(33, 62);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(61, 13);
this.label1.TabIndex = 0;
this.label1.Text = "Username :";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(33, 125);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(59, 13);
this.label2.TabIndex = 1;
this.label2.Text = "Password :";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(33, 146);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(120, 13);
this.label3.TabIndex = 2;
this.label3.Text = "Password Confirmation :";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(33, 192);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(38, 13);
this.label4.TabIndex = 3;
this.label4.Text = "Email :";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(33, 245);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(51, 13);
this.label5.TabIndex = 4;
this.label5.Text = "Raferrer :";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(33, 285);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(59, 13);
this.label6.TabIndex = 5;
this.label6.Text = "Birth Year :";
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(33, 340);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(93, 13);
this.label7.TabIndex = 6;
this.label7.Text = "Verification Code :";
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(33, 390);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(395, 30);
this.checkBox1.TabIndex = 7;
this.checkBox1.Text = "I declare to have read, understood, and accecpted the Terms of Services And\r\nPriv" +
"acy Policy.";
this.checkBox1.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
this.checkBox1.UseVisualStyleBackColor = true;
//
// checkBox2
//
this.checkBox2.AutoSize = true;
this.checkBox2.Location = new System.Drawing.Point(33, 444);
this.checkBox2.Name = "checkBox2";
this.checkBox2.Size = new System.Drawing.Size(291, 17);
this.checkBox2.TabIndex = 8;
this.checkBox2.Text = "I give my consent to the processing of my personal data.";
this.checkBox2.UseVisualStyleBackColor = true;
//
// button1
//
this.button1.Location = new System.Drawing.Point(378, 490);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 9;
this.button1.Text = "continue";
this.button1.UseVisualStyleBackColor = true;
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(100, 59);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(353, 20);
this.textBox1.TabIndex = 10;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(99, 120);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(354, 20);
this.textBox2.TabIndex = 11;
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(160, 145);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(293, 20);
this.textBox3.TabIndex = 12;
//
// textBox4
//
this.textBox4.Location = new System.Drawing.Point(78, 187);
this.textBox4.Name = "textBox4";
this.textBox4.Size = new System.Drawing.Size(375, 20);
this.textBox4.TabIndex = 13;
//
// textBox5
//
this.textBox5.Location = new System.Drawing.Point(91, 243);
this.textBox5.Name = "textBox5";
this.textBox5.Size = new System.Drawing.Size(362, 20);
this.textBox5.TabIndex = 14;
//
// textBox6
//
this.textBox6.Location = new System.Drawing.Point(98, 282);
this.textBox6.Name = "textBox6";
this.textBox6.Size = new System.Drawing.Size(355, 20);
this.textBox6.TabIndex = 15;
//
// textBox7
//
this.textBox7.Location = new System.Drawing.Point(133, 338);
this.textBox7.Name = "textBox7";
this.textBox7.Size = new System.Drawing.Size(320, 20);
this.textBox7.TabIndex = 16;
//
// Register
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(498, 536);
this.Controls.Add(this.textBox7);
this.Controls.Add(this.textBox6);
this.Controls.Add(this.textBox5);
this.Controls.Add(this.textBox4);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Controls.Add(this.checkBox2);
this.Controls.Add(this.checkBox1);
this.Controls.Add(this.label7);
this.Controls.Add(this.label6);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "Register";
this.Text = "Register";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.CheckBox checkBox2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.TextBox textBox4;
private System.Windows.Forms.TextBox textBox5;
private System.Windows.Forms.TextBox textBox6;
private System.Windows.Forms.TextBox textBox7;
}
}
i created this application for register for neobux
i don't know how to connect my project with neobux server.

How can I call my windows form elements in my other class in C#

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

SelectIndexChanged not working (C# desktop)

**The autopostback-fix does not work! **
I have a GUI that looks like:
I want to show the details of a cat when it's clicked on.
I used this code for it:
private void listBox_Cats_SelectedIndexChanged(object sender, System.EventArgs e)
{
// Get the currently selected item in the ListBox.
Cat cat = listBox_Cats.SelectedItem as Cat;
if (cat != null)
{
tb_ID.Text = cat.ID.ToString();
tb_Name.Text = cat.Name.ToString();
tb_DateArrived.Text = cat.DateArrived.ToString();
tb_IsAdopted.Text = cat.IsAdopted.ToString();
tb_adoptedBy.Text = cat.AdoptedBy.ToString();
}
}
When running however, nothing seems to work. What am I doing wrong?
EDIT
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using IntegrationTool;
namespace IntegrationTool
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
SqlConnection conn = new SqlConnection("Server=.\\SQLEXPRESS;Database=CatShelter;Integrated Security=true");
conn.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM [dbo].[cats]", conn);
SqlDataReader reader = cmd.ExecuteReader();
List<Cat> cats = new List<Cat>();
while (reader.Read())
{
Cat c = new Cat();
c.ID = (int)reader["CatID"];
c.Name = (string)reader["Name"];
c.DateArrived = (DateTime)reader["DateArrived"];
c.IsAdopted = (string)reader["IsAdopted"];
c.AdoptedBy = (string)reader["AdoptedBy"];
cats.Add(c);
}
foreach (Cat c in cats)
{
Console.WriteLine(c.Name);
}
reader.Close();
conn.Close();
if (Debugger.IsAttached)
{
Console.ReadLine();
}
listBox_Cats.DataSource = cats;
listBox_Cats.DisplayMember = "Name";
listBox_Cats.ValueMember = "ID";
}
private void listBox_Cats_SelectedIndexChanged(object sender, System.EventArgs e)
{
// Get the currently selected item in the ListBox.
Cat cat = listBox_Cats.SelectedItem as Cat;
if (cat != null)
{
Console.WriteLine(cat.Name);
tb_ID.Text = cat.ID.ToString();
tb_Name.Text = cat.Name.ToString();
tb_DateArrived.Text = cat.DateArrived.ToString();
tb_IsAdopted.Text = cat.IsAdopted.ToString();
tb_adoptedBy.Text = cat.AdoptedBy.ToString();
}
}
}
}
namespace IntegrationTool
{
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.listBox_Cats = new System.Windows.Forms.ListBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.button2 = new System.Windows.Forms.Button();
this.cb_VetCheck = new System.Windows.Forms.CheckBox();
this.label5 = new System.Windows.Forms.Label();
this.tb_Comment = new System.Windows.Forms.TextBox();
this.tb_ID = new System.Windows.Forms.TextBox();
this.tb_DateArrived = new System.Windows.Forms.TextBox();
this.tb_IsAdopted = new System.Windows.Forms.TextBox();
this.tb_adoptedBy = new System.Windows.Forms.TextBox();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.label6 = new System.Windows.Forms.Label();
this.tb_Name = new System.Windows.Forms.TextBox();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.SuspendLayout();
//
// listBox_Cats
//
this.listBox_Cats.FormattingEnabled = true;
this.listBox_Cats.Location = new System.Drawing.Point(16, 35);
this.listBox_Cats.Name = "listBox_Cats";
this.listBox_Cats.Size = new System.Drawing.Size(137, 316);
this.listBox_Cats.TabIndex = 0;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.tb_Name);
this.groupBox1.Controls.Add(this.label6);
this.groupBox1.Controls.Add(this.tb_adoptedBy);
this.groupBox1.Controls.Add(this.tb_IsAdopted);
this.groupBox1.Controls.Add(this.tb_DateArrived);
this.groupBox1.Controls.Add(this.tb_ID);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Location = new System.Drawing.Point(252, 31);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(409, 190);
this.groupBox1.TabIndex = 1;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Details";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(6, 35);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(24, 13);
this.label1.TabIndex = 0;
this.label1.Text = "ID: ";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(6, 95);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(69, 13);
this.label2.TabIndex = 1;
this.label2.Text = "Date Arrived:";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(6, 123);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(60, 13);
this.label3.TabIndex = 2;
this.label3.Text = "Is adopted:";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(6, 157);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(65, 13);
this.label4.TabIndex = 3;
this.label4.Text = "Adopted By:";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.tb_Comment);
this.groupBox2.Controls.Add(this.label5);
this.groupBox2.Controls.Add(this.cb_VetCheck);
this.groupBox2.Location = new System.Drawing.Point(252, 243);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(409, 157);
this.groupBox2.TabIndex = 2;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Validate";
//
// button2
//
this.button2.Location = new System.Drawing.Point(553, 424);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(107, 31);
this.button2.TabIndex = 4;
this.button2.Text = "Save";
this.button2.UseVisualStyleBackColor = true;
//
// cb_VetCheck
//
this.cb_VetCheck.AutoSize = true;
this.cb_VetCheck.Location = new System.Drawing.Point(9, 30);
this.cb_VetCheck.Name = "cb_VetCheck";
this.cb_VetCheck.Size = new System.Drawing.Size(76, 17);
this.cb_VetCheck.TabIndex = 0;
this.cb_VetCheck.Text = "Vet Check";
this.cb_VetCheck.UseVisualStyleBackColor = true;
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(6, 75);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(51, 13);
this.label5.TabIndex = 1;
this.label5.Text = "Comment";
//
// tb_Comment
//
this.tb_Comment.Location = new System.Drawing.Point(9, 91);
this.tb_Comment.Name = "tb_Comment";
this.tb_Comment.Size = new System.Drawing.Size(288, 20);
this.tb_Comment.TabIndex = 2;
//
// tb_ID
//
this.tb_ID.Location = new System.Drawing.Point(81, 35);
this.tb_ID.Name = "tb_ID";
this.tb_ID.ReadOnly = true;
this.tb_ID.Size = new System.Drawing.Size(66, 20);
this.tb_ID.TabIndex = 4;
//
// tb_DateArrived
//
this.tb_DateArrived.Location = new System.Drawing.Point(81, 92);
this.tb_DateArrived.Name = "tb_DateArrived";
this.tb_DateArrived.ReadOnly = true;
this.tb_DateArrived.Size = new System.Drawing.Size(66, 20);
this.tb_DateArrived.TabIndex = 5;
//
// tb_IsAdopted
//
this.tb_IsAdopted.Location = new System.Drawing.Point(81, 120);
this.tb_IsAdopted.Name = "tb_IsAdopted";
this.tb_IsAdopted.ReadOnly = true;
this.tb_IsAdopted.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
this.tb_IsAdopted.Size = new System.Drawing.Size(66, 20);
this.tb_IsAdopted.TabIndex = 6;
//
// tb_adoptedBy
//
this.tb_adoptedBy.Location = new System.Drawing.Point(81, 154);
this.tb_adoptedBy.Name = "tb_adoptedBy";
this.tb_adoptedBy.ReadOnly = true;
this.tb_adoptedBy.Size = new System.Drawing.Size(66, 20);
this.tb_adoptedBy.TabIndex = 7;
//
// groupBox3
//
this.groupBox3.Controls.Add(this.listBox_Cats);
this.groupBox3.Location = new System.Drawing.Point(12, 31);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(175, 369);
this.groupBox3.TabIndex = 5;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Cats";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(7, 61);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(41, 13);
this.label6.TabIndex = 8;
this.label6.Text = "Name: ";
//
// tb_Name
//
this.tb_Name.Location = new System.Drawing.Point(81, 61);
this.tb_Name.Name = "tb_Name";
this.tb_Name.ReadOnly = true;
this.tb_Name.Size = new System.Drawing.Size(66, 20);
this.tb_Name.TabIndex = 9;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(721, 480);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.button2);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Name = "Form1";
this.Text = "Form1";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.groupBox3.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ListBox listBox_Cats;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox tb_adoptedBy;
private System.Windows.Forms.TextBox tb_IsAdopted;
private System.Windows.Forms.TextBox tb_DateArrived;
private System.Windows.Forms.TextBox tb_ID;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.TextBox tb_Comment;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.CheckBox cb_VetCheck;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.TextBox tb_Name;
private System.Windows.Forms.Label label6;
}
}
Your listBox_Cats_SelectedIndexChanged is not bound to the SelectedIndexChanged event of the listBox.
There should be entry in your designer file that looks like:
this.listBox_Cats.SelectedIndexChanged += new System.EventHandler(this.listBox_Cats_SelectedIndexChanged);
You can add it manually if it isn't already there - in InitializeComponent.
Your listbox(listBox_Cats) has Cat as a Complex type so try to get the selected item by below code and see it works.
Cat value = (Cat) this.listBox_Cats.SelectedItem;

c# chart axis not displaying when form is loaded

For some reason the axis and grid is not being displayed on the c# chart. as you can see from the two pictures, the background of the chart is being displayed, but nothing else is. Can anyone help me figure out why the grid and information from the chart is not being displayed?
The form from designer in visual studio:
The form at runtime:
namespace Harman.Generic.Framework.WaveformMaker
{
partial class WaveformMaker
{
/// <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.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.mnuStrip = new System.Windows.Forms.MenuStrip();
this.mnuFile = new System.Windows.Forms.ToolStripMenuItem();
this.mnuFileSaveWaveform = new System.Windows.Forms.ToolStripMenuItem();
this.mnuFileExit = new System.Windows.Forms.ToolStripMenuItem();
this.btnRun = new System.Windows.Forms.Button();
this.lblPointVoltage = new System.Windows.Forms.Label();
this.lblPointDuration = new System.Windows.Forms.Label();
this.dgdPointList = new System.Windows.Forms.DataGridView();
this.colPoint = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colVoltage = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colDuration = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.btnRemovePoint = new System.Windows.Forms.Button();
this.btnAddPoint = new System.Windows.Forms.Button();
this.chWaveform = new System.Windows.Forms.DataVisualization.Charting.Chart();
this.mnuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dgdPointList)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.chWaveform)).BeginInit();
this.SuspendLayout();
//
// contextMenuStrip1
//
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(61, 4);
//
// mnuStrip
//
this.mnuStrip.BackColor = System.Drawing.SystemColors.Control;
this.mnuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuFile});
this.mnuStrip.Location = new System.Drawing.Point(0, 0);
this.mnuStrip.Name = "mnuStrip";
this.mnuStrip.Size = new System.Drawing.Size(894, 24);
this.mnuStrip.TabIndex = 2;
this.mnuStrip.Text = "menuStrip1";
//
// mnuFile
//
this.mnuFile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.mnuFileSaveWaveform,
this.mnuFileExit});
this.mnuFile.Name = "mnuFile";
this.mnuFile.Size = new System.Drawing.Size(37, 20);
this.mnuFile.Text = "File";
//
// mnuFileSaveWaveform
//
this.mnuFileSaveWaveform.Name = "mnuFileSaveWaveform";
this.mnuFileSaveWaveform.Size = new System.Drawing.Size(156, 22);
this.mnuFileSaveWaveform.Text = "Save Waveform";
//
// mnuFileExit
//
this.mnuFileExit.Name = "mnuFileExit";
this.mnuFileExit.Size = new System.Drawing.Size(156, 22);
this.mnuFileExit.Text = "Exit";
//
// btnRun
//
this.btnRun.Location = new System.Drawing.Point(621, 562);
this.btnRun.Name = "btnRun";
this.btnRun.Size = new System.Drawing.Size(83, 23);
this.btnRun.TabIndex = 4;
this.btnRun.Text = "Run";
this.btnRun.UseVisualStyleBackColor = true;
//
// lblPointVoltage
//
this.lblPointVoltage.AutoSize = true;
this.lblPointVoltage.Location = new System.Drawing.Point(10, 572);
this.lblPointVoltage.Name = "lblPointVoltage";
this.lblPointVoltage.Size = new System.Drawing.Size(49, 13);
this.lblPointVoltage.TabIndex = 6;
this.lblPointVoltage.Text = "Voltage: ";
//
// lblPointDuration
//
this.lblPointDuration.AutoSize = true;
this.lblPointDuration.Location = new System.Drawing.Point(65, 572);
this.lblPointDuration.Name = "lblPointDuration";
this.lblPointDuration.Size = new System.Drawing.Size(58, 13);
this.lblPointDuration.TabIndex = 7;
this.lblPointDuration.Text = "Time (ms): ";
//
// dgdPointList
//
this.dgdPointList.AllowUserToAddRows = false;
this.dgdPointList.AllowUserToResizeColumns = false;
this.dgdPointList.AllowUserToResizeRows = false;
this.dgdPointList.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgdPointList.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.colPoint,
this.colVoltage,
this.colDuration});
this.dgdPointList.Location = new System.Drawing.Point(710, 28);
this.dgdPointList.MultiSelect = false;
this.dgdPointList.Name = "dgdPointList";
this.dgdPointList.RowHeadersVisible = false;
this.dgdPointList.ScrollBars = System.Windows.Forms.ScrollBars.None;
this.dgdPointList.Size = new System.Drawing.Size(172, 528);
this.dgdPointList.TabIndex = 8;
//
// colPoint
//
this.colPoint.HeaderText = "Point";
this.colPoint.Name = "colPoint";
this.colPoint.Resizable = System.Windows.Forms.DataGridViewTriState.False;
this.colPoint.Width = 56;
//
// colVoltage
//
this.colVoltage.HeaderText = "Voltage";
this.colVoltage.Name = "colVoltage";
this.colVoltage.Resizable = System.Windows.Forms.DataGridViewTriState.False;
this.colVoltage.Width = 56;
//
// colDuration
//
this.colDuration.HeaderText = "Duration";
this.colDuration.Name = "colDuration";
this.colDuration.Resizable = System.Windows.Forms.DataGridViewTriState.False;
this.colDuration.Width = 56;
//
// btnRemovePoint
//
this.btnRemovePoint.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
this.btnRemovePoint.Location = new System.Drawing.Point(799, 562);
this.btnRemovePoint.Name = "btnRemovePoint";
this.btnRemovePoint.Size = new System.Drawing.Size(83, 23);
this.btnRemovePoint.TabIndex = 9;
this.btnRemovePoint.Text = "Remove Point";
this.btnRemovePoint.UseVisualStyleBackColor = true;
//
// btnAddPoint
//
this.btnAddPoint.Location = new System.Drawing.Point(710, 562);
this.btnAddPoint.Name = "btnAddPoint";
this.btnAddPoint.Size = new System.Drawing.Size(83, 23);
this.btnAddPoint.TabIndex = 10;
this.btnAddPoint.Text = "Add Point";
this.btnAddPoint.UseVisualStyleBackColor = true;
this.btnAddPoint.Click += new System.EventHandler(this.btnAddPoint_Click);
//
// chWaveform
//
this.chWaveform.BackColor = System.Drawing.SystemColors.Control;
this.chWaveform.BorderlineColor = System.Drawing.SystemColors.WindowText;
chartArea1.Area3DStyle.LightStyle = System.Windows.Forms.DataVisualization.Charting.LightStyle.Realistic;
chartArea1.AxisX.MajorGrid.Interval = 1000D;
chartArea1.AxisX.MajorGrid.LineColor = System.Drawing.Color.LightGray;
chartArea1.AxisX.MajorTickMark.Interval = 1000D;
chartArea1.AxisX.Maximum = 5000D;
chartArea1.AxisX.Minimum = 0D;
chartArea1.AxisX.MinorGrid.Enabled = true;
chartArea1.AxisX.MinorGrid.Interval = 100D;
chartArea1.AxisX.MinorGrid.LineColor = System.Drawing.Color.WhiteSmoke;
chartArea1.AxisX.Title = "Time (seconds)";
chartArea1.AxisX2.IsStartedFromZero = false;
chartArea1.AxisY.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.VariableCount;
chartArea1.AxisY.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
chartArea1.AxisY.MajorGrid.LineColor = System.Drawing.Color.LightGray;
chartArea1.AxisY.MajorTickMark.Interval = 1D;
chartArea1.AxisY.MajorTickMark.IntervalOffset = 0D;
chartArea1.AxisY.MajorTickMark.IntervalOffsetType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Auto;
chartArea1.AxisY.MajorTickMark.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Number;
chartArea1.AxisY.MajorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.AcrossAxis;
chartArea1.AxisY.Maximum = 16D;
chartArea1.AxisY.Minimum = 0D;
chartArea1.AxisY.MinorGrid.Enabled = true;
chartArea1.AxisY.MinorGrid.Interval = 0.25D;
chartArea1.AxisY.MinorGrid.LineColor = System.Drawing.Color.WhiteSmoke;
chartArea1.AxisY.MinorTickMark.Enabled = true;
chartArea1.AxisY.MinorTickMark.Interval = 0.25D;
chartArea1.AxisY.MinorTickMark.Size = 0.25F;
chartArea1.AxisY.MinorTickMark.TickMarkStyle = System.Windows.Forms.DataVisualization.Charting.TickMarkStyle.AcrossAxis;
chartArea1.AxisY.Title = "Voltage";
chartArea1.Name = "ChartArea1";
this.chWaveform.ChartAreas.Add(chartArea1);
legend1.Enabled = false;
legend1.Name = "Legend1";
this.chWaveform.Legends.Add(legend1);
this.chWaveform.Location = new System.Drawing.Point(13, 28);
this.chWaveform.Name = "chWaveform";
this.chWaveform.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.Excel;
series1.ChartArea = "ChartArea1";
series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StepLine;
series1.Legend = "Legend1";
series1.Name = "Series1";
this.chWaveform.Series.Add(series1);
this.chWaveform.Size = new System.Drawing.Size(691, 528);
this.chWaveform.TabIndex = 5;
this.chWaveform.Click += new System.EventHandler(this.chWaveform_Click);
//
// WaveformMaker
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(894, 594);
this.Controls.Add(this.btnAddPoint);
this.Controls.Add(this.btnRemovePoint);
this.Controls.Add(this.dgdPointList);
this.Controls.Add(this.lblPointDuration);
this.Controls.Add(this.lblPointVoltage);
this.Controls.Add(this.chWaveform);
this.Controls.Add(this.btnRun);
this.Controls.Add(this.mnuStrip);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Name = "WaveformMaker";
this.Text = "Waveform Maker";
this.Load += new System.EventHandler(this.WaveformMaker_Load);
this.mnuStrip.ResumeLayout(false);
this.mnuStrip.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dgdPointList)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.chWaveform)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
private System.Windows.Forms.MenuStrip mnuStrip;
private System.Windows.Forms.ToolStripMenuItem mnuFile;
private System.Windows.Forms.ToolStripMenuItem mnuFileSaveWaveform;
private System.Windows.Forms.ToolStripMenuItem mnuFileExit;
private System.Windows.Forms.Button btnRun;
private System.Windows.Forms.Label lblPointVoltage;
private System.Windows.Forms.Label lblPointDuration;
private System.Windows.Forms.DataGridView dgdPointList;
private System.Windows.Forms.DataGridViewTextBoxColumn colPoint;
private System.Windows.Forms.DataGridViewTextBoxColumn colVoltage;
private System.Windows.Forms.DataGridViewTextBoxColumn colDuration;
private System.Windows.Forms.Button btnRemovePoint;
private System.Windows.Forms.Button btnAddPoint;
private System.Windows.Forms.DataVisualization.Charting.Chart chWaveform;
}
}
Your code works fine but you need to add a DataPoint to trigger the Chart's display.
This is most likely because without any data the automatic settings, which are default for most elements, including ChartArea's Size, have nothing to work from. I tried it and after adding even a dummy point the grid and all other nice details will show just fine..:
As you can see clearing the DataPoints will wipe out the chart again..
If you want your Series clean of dummy data you can either delete the dummy after adding the first data or add a dummy series..

c# Form with custom design code doesn't show up

I am currently working on a project that allows the user to design his own WinForm (using DesignSurface). Therefore I wrote an algrotithm to create Designer-Code for the form. Everything works fine, except for one thing: The form, once compiled, won't show up. Everything should be working; I could not figure out what the problem was. Anyways, here's the code:
public partial class mainForm : Form
{
public mainForm()
{
InitializeComponent();
}
private System.Windows.Forms.CheckBox checkBox3;
private System.Windows.Forms.CheckBox checkBox2;
private System.Windows.Forms.CheckBox checkBox1;
private CustomButton button1;
private CustomTextBox textBox3;
private System.Windows.Forms.Label label3;
private CustomTextBox textBox2;
private System.Windows.Forms.Label label2;
private CustomTextBox textBox1;
private System.Windows.Forms.Label label1;
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.checkBox3 = new System.Windows.Forms.CheckBox();
this.checkBox2 = new System.Windows.Forms.CheckBox();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.button1 = new CustomButton();
this.textBox3 = new CustomTextBox();
this.label3 = new System.Windows.Forms.Label();
this.textBox2 = new CustomTextBox();
this.label2 = new System.Windows.Forms.Label();
this.textBox1 = new CustomTextBox();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
//checkBox3
//
this.checkBox3.AutoCheck = false;
this.checkBox3.AutoSize = true;
this.checkBox3.BackColor = System.Drawing.Color.FromArgb(-986896);
this.checkBox3.Text = #"";
this.checkBox3.ForeColor = System.Drawing.Color.FromName("Black");
this.checkBox3.Location = new System.Drawing.Point(187, 151);
this.checkBox3.Name = #"checkBox3";
this.checkBox3.Size = new System.Drawing.Size(87, 17);
this.checkBox3.TabIndex = 9;
this.checkBox3.Tag = #"XC";
//
//checkBox2
//
this.checkBox2.AutoCheck = false;
this.checkBox2.AutoSize = true;
this.checkBox2.BackColor = System.Drawing.Color.FromArgb(-986896);
this.checkBox2.Text = #"";
this.checkBox2.ForeColor = System.Drawing.Color.FromName("Black");
this.checkBox2.Location = new System.Drawing.Point(101, 151);
this.checkBox2.Name = #"checkBox2";
this.checkBox2.Size = new System.Drawing.Size(60, 17);
this.checkBox2.TabIndex = 8;
this.checkBox2.Tag = #"XC";
//
//checkBox1
//
this.checkBox1.AutoCheck = false;
this.checkBox1.AutoSize = true;
this.checkBox1.BackColor = System.Drawing.Color.FromArgb(-986896);
this.checkBox1.Text = #"";
this.checkBox1.ForeColor = System.Drawing.Color.FromName("Black");
this.checkBox1.Location = new System.Drawing.Point(15, 151);
this.checkBox1.Name = #"checkBox1";
this.checkBox1.Size = new System.Drawing.Size(70, 17);
this.checkBox1.TabIndex = 7;
this.checkBox1.Tag = #"XC";
//
//button1
//
this.button1.BackColor = System.Drawing.Color.FromArgb(-986896);
this.button1.Text = #"";
this.button1.UseVisualStyleBackColor = false;
this.button1.ForeColor = System.Drawing.Color.FromName("Black");
this.button1.Location = new System.Drawing.Point(12, 187);
this.button1.Name = #"button1";
this.button1.Size = new System.Drawing.Size(309, 38);
this.button1.TabIndex = 6;
this.button1.Tag = #"XC";
//
//textBox3
//
this.textBox3.UseForCustoming = true;
this.textBox3.CustomingName = #"";
this.textBox3.BackColor = System.Drawing.Color.FromName("White");
this.textBox3.ForeColor = System.Drawing.Color.FromName("Black");
this.textBox3.Location = new System.Drawing.Point(15, 116);
this.textBox3.Name = #"textBox3";
this.textBox3.Size = new System.Drawing.Size(306, 20);
this.textBox3.TabIndex = 5;
this.textBox3.Tag = #"XC";
//
//label3
//
this.label3.AutoSize = true;
this.label3.Text = #"";
this.label3.BackColor = System.Drawing.Color.FromArgb(-986896);
this.label3.ForeColor = System.Drawing.Color.FromName("Black");
this.label3.Location = new System.Drawing.Point(12, 100);
this.label3.Name = #"label3";
this.label3.Size = new System.Drawing.Size(100, 13);
this.label3.TabIndex = 4;
this.label3.Tag = #"XC";
//
//textBox2
//
this.textBox2.UseForCustoming = true;
this.textBox2.CustomingName = #"";
this.textBox2.BackColor = System.Drawing.Color.FromName("White");
this.textBox2.ForeColor = System.Drawing.Color.FromName("Black");
this.textBox2.Location = new System.Drawing.Point(15, 71);
this.textBox2.Name = #"textBox2";
this.textBox2.Size = new System.Drawing.Size(306, 20);
this.textBox2.TabIndex = 3;
this.textBox2.Tag = #"XC";
//
//label2
//
this.label2.AutoSize = true;
this.label2.Text = #"";
this.label2.BackColor = System.Drawing.Color.FromArgb(-986896);
this.label2.ForeColor = System.Drawing.Color.FromName("Black");
this.label2.Location = new System.Drawing.Point(12, 55);
this.label2.Name = #"label2";
this.label2.Size = new System.Drawing.Size(82, 13);
this.label2.TabIndex = 2;
this.label2.Tag = #"XC";
//
//textBox1
//
this.textBox1.UseForCustoming = true;
this.textBox1.CustomingName = #"";
this.textBox1.BackColor = System.Drawing.Color.FromName("White");
this.textBox1.ForeColor = System.Drawing.Color.FromName("Black");
this.textBox1.Location = new System.Drawing.Point(15, 25);
this.textBox1.Name = #"textBox1";
this.textBox1.Size = new System.Drawing.Size(306, 20);
this.textBox1.TabIndex = 1;
this.textBox1.Tag = #"XC";
//
//label1
//
this.label1.AutoSize = true;
this.label1.Text = #"";
this.label1.BackColor = System.Drawing.Color.FromArgb(-986896);
this.label1.ForeColor = System.Drawing.Color.FromName("Black");
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = #"label1";
this.label1.Size = new System.Drawing.Size(51, 13);
this.label1.Tag = #"XC";
//
//mainForm
//
this.AutoScaleDimensions = new SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(455, 275);
this.BackColor = System.Drawing.Color.FromArgb(-986896);
this.MaximizeBox = false;
this.ShowIcon = false;
this.Size = new System.Drawing.Size(349, 276);
this.Text = #"";
this.TopLevel = false;
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AllowDrop = true;
this.ForeColor = System.Drawing.Color.FromName("Black");
this.Name = #"opForm";
this.Tag = #"";
this.Controls.Add(checkBox3);
this.Controls.Add(checkBox2);
this.Controls.Add(checkBox1);
this.Controls.Add(button1);
this.Controls.Add(textBox3);
this.Controls.Add(label3);
this.Controls.Add(textBox2);
this.Controls.Add(label2);
this.Controls.Add(textBox1);
this.Controls.Add(label1);
this.ResumeLayout(false);
this.PerformLayout();
}
}
And here's the code that creates the form:
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new mainForm());
}
}
I don't get what's wrong with this code. Maybe someone can help me out here.
Chester
For one thing I think the values for ClientSize and Size are clashing. Actually I believe only one should be set and the last one to be set will win.
But the one line that prevents the window from showing up is this:
this.TopLevel = false;
Leave it out or set it to true (the default) and your window will show just fine..
From MSDN:
A top-level form is a window that has no parent form, or whose parent
form is the desktop window. Top-level windows are typically used as
the main form in an application.
So if DesignSurface has set it to false you probably have told it that you are creating something else than a main form.. I believe MDI child windows have it set to false, but I'm not sure, MDI is soo long away..

Categories

Resources