TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Shesh Mishra
NA
22
31.9k
Windows Form Does not working Sequentially?Please Suggest
Oct 23 2012 11:52 PM
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
namespace Insert_form
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void OnKeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Enter:
SendKeys.Send("{TAB}");
// SelectNext(this);
break;
default:
base.OnKeyDown(e);
break;
}
}
private void OnKeyDown1(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Enter:
SendKeys.Send("{TAB}");
// SelectNext(this);
break;
default:
base.OnKeyDown1(e);
break;
}
}
private void OnKeyDown2(object sender, KeyEventArgs e)
{
bool invalidInput = false;
string pid = txtPID.Text.ToString().Trim();
string pnm = txtPName.Text.ToString().Trim();
string prt = txtPprice.Text.ToString().Trim();
if (pid.Length == 0 || pnm.Length == 0 || prt.Length == 0)
invalidInput = true;
if (invalidInput)
MessageBox.Show("You have Input Errors, Please click Reset to Cancel Updates", "Or Search", MessageBoxButtons.OK);
else
MessageBox.Show("Click Submit to save");
}
private void Button1_Click(object sender, EventArgs e)
{
String connetionString = null;
SqlConnection connection;
SqlDataAdapter adapter = new SqlDataAdapter();
String sql = null;
connetionString = @"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=LMS;Data Source=SHESH-PC\SHESH";
connection = new SqlConnection(connetionString);
sql = "insert into Product1 (Product_id,Product_name,Product_price) values(" + txtPID.Text.ToString() + ",'" + txtPName.Text + "'," + txtPprice.Text.ToString() + ")";
try
{
connection.Open();
adapter.InsertCommand = new SqlCommand(sql, connection);
adapter.InsertCommand.ExecuteNonQuery();
MessageBox.Show("Row inserted !! ");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void btnSearch_Click(object sender, EventArgs e)
{
new Form2().Show();
}
private void btnCancel_Click(object sender, EventArgs e)
{
foreach (Control cont in this.Controls)
{
if (cont is TextBox)
{
((TextBox)cont).Text = string.Empty;
}
}
}
}
}
Form1.Designer.cs
namespace Insert_form
{
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.Button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.btnSearch = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.panel1 = new System.Windows.Forms.Panel();
this.txtPprice = new System.Windows.Forms.TextBox();
this.txtPName = new System.Windows.Forms.TextBox();
this.txtPID = new System.Windows.Forms.TextBox();
this.panel2 = new System.Windows.Forms.Panel();
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
this.SuspendLayout();
//
// Button1
//
this.Button1.Location = new System.Drawing.Point(117, 0);
this.Button1.Name = "Button1";
this.Button1.Size = new System.Drawing.Size(75, 23);
this.Button1.TabIndex = 0;
this.Button1.Text = "Submit";
this.Button1.UseVisualStyleBackColor = true;
this.Button1.Click += new System.EventHandler(this.Button1_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(3, 3);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(68, 11);
this.label1.TabIndex = 1;
this.label1.Text = "Prouct ID";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(-2, 57);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(89, 11);
this.label2.TabIndex = 2;
this.label2.Text = "Product Name";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(-2, 115);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(96, 11);
this.label3.TabIndex = 3;
this.label3.Text = "Product Price";
//
// btnSearch
//
this.btnSearch.Location = new System.Drawing.Point(0, 0);
this.btnSearch.Name = "btnSearch";
this.btnSearch.Size = new System.Drawing.Size(75, 23);
this.btnSearch.TabIndex = 4;
this.btnSearch.Text = "Search";
this.btnSearch.UseVisualStyleBackColor = true;
this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
//
// btnCancel
//
this.btnCancel.Location = new System.Drawing.Point(237, 0);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 23);
this.btnCancel.TabIndex = 5;
this.btnCancel.Text = "Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// panel1
//
this.panel1.BackColor = System.Drawing.SystemColors.ControlDark;
this.panel1.Controls.Add(this.txtPprice);
this.panel1.Controls.Add(this.txtPName);
this.panel1.Controls.Add(this.txtPID);
this.panel1.Controls.Add(this.label1);
this.panel1.Controls.Add(this.label2);
this.panel1.Controls.Add(this.label3);
this.panel1.Location = new System.Drawing.Point(121, 38);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(312, 168);
this.panel1.TabIndex = 6;
//
// txtPprice
//
this.txtPprice.Location = new System.Drawing.Point(136, 108);
this.txtPprice.Name = "txtPprice";
this.txtPprice.Size = new System.Drawing.Size(100, 18);
this.txtPprice.TabIndex = 6;
this.txtPprice.KeyDown += new System.Windows.Forms.KeyEventHandler(this.OnKeyDown2);
//
// txtPName
//
this.txtPName.Location = new System.Drawing.Point(136, 54);
this.txtPName.Name = "txtPName";
this.txtPName.Size = new System.Drawing.Size(100, 18);
this.txtPName.TabIndex = 5;
this.txtPName.KeyDown += new System.Windows.Forms.KeyEventHandler(this.OnKeyDown1);
//
// txtPID
//
this.txtPID.Location = new System.Drawing.Point(136, 0);
this.txtPID.Name = "txtPID";
this.txtPID.Size = new System.Drawing.Size(100, 18);
this.txtPID.TabIndex = 4;
this.txtPID.KeyDown += new System.Windows.Forms.KeyEventHandler(this.OnKeyDown);
//
// panel2
//
this.panel2.Controls.Add(this.btnSearch);
this.panel2.Controls.Add(this.Button1);
this.panel2.Controls.Add(this.btnCancel);
this.panel2.Location = new System.Drawing.Point(121, 229);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(312, 22);
this.panel2.TabIndex = 7;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 11F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
this.ClientSize = new System.Drawing.Size(597, 350);
this.Controls.Add(this.panel2);
this.Controls.Add(this.panel1);
this.Font = new System.Drawing.Font("Lucida Console", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.Name = "Form1";
this.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.Text = "Prouct Master";
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.panel2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button Button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button btnSearch;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.TextBox txtPprice;
private System.Windows.Forms.TextBox txtPName;
private System.Windows.Forms.TextBox txtPID;
private System.Windows.Forms.Panel panel2;
}
}
}
}
Reply
Answers (
0
)
Whic code is more correct?
how to switch between photos in windows forms using time interval?