Presentation is loading. Please wait.

Presentation is loading. Please wait.

WINDOWS COMMON CONTROLS DEFAULT EVENT HANDLERS.

Similar presentations


Presentation on theme: "WINDOWS COMMON CONTROLS DEFAULT EVENT HANDLERS."— Presentation transcript:

1

2

3

4 WINDOWS COMMON CONTROLS DEFAULT EVENT HANDLERS

5 HOW TO ADD THE DATA’S TO CONTROL
SLNO CONTROLS HOW TO ADD THE DATA’S TO CONTROL DEFAULT EVENT HANDLER 1. Form Form1.Text = “Chettinad”; private void Form1_Load(object sender, EventArgs e){ } 2. Button Button1.Text=”Click Here”; private void button1_Click(object sender, EventArgs e) { } Label Label.Text=”Enter the A Value”; private void label1_Click(object sender, EventArgs e) { } 3. Textbox Textbox1.Text=”Insert the Text Here”; private void textBox1_TextChanged(object sender, EventArgs e) { } 4. Checkbox Checkbox1.Text=”Addition”; private void checkBox1_CheckedChanged(object sender, EventArgs e) { } 5. Radiobutton Radiobutton1.Text=”Addition”; private void radioButton1_CheckedChanged(object sender, EventArgs e) { } 6. CheckListBox CheckListbox.Items.add(“Add”); CheckLIstbox.Items.add(“Sub”); private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e) { } 7. ComboBox Combobox.Items.add(“Add”); Combobox.Items.add(“Sub”); private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { } 8. ListBox Listbox1.Items.add(“Add”); Listbox1.Items.add(“Sub”); private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { } 9. Picturebox Picturebox1.Load(“Picture File Path”) private void pictureBox1_Click(object sender, EventArgs e) { } 10. Progressbar NIL private void progressBar1_Click(object sender, EventArgs e) { } 11. Treeview Treeview1.Items.add(“Add”); TreeView1.Items.add(“Sub”); private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { } 12. Listview Listview1.Items.add(“Add”); Listview1.Items.add(“Sub”); private void listView1_SelectedIndexChanged(object sender, EventArgs e) { } 13. Groupbox Groupbox1.Controls.add(button1); private void groupBox1_Enter(object sender, EventArgs e) { } 14. Timer Nil private void timer1_Tick(object sender, EventArgs e) { }

6 WINDOWS COMMON CONTROL PROPERTIES

7 SLNO PROPERITE NAME PROPERTY VALUE DESCRIPTION 1. Name “Form1” Indicates the name used in code to identify the object or control 2. Autosize True or False Specifies whether a control will automatically size iteselft to fit its contents 3. BackColor Color Name The background color of the component 4. BackgroundImage Image File path The background image used for the control 5. Enabled Indicates whether the control is enabled 6. ForeColor The foreground color of this component, which is used to display text. 7. Font Font Face, Font Style, Font size, Font Color The font used to display text in the control. 8. Location X, Y axis The coordinates of the upper – left corner of the control relative to the upper – left corner of its container 9. Locked The Locked property determines if we can move or resize the control 10. Size Width and Height The size of the control in pixels 11. Text “Text of the Particular Control” The text associated with the control 12. Visible Determines whether the control is visible or hidden 13. TabIndex Index value to the control Determines the index in the TAB order that this control will occupy. 14. TabStop Indicates whether the user can use the TAB key to give focus to the control. 15. TextAlign Left, Center, Rigth The alignment of the text that will be displayed on the control. 16. ToolTip Text Tool Tip Text on the particular Control Determines the tool tip shown when the mouse hovers over the control. 17. UseMnemonic If true, the first character proceeded by an ampersand (&) will be used as the button’s mnemonic key.

8 EXTRA PROPERTIES FOR THE WINDOWS CONTROLS

9 SLNO CONTROL NAME PROPERITE NAME PROPERTY VALUE DESCRIPTION 1. PictureBox Image .jpg or .bmp or .gif The image display in the PictureBox. WaitOnLoad True or False Controls whether processing will stop until the image is loaded. 2. RadioButton Checked Indicates whether the component is in the checked state. 3. Checkbox CheckState Unchecked or Checked or Intermediate Indicates the state of the component. ThreeState Indicates whether the CheckBox will allow three check states rather than two. 4. TextBox HideSelection Indicates that the selection should be hidden when the edit control loses focus. MaxLength 32767 Specifies the maximum number of character that can be entered into the edit control. Multiline Controls whether the text of the edit control can span more than one line. PasswordChar ***** or &&&&& Indicates the character to display for password input for single – line edit controls. ScrollBars None, Horizontal, Vertical Indicates, for multiline edit contrls, which scroll bars, will be shown for this control. WordWrap Indicates if lines are automatically word – wrapped for multiline edit controls. ShortcutsEnabled Indicates whether shortcuts defined for the control are enabled. 5. Form ControlBox Determines whether a form has a Control / System menu box. Cursor Different Cursor Control The Cursor that appear when the pointer moves over the control. MaximizeBox Determines whether a form has a maximize box in the upper – right corner of its caption bar. MinimizeBox Determines whether a form has a minimize box in the upper – right corner of its caption bar. StartPosition Windows appears for the different location Determines the position of a form when it first appears. WindowState Normal, Maximize, Minimize 6. Timer Enabled Enables generation of Elapsed events Interval 1000 (milliseconds) The frequency of Elapsed events in milliseconds 7. ProgressBar Minimum The lower bound of the range this ProgressBar is working with. Maximum 1000 The upper bound of the range this ProgressBar is working with.

10

11

12

13

14

15

16

17

18 MessageBox Program using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Form1 : Form public Form1() InitializeComponent(); }

19 private void button1_Click(object sender, EventArgs e)
{ MessageBox.Show("Welcome to Chettinad College of Engineering and Technology"); } private void button2_Click(object sender, EventArgs e) MessageBox.Show("Welcome", "Chettinad", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Stop); private void button3_Click(object sender, EventArgs e) DialogResult ans = MessageBox.Show("Arithmetic Operation", "Welcome", MessageBoxButtons.OKCancel); if (ans == DialogResult.OK ) MessageBox.Show("Click OK Button"); else if(ans == DialogResult.Cancel) MessageBox.Show("Click Cancel Button"); private void button4_Click(object sender, EventArgs e) Button_Control f2 = new Button_Control(); f2.Show();

20 Addition of Two Numbers using Button, Label and Textbox
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Button_Control : Form public Button_Control() InitializeComponent(); } private void button1_Click(object sender, EventArgs e) int a, b, c; a = int.Parse(textBox1.Text); b = int.Parse(textBox2.Text); c = a + b; textBox3.Text = c.ToString();

21 Arithmetic Operation using Checkboxes
private void checkBox1_CheckedChanged(object sender, EventArgs e) { if (checkBox1.Checked == true) checkBox2.Checked = false; checkBox3.Checked = false; checkBox4.Checked = false; checkBox5.Checked = false; x = textBox1.Text; y = textBox2.Text; a = int.Parse(x); b = int.Parse(y); c = a + b; textBox3.Text = c.ToString(); } } namespace WindowsApplication1 { public partial class CheckBox_Control : Form public CheckBox_Control() InitializeComponent(); } int a, b, c; string x, y;

22 private void checkBox3_CheckedChanged(object sender, EventArgs e)
{ if (checkBox3.Checked == true) checkBox1.Checked = false; checkBox2.Checked = false; checkBox4.Checked = false; checkBox5.Checked = false; x = textBox1.Text; y = textBox2.Text; a = int.Parse(x); b = int.Parse(y); c = a * b; textBox3.Text = c.ToString(); } private void checkBox2_CheckedChanged(object sender, EventArgs e) { if (checkBox2.Checked == true) checkBox1.Checked = false; checkBox3.Checked = false; checkBox4.Checked = false; checkBox5.Checked = false; x = textBox1.Text; y = textBox2.Text; a = int.Parse(x); b = int.Parse(y); c = a - b; textBox3.Text = c.ToString(); }

23 private void checkBox4_CheckedChanged(object sender, EventArgs e)
{ if (checkBox4.Checked == true) checkBox1.Checked = false; checkBox2.Checked = false; checkBox3.Checked = false; checkBox5.Checked = false; x = textBox1.Text; y = textBox2.Text; a = int.Parse(x); b = int.Parse(y); c = a / b; textBox3.Text = c.ToString(); } private void checkBox5_CheckedChanged(object sender, EventArgs e) { if (checkBox5.Checked == true) checkBox1.Checked = false; checkBox2.Checked = false; checkBox3.Checked = false; checkBox4.Checked = false; textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; }

24 Arithmetic Operation using Radio Buttons
private void radioButton1_CheckedChanged(object sender, EventArgs e) { if (radioButton1.Checked == true) radioButton2.Checked = false; radioButton3.Checked = false; radioButton4.Checked = false; radioButton5.Checked = false; try a = int.Parse(textBox1.Text); b = int.Parse(textBox2.Text); } catch c = a + b; textBox3.Text = c.ToString(); using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Radio_Control : Form int a, b, c; public Radio_Control() InitializeComponent(); }

25 private void radioButton2_CheckedChanged(object sender, EventArgs e)
{ if (radioButton2.Checked == true) radioButton1.Checked = false; radioButton3.Checked = false; radioButton4.Checked = false; radioButton5.Checked = false; a = int.Parse(textBox1.Text); b = int.Parse(textBox2.Text); c = a - b; textBox3.Text = c.ToString(); } private void radioButton3_CheckedChanged(object sender, EventArgs e) { if (radioButton3.Checked == true) radioButton1.Checked = false; radioButton2.Checked = false; radioButton4.Checked = false; radioButton5.Checked = false; a = int.Parse(textBox1.Text); b = int.Parse(textBox2.Text); c = a * b; textBox3.Text = c.ToString(); }

26 private void radioButton4_CheckedChanged(object sender, EventArgs e)
{ if (radioButton4.Checked == true) radioButton1.Checked = false; radioButton2.Checked = false; radioButton3.Checked = false; radioButton5.Checked = false; a = int.Parse(textBox1.Text); b = int.Parse(textBox2.Text); c = a / b; textBox3.Text = c.ToString(); } private void radioButton5_CheckedChanged(object sender, EventArgs e) { if (radioButton5.Checked == true) radioButton1.Checked = false; radioButton2.Checked = false; radioButton3.Checked = false; radioButton4.Checked = false; textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; } private void Form6_Load(object sender, EventArgs e) radioButton5.Checked = false;

27 Arithmetic Operation using ComboBox and ListBox
private void Form5_Load(object sender, EventArgs e) { comboBox1.Items.Add("Addition"); comboBox1.Items.Add("Subtraction"); comboBox1.Items.Add("Multiplication"); comboBox1.Items.Add("Division"); comboBox1.Items.Add("Clear"); listBox1.Items.Add("Addition"); listBox1.Items.Add("Subtraction"); listBox1.Items.Add("Multiplication"); listBox1.Items.Add("Division"); listBox1.Items.Add("Clear"); } using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Form5 : Form int a, b, c; public Form5() InitializeComponent(); }

28 private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { a = int.Parse(textBox1.Text); b = int.Parse(textBox2.Text); if (comboBox1.SelectedIndex == 0) c = a + b; textBox3.Text = c.ToString(); } if (comboBox1.SelectedIndex == 1) c = a - b; if (comboBox1.SelectedIndex == 2) c = a * b; if (comboBox1.SelectedIndex == 3) c = a / b; if (comboBox1.SelectedIndex == 4) textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { a = int.Parse(textBox1.Text); b = int.Parse(textBox2.Text); if (listBox1.SelectedIndex == 0) c = a + b; textBox3.Text = c.ToString(); } if (listBox1.SelectedIndex == 1) c = a - b; if (listBox1.SelectedIndex == 2) c = a * b; if (listBox1.SelectedIndex == 3) c = a / b; if (listBox1.SelectedIndex == 4) textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; } }

29 Arithmetic Operation using CheckListBox
private void Checkboxlist_Control_Load(object sender, EventArgs e) { checkedListBox1.Items.Add("Addition"); checkedListBox1.Items.Add("Subtraction"); checkedListBox1.Items.Add("Multiplication"); checkedListBox1.Items.Add("Division"); checkedListBox1.Items.Add("Clear"); } using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Checkboxlist_Control : Form public Checkboxlist_Control() InitializeComponent(); } int a, b, c;

30 private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{ a = int.Parse (textBox1 .Text ); b = int.Parse (textBox2 .Text ); if (checkedListBox1.SelectedIndex == 0) c = a + b; textBox3.Text = c.ToString(); } if (checkedListBox1.SelectedIndex == 1) c = a - b; if (checkedListBox1.SelectedIndex == 2) c = a * b; if (checkedListBox1.SelectedIndex == 3) c = a / b; if (checkedListBox1.SelectedIndex == 4) textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = "";

31 PROGRAM FOR THE PICTURE BOX
namespace WindowsApplication1 { public partial class Picturebox_Control : Form public Picturebox_Control() InitializeComponent(); and Settings\All Users\Documents\My Pictures\Sample Pictures\sunset.jpg"); } private void button1_Click(object sender, EventArgs e) pictureBox1 .Image = Image .FromFile and Settings\All Users\Documents\My Pictures\Sample Pictures\sunset.jpg"); pictureBox1.ImageLocation = " using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;

32 PROGRAM FOR THE PROGRESS BAR
private void Progress_Control_Load(object sender, EventArgs e) { progressBar1.Minimum = 0; progressBar1.Maximum = 1000; } private void button1_Click(object sender, EventArgs e) progressBar1.Increment(10); using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Progress_Control : Form public Progress_Control() InitializeComponent(); }

33 PROGRAM FOR THE PROGRESS BAR AND THE TIMER
private void Timer_Control_Load(object sender, EventArgs e) { progressBar1.Minimum = 0; progressBar1.Maximum = 1000; } private void timer1_Tick(object sender, EventArgs e) progressBar1.Increment(100); using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Timer_Control : Form public Timer_Control() InitializeComponent(); } NOTE In the Timer Control Properties change the Enabled properties is True and the set the Time Interval ( not Zero)

34 PROGRAM FOR THE LIST VIEW
private void button1_Click(object sender, EventArgs e) { listView1.View = View.LargeIcon; } private void button2_Click(object sender, EventArgs e) listView1.View = View.SmallIcon; private void button3_Click(object sender, EventArgs e) listView1.View = View.List; private void button4_Click(object sender, EventArgs e) listView1.View = View.Details; private void button5_Click(object sender, EventArgs e) listView1.Clear(); using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Listview_Control : Form public Listview_Control() InitializeComponent(); }

35 Creating Calculator Program using the Code File
(Design view and Code view Creating to the User) //1. Include the Namespaces// using System; using System.Drawing; using System.Windows.Forms; //2. Create a class that inherit from Form class of Windows// public class ButtonDemo: Form { //3.Create the Controls // Button b0; Button b1; Button b2; Button b3; Button b4; Button b5; Button b6; Button b7; String s1=""; String s2=""; String op=""; TextBox t1; //4.Create the class Constructor methosd to invoke the components to be initialized// public ButtonDemo() //5. Invoke the method to initialize the components// InitializeComponent(); }

36 private void InitializeComponent()
{ // Initilaize the components properties and Events// t1=new TextBox(); t1.Name="textbox1"; t1.Location=new Point(50,80); t1.Size=new System.Drawing.Size(80,50); this.Controls.Add(t1); b0=new Button(); b0.Location=new Point(50,120); b0.Size=new System.Drawing.Size(25,25); b0.Text="0"; b0.Click+=new System.EventHandler(this.btnsubmit_Click); this.Controls.Add(b0); b1=new Button(); b1.Location=new Point(75,120); b1.Size=new System.Drawing.Size(25,25); b1.Text="1"; b1.Click += new System.EventHandler(this.btnsubmit_Click); this.Controls.Add(b1); b2 = new Button(); b2.Location = new Point(100, 120); b2.Size = new System.Drawing.Size(25, 25); b2.Text = "2"; b2.Click += new System.EventHandler(this.btnsubmit_Click); this.Controls.Add(b2);

37 b6.Location = new Point(100, 145);
b3 = new Button(); b3.Location = new Point(125, 120); b3.Size = new System.Drawing.Size(25, 25); b3.Text = "3"; b3.Click += new System.EventHandler(this.btnsubmit_Click); this.Controls.Add(b3); b4 = new Button(); b4.Location = new Point(50, 145); b4.Size = new System.Drawing.Size(25, 25); b4.Text = "4"; b4.Click += new System.EventHandler(this.btnsubmit_Click); this.Controls.Add(b4); b5 = new Button(); b5.Location = new Point(75, 145); b5.Size = new System.Drawing.Size(25, 25); b5.Text = "+"; b5.Click += new System.EventHandler(this.btnsubmit_Click); this.Controls.Add(b5); b6 = new Button(); b6.Location = new Point(100, 145); b6.Size = new System.Drawing.Size(25, 25); b6.Text = "-"; b6.Click += new System.EventHandler(this.btnsubmit_Click); this.Controls.Add(b6); b7 = new Button(); b7.Location = new Point(125, 145); b7.Size = new System.Drawing.Size(25, 25); b7.Text = "="; b7.Click += new System.EventHandler(this.btnsubmit_Click); this.Controls.Add(b7); this.Name="Button Demo"; this.Text="Button Demo"; }

38 else if(sender.Equals(b7)) { if(op.Equals("+"))
//Events handling Procedures// private void btnsubmit_Click(Object sender, EventArgs e) { if(sender.Equals(b0)) t1.Text += "0"; } else if (sender.Equals(b1)) t1.Text += "1"; else if (sender.Equals(b2)) t1.Text+="2"; else if (sender.Equals(b3)) t1.Text += "3"; else if (sender.Equals(b4)) t1.Text += "4"; else if (sender.Equals(b5)) s1=t1.Text; t1.Text=""; op=b5.Text; } else if(sender.Equals(b7)) { if(op.Equals("+")) MessageBox.Show((Int32.Parse(t1.Text)+Int32.Parse(s1)).ToString()); public class Demo static void Main() System.Windows.Forms.Application.Run(new ButtonDemo());

39 Output of the Above program is

40 Data Access with ADO.NET

41 ADO.NET relational data bases XML data other data sources
Is the .NET technology for accessing structured data Uniform object oriented interface for different data sources relational data bases XML data other data sources Designed for distributed and Web applications Provides 2 models for data access connection-oriented connectionless

42 Idea of Universal Data Access
Connection of (object-oriented) programming languages and relational data bases Uniform programming model and API Special implementations for data sources (providers)

43 Data Providers Microsoft’s layered architecture for data access

44 History of Universal Data Access (Microsoft)
ODBC OLE DB ADO (ActiveX Data Objects) ADO.NET ADO ADO.NET connection-oriented connection-oriented + connectionless sequential access sequential access + main-memory representation with direct access only one table supported more than one table supported COM-marshalling XML-marshalling

45 DIFFERENCES BETWEEN ADO AND ADO .NET
ADO has one main object that is used to reference data, called the Record set object. This object basically gives you a single table view of your data, although you can join tables to create a new set of records.   With ADO.NET, you have various objects that allow you to access data in various ways. The Dataset object will actually allow you to store the relational model of your database. This allows you to pull up customers and their orders, accessing/updating the data in each related table individually. ADO works with connected data. This means that when you access data, such as viewing and updating data, it is real-time, with a connection being used all the time. This is barring, of course, you programming special routines to pull all your data into temporary tables.   ADO.NET uses data in a disconnected fashion. When you access data, ADO.NET makes a copy of the data using XML. ADO.NET only holds the connection open long enough to either pull down the data or to make any requested updates. This makes ADO.NET efficient to use for Web applications. It's also decent for desktop applications. In ado user can move sequentially to database In ado.net user can move one data from one table to another table. ADO allows you to create client-side cursors only ADO.NET we don't have any cursor support in ADO.NET. ADO allows you to persist records in XML format ADO.NET allows you to manipulate your data using XML as the primary means. This is nice when you are working with other business applications and also helps when you are working with firewalls because data is passed as HTML and XML.   COM – marshalling XML – marshalling

46 Architecture of ADO.NET

47 Architecture represents connection to data source
DbConnection represents connection to data source DbCommand represents a SQL command DbTransaction represents a transaction commands can be executed within a transaction DataReader result of a data base query allows sequential reading of rows

48 DataTables and DataColumns
DataAdapter DataAdapter as a bridge between the DataSet and the data source, which is underlying database DataAdapter provides the Fill() method to retrieve data from the database and populate the dataset DataSet A DataSet represents a complete set of data including the tables that contain, order, and constrain the data, as well as the relationships between the tables. DataTables and DataColumns The DataTable has a number of public properties, including the columns collection, which returns the DataColumnCollection object ,which in trun consists of DataColumn objects. Each DataColumn object represents a column in a table DataRelations DataRelation represents a relationship between two tables through DataColumn objects. For example, in the Northwind database the Customers table is in a relationship with the Orders table through the CustomerID column DataRows - DataTable’s Rows collection returns a set of rows for that table. Use this collection to examine the results of queries against the database, iterating throught the rows to examine each record in trun.

49 Connection-oriented versus Connectionless
Keeps the connection to the data base alive Always up-to-date data Intended for applications with: short running transactions only a few parallel access operations Connectionless No permanent connection to the data source Data cached in main memory Changes in main memory may be in conflict with changes in data source many parallel and long lasting access operations (e.g.: Web applications)

50 IDbConnection: Property ConnectionString

51 ExecuteNonQuery Method

52 ExecuteScalar Method

53 ADO.NET and Transactions
2 transaction models local transactions: transactions for one connection provided by ADO.NET distributed transactions: transactions for several connections usage of Microsoft Distributed Transaction Component (MSDTC) namespace System.Transaction

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70


Download ppt "WINDOWS COMMON CONTROLS DEFAULT EVENT HANDLERS."

Similar presentations


Ads by Google