Professional Documents
Culture Documents
namespace WindowsFormsApplication1
{
public partial class Calc : Form
{
double FirstNumber;
string operation;
public Calc()
{
InitializeComponent();
textBox2.Text = "7";
}
else
{
textBox2.Text += "7";
}
}
textBox2.Text += "1";
}
}
textBox1.Text = null;
SecondNumber = Convert.ToDouble(textBox2.Text);
else i
f (operation == "-")
{
Result = (FirstNumber - SecondNumber);
textBox2.Text = Convert.ToString(Result);
}
else i
f (operation == "*")
{
Result = (FirstNumber * SecondNumber);
textBox2.Text = Convert.ToString(Result);
}
textBox2.Text = "0";
operation = "-";
}
else
{
textBox2.Text += ".";
}
}
}
}
}
6
Output:
7
namespace WindowsFormsApp5
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
}
x /= 2;
}
textBox2.Text = y;
}
}
}
Output:
8
namespace WindowsFormsApp5
{
public partial class Form5 : Form
{
public OleDbConnection connection1 = new OleDbConnection();
public Form5()
{
InitializeComponent();
connection1.ConnectionString= @"Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=D:\\Pass.accdb;Persist Security Info=False";
}
private void button1_Click(object sender, EventArgs e)
{
connection1.Open();
OleDbCommand com1 = new OleDbCommand();
com1.Connection = connection1;
com1.CommandText = "select * from id where username='" + textBox1.Text + "'and password='"
+ textBox2.Text + "'";
OleDbDataReader reader1 = com1.ExecuteReader();
bool access = false;
while (reader1.Read())
{
access = true;
}
if (access)
{
MessageBox.Show("Login Successful");
}
else
{
MessageBox.Show("Incorrect Username or Password");
}
textBox1.Clear();
textBox2.Clear();
connection1.Close();
}
}
}
9
Output:
10
con.Open();
OleDbCommand com1 = new OleDbCommand();
com1.Connection = con; com1.CommandText = "insert into csinfo(sname,rollno) values('" +
textBox1.Text + "','" + textBox2.Text + "')";
com1.ExecuteNonQuery();
MessageBox.Show("Submitted");
textBox1.Text = null;
textBox2.Text = null;
con.Close();
}
}
}
11
Output:
12
13
Output:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp5
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
textBox2.Text = objReader.ReadToEnd();
objReader.Close();
}
else
{
MessageBox.Show("No such file" + file_name);
}
}
System.IO.StreamWriter objWriter;
objWriter = new System.IO.StreamWriter(file_name);
objWriter.Write(textBox2.Text + textBox3.Text);
objWriter.Close();
textBox3.Clear();
MessageBox.Show("Wrote File");
}
System.IO.StreamWriter objWriter1;
objWriter1 = new System.IO.StreamWriter(file_name);
objWriter1.Write("");
objWriter1.Close();
}
}
}
Output:
17
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
}
Output:
19
namespace WindowsFormsApp6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
}
Output:
20
namespace WindowsFormsApp6
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
wc.DownloadFile(textBox1.Text, @"D:\\Download.pdf");
MessageBox.Show("DONE");
}
}
}
Output:
21
namespace WindowsFormsApp5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
if (!Directory.Exists(root))
{
Directory.CreateDirectory(root);
MessageBox.Show("Directory Successfully Created");
}
else
{
MessageBox.Show("Directory Already Exists");
}
}
}
}
22
Output: