Answer 1
using System;
public class evenoddarr
{
public static void Main (string[] args)
{
int[] arr=new int[5];
int odd=0,even=0;
for(int i=0;i<5;i++)
{
Console.Write("Value {0} :",i);
arr[i]=Convert.ToInt32(Console.ReadLine());
if(arr[i]%2==0)
even++;
else
odd++;
}
Console.WriteLine("The even nos are "+even);
Console.WriteLine("The odd nos are "+odd);
string x=Console.ReadLine(); //for holding the screen
}
}
Answer 2
using System;
public class vowelcount
{
public static void Main (string[] args)
{
//char[] arr=new char[10];
string input;
int vowels=0;
input=Console.ReadLine();
char[] arr=input.ToCharArray();
for(int i=0;i<input.Length;i++)
{
if(Char.ToLower(arr[i]).Equals('a')||
Char.ToLower(arr[i]).Equals('e')||
Char.ToLower(arr[i]).Equals('i')||
Char.ToLower(arr[i]).Equals('o')||
Char.ToLower(arr[i]).Equals('u'))
vowels++;
}
Console.WriteLine("The vowels nos are "+vowels);
string x=Console.ReadLine(); //for holding the screen
}
}
Answer 3:
using System;
public class factorial
{
public static void Main (string[] args)
{
//char[] arr=new char[10];
int input;
long fact=1;
input=Convert.ToInt32(Console.ReadLine());
for(int i=input;i>0;i--)
{
fact=fact * i;
}
Console.WriteLine("The factorial is "+fact);
string x=Console.ReadLine(); //for holding the screen
}
}
Answer 2://imp
using System;
using System.Windows.Forms;
using System.Drawing;
public class form1:Form
{
public CheckBox c1=new CheckBox();
public Button b1=new Button();
public form2 f2;
public form1()
{
//form features
this.Size=new System.Drawing.Size(400,400);
this.Location=new System.Drawing.Point(100,100);
//checkbox features
c1=new CheckBox();
c1.Text="dot net";
c1.Size=new System.Drawing.Size(100,50);
c1.Location=new System.Drawing.Point(100,200);
c1.CheckStateChanged+=new EventHandler(c1_CheckStateChanged);
Controls.Add(c1);
//button features
b1=new Button();
b1.Text="Click me";
b1.Size=new System.Drawing.Size(100,50);
b1.Location=new System.Drawing.Point(10,200);
b1.Click+=new EventHandler(b1_Click);
Controls.Add(b1);
f2=new form2();
}
public static void Main()
{
Application.Run(new form1());
}
private void b1_Click(object sender, EventArgs e)
{
f2.Show();
f2.BringToFront();
}
private void c1_CheckStateChanged(object sender, EventArgs e)
{
if(c1.Checked)
{
f2.c1.Checked=true;
f2.c2.Checked=true;
}
else
{
f2.c1.Checked=false;
f2.c2.Checked=false;
}
}
}
public class form2:Form
{
public CheckBox c1;
public CheckBox c2;
public Button b1;
public form2()
{
//form features
this.Size=new System.Drawing.Size(400,400);
this.Location=new System.Drawing.Point(100,100);
//checkbox1 features
c1=new CheckBox();
c1.Text="c#";
c1.Size=new System.Drawing.Size(100,50);
c1.Location=new System.Drawing.Point(100,100);
Controls.Add(c1);
//checkbox2 features
c2=new CheckBox();
c2.Text="VS.net";
c2.Size=new System.Drawing.Size(100,50);
c2.Location=new System.Drawing.Point(100,200);
Controls.Add(c2);
//button features
b1=new Button();
b1.Text="Click me";
b1.Size=new System.Drawing.Size(100,50);
b1.Location=new System.Drawing.Point(100,300);
Controls.Add(b1);
}
}
Answer 2(a)//imp
public class form1:Form
{
RadioButton r1;
RadioButton r2;
PictureBox p1;
Pen pen1;
Graphics g;
public form1()
{
//form features
this.Size=new System.Drawing.Size(400,400);
this.Location=new System.Drawing.Point(100,100);
pen1=new Pen(Color.Red,4);
//checkbox features
r1=new RadioButton();
r1.Text="Line";
r1.Size=new System.Drawing.Size(100,20);
r1.Location=new System.Drawing.Point(100,10);
r1.CheckedChanged+=new EventHandler(r1_CheckedChanged);
Controls.Add(r1);
//checkbox features
r2=new RadioButton();
r2.Text="Rectangle";
r2.Size=new System.Drawing.Size(100,20);
r2.Location=new System.Drawing.Point(100,50);
r2.CheckedChanged+=new EventHandler(r2_CheckedChanged);
Controls.Add(r2);
//checkbox features
p1=new PictureBox();
p1.Location=new System.Drawing.Point(100,100);
p1.Size=new System.Drawing.Size(400,400);
p1.BackColor=Color.White;
Controls.Add(p1);
//
// TODO: Add constructor logic here
//
}
public static void Main()
{
Application.Run(new form1());
}
private void r1_CheckedChanged(object sender, EventArgs e)
{
g=p1.CreateGraphics();
g.Clear(p1.BackColor);
g.DrawLine(pen1,10,10,30,30);
}
private void r2_CheckedChanged(object sender, EventArgs e)
{
g=p1.CreateGraphics();
g.Clear(p1.BackColor);
g.DrawRectangle(pen1,20,20,30,100);
}
}
Answer 2(b)://padnu pardaina(x)
public class form1:Form
{
MainMenu mBar;
MenuItem mFile, mf1,mf2,mf3;
public form1()
{
//form features
this.Size=new System.Drawing.Size(400,400);
this.Location=new System.Drawing.Point(100,100);
//menu features
mBar=new MainMenu();
mFile=new MenuItem("File");
mf1=new MenuItem("Add Three Text Box");
mf2=new MenuItem("Add Button");
mf3=new MenuItem("Exit");
mFile.MenuItems.Add(mf1);
mFile.MenuItems.Add(mf2);
mFile.MenuItems.Add(mf3);
mf3.Click+=new EventHandler(mf3_Click);
mBar.MenuItems.Add(mFile);
this.Menu=mBar;
//
}
public static void Main()
{
Application.Run(new form1());
}
private void mf3_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
Answer 3:
public class form1:Form
{
protected override void OnPaint(PaintEventArgs e)
{
Graphics g=this.CreateGraphics();
Font f1=new Font("Arial",16,FontStyle.Bold^FontStyle.Italic);
SolidBrush b1=new SolidBrush(Color.Black);
g.DrawString(".Net Programming",f1,b1,20,20);
}
public form1()
{
//form features
this.Size=new System.Drawing.Size(400,400);
this.Location=new System.Drawing.Point(100,100);
}
public static void Main()
{
Application.Run(new form1());
}
}
Answer 4:
public class form1:Form
{
ComboBox cb;
Label l1;
public form1()
{
//form features//pardaina
//this.Size=new System.Drawing.Size(400,400);
//this.Location=new System.Drawing.Point(100,100);
//checkbox features
l1=new Label();
l1.Text="items";
l1.Size=new System.Drawing.Size(200,20);
l1.Location=new System.Drawing.Point(10,10);
Controls.Add(l1);
//checkbox features
cb=new ComboBox();
cb.Size=new System.Drawing.Size(200,20);
cb.Location=new System.Drawing.Point(10,50);
cb.SelectedIndexChanged+=new EventHandler(cb_SelectedIndexChanged);
cb.Items.Add("Apple");
cb.Items.Add("Orange");
cb.Items.Add("Banana");
Controls.Add(cb);
}
public static void Main()
{
Application.Run(new form1());
}
private void cb_SelectedIndexChanged(object sender, EventArgs e)
{
l1.Text=cb.SelectedItem.ToString();
}
}
Answer 5/6:
public class form1:Form
{
OpenFileDialog ofd;
ColorDialog cd;
Button b1;
public form1()
{
//form features
this.Size=new System.Drawing.Size(400,400);
this.Location=new System.Drawing.Point(100,100);
b1=new Button();
b1.Text="click";
b1.Location=new System.Drawing.Point(10,10);
b1.Size=new System.Drawing.Size(100,30);
b1.Click+=new EventHandler(b1_Click);
Controls.Add(b1);
}
public static void Main()
{
Application.Run(new form1());
}
private void b1_Click(object sender, EventArgs e)
{
//for setting background image
OpenFileDialog ofd=new OpenFileDialog();
ofd.Filter="Bmp File (*.bmp) | *.bmp|JPeg files(*.jpg)|*.jpg|Gif files(*.gif)|*.gif";
ofd.RestoreDirectory=true;
if(ofd.ShowDialog()==DialogResult.OK)
{
this.BackgroundImage=Image.FromFile(ofd.FileName);
//MessageBox.Show(ofd.FileName);
}
//for setting background color
cd=new ColorDialog();
if(cd.ShowDialog()==DialogResult.OK)
{
this.BackColor=cd.Color;
//MessageBox.Show(ofd.FileName);
}
}
}
Answer 7:
public class form1:Form
{
PictureBox p1;
Button b1;
public form1()
{
//form features
this.Size=new System.Drawing.Size(400,400);
this.Location=new System.Drawing.Point(100,100);
//checkbox features
b1=new Button();
b1.Text="Draw";
b1.Size=new System.Drawing.Size(100,20);
b1.Location=new System.Drawing.Point(100,50);
b1.Click+=new EventHandler(b1_Click);
Controls.Add(b1);
//checkbox features
p1=new PictureBox();
p1.Location=new System.Drawing.Point(100,100);
p1.Size=new System.Drawing.Size(400,400);
p1.BackColor=Color.White;
Controls.Add(p1);
//
// TODO: Add constructor logic here
//
}
public static void Main()
{
Application.Run(new form1());
}
private void b1_Click(object sender, EventArgs e)
{
Graphics g=p1.CreateGraphics();
Font f1=new Font("Arial Black",14);
SolidBrush sb=new SolidBrush(Color.Red);
g.DrawString("Welcome",f1,sb,20,20);
g.FillEllipse(sb,50,50,20,20);
}
}
Answer 8:
public class form1:Form
{
Label l1;
Button b1;
Timer t1;
public form1()
{
//form features
this.Size=new System.Drawing.Size(400,400);
this.Location=new System.Drawing.Point(100,100);
l1=new Label();
l1.Text="click";
l1.Location=new System.Drawing.Point(10,10);
l1.Size=new System.Drawing.Size(400,30);
Controls.Add(l1);
b1=new Button();
b1.Text="click";
b1.Location=new System.Drawing.Point(10,50);
b1.Size=new System.Drawing.Size(100,30);
b1.Click+=new EventHandler(b1_Click);
Controls.Add(b1);
t1=new Timer();
t1.Interval=1000;
t1.Tick+=new EventHandler(t1_Tick);
}
public static void Main()
{
Application.Run(new form1());
}
private void b1_Click(object sender, EventArgs e)
{
t1.Start();
}
private void t1_Tick(object sender, EventArgs e)
{
l1.Text=DateTime.Now.ToLongTimeString();
//l1.Text=DateTime.Now.ToLString();
}
}
Answer 9:
public class form1:Form
{
Label l1;
public form1()
{
//form features
this.Size=new System.Drawing.Size(400,400);
this.Location=new System.Drawing.Point(100,100);
this.KeyPress+=new KeyPressEventHandler(form1_KeyPress);
//checkbox features
l1=new Label();
l1.Text="Press keys";
l1.Size=new System.Drawing.Size(100,20);
l1.Location=new System.Drawing.Point(100,50);
Controls.Add(l1);
}
public static void Main()
{
Application.Run(new form1());
}
private void form1_KeyPress(object sender, KeyPressEventArgs e)
{
l1.Text="Key Pressed="+e.KeyChar;
}
}
Answer 10:
Solve yourself
Answer 11:
Solve yourself
Answer 12:
public class form1:Form
{
TextBox t1;
Button b1,b2;
ListBox lb;
public form1()
{
//form features
this.Size=new System.Drawing.Size(400,400);
this.Location=new System.Drawing.Point(100,100);
//checkbox features
t1=new TextBox();
t1.Text="";
t1.Size=new System.Drawing.Size(200,20);
t1.Location=new System.Drawing.Point(10,10);
Controls.Add(t1);
//checkbox features
b1=new Button();
b1.Text="Add";
b1.Size=new System.Drawing.Size(200,20);
b1.Location=new System.Drawing.Point(10,50);
b1.Click+=new EventHandler(b1_Click);
Controls.Add(b1);
//checkbox features
b2=new Button();
b2.Text="Remove";
b2.Size=new System.Drawing.Size(200,20);
b2.Location=new System.Drawing.Point(10,80);
b2.Click+=new EventHandler(b2_Click);
Controls.Add(b2);
lb=new ListBox();
lb.Size=new System.Drawing.Size(200,100);
lb.Location=new System.Drawing.Point(10,150);
Controls.Add(lb);
}
public static void Main()
{
Application.Run(new form1());
}
private void b1_Click(object sender, EventArgs e)
{
if(t1.Text!="")
lb.Items.Add(t1.Text);
t1.Text="";
}
private void b2_Click(object sender, EventArgs e)
{
if(lb.SelectedIndex!=-1)
{
lb.Items.RemoveAt(lb.SelectedIndex);
}
else
MessageBox.Show("No item selected to remove");
}
}
Answer 13:
Solve yourself
Answer 14:
public class form1:Form
{
LinkLabel l1;
public form1()
{
//form features
this.Size=new System.Drawing.Size(400,400);
this.Location=new System.Drawing.Point(100,100);
l1=new LinkLabel();
l1.Text="Click to open google";
l1.Location=new System.Drawing.Point(10,10);
l1.Size=new System.Drawing.Size(400,30);
l1.Click+=new EventHandler(l1_Click);
Controls.Add(l1);
}
public static void Main()
{
Application.Run(new form1());
}
private void l1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://www.google.com");
}
}
Answer 15:
public class form1:Form
{
RichTextBox r1;
OpenFileDialog ofd;
SaveFileDialog sfd;
Button b1,b2,b3;
public form1()
{
//form features
this.Size=new System.Drawing.Size(400,400);
this.Location=new System.Drawing.Point(100,100);
b1=new Button();
b1.Text="Open";
b1.Location=new System.Drawing.Point(10,10);
b1.Size=new System.Drawing.Size(50,30);
b1.Click+=new EventHandler(b1_Click);
Controls.Add(b1);
b2=new Button();
b2.Text="Save As";
b2.Location=new System.Drawing.Point(10,50);
b2.Size=new System.Drawing.Size(50,30);
b2.Click+=new EventHandler(b2_Click);
Controls.Add(b2);
b3=new Button();
b3.Text="Save";
b3.Location=new System.Drawing.Point(10,90);
b3.Size=new System.Drawing.Size(50,30);
b3.Click+=new EventHandler(b3_Click);
Controls.Add(b3);
r1=new RichTextBox();
r1.Location=new System.Drawing.Point(10,120);
r1.Size=new System.Drawing.Size(400,300);
Controls.Add(r1);
}
public static void Main()
{
Application.Run(new form1());
}
private void l1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://www.google.com");
}
private void b1_Click(object sender, EventArgs e)
{
//open the text files in richtext box
ofd=new OpenFileDialog();
if(ofd.ShowDialog()==DialogResult.OK)
{
StreamReader sr=new StreamReader(ofd.FileName);
r1.Text=sr.ReadToEnd();
sr.Close();
}
}
private void b2_Click(object sender, EventArgs e)
{
sfd=new SaveFileDialog();
sfd.Filter="All files(*.*)|*.*|text files(*.txt)|*.txt";
if(sfd.ShowDialog()==DialogResult.OK)
{
r1.SaveFile(sfd.FileName,RichTextBoxStreamType.PlainText);
}
}
private void b3_Click(object sender, EventArgs e)
{
r1.SaveFile(ofd.FileName,RichTextBoxStreamType.PlainText);
}
}
Answer 16:
Solve yourself
Answer 17:
Solve yourself
Answer 18:
public class form1:Form
{
Label l1;
public form1()
{
//form features
this.Size=new System.Drawing.Size(400,400);
this.Location=new System.Drawing.Point(100,100);
this.MouseDown+=new MouseEventHandler(form1_MouseDown);
//checkbox features
l1=new Label();
l1.Text="Press Mouse";
l1.Size=new System.Drawing.Size(200,20);
l1.Location=new System.Drawing.Point(100,50);
Controls.Add(l1);
}
public static void Main()
{
Application.Run(new form1());
}
private void form1_MouseDown(object sender, MouseEventArgs e)
{
l1.Text="Mouse Position: "+e.X+" , "+e.Y;
}
}
Answer 19:
Solve yourself
1. Use of Range Validator
<script runat="server">
public void submit(Object sender, EventArgs e)
{
public void submit(Object sender, EventArgs e)
{
if(Page.IsValid)
lbl1.Text="Page is valid."
else
lbl1.Text="Page is not valid!!"
}
else
lbl1.Text="Page is not valid!!"
}
</script>
<html>
<body>
<form runat="server">
Enter a number from 1 to 100:
<asp:TextBox id="tbox1" runat="server" />
<br /><br />
<asp:Button Text="Submit" OnClick="submit" runat="server" />
<br /><br />
<asp:Label id="lbl1" runat="server" />
<br />
<asp:RangeValidator
ControlToValidate="tbox1"
MinimumValue="1"
MaximumValue="100"
Type="Integer"
EnableClientScript="false"
Text="The value must be from 1 to 100!"
runat="server" />
</form>
</body>
</html>
<html>
<body>
<form runat="server">
Enter a number from 1 to 100:
<asp:TextBox id="tbox1" runat="server" />
<br /><br />
<asp:Button Text="Submit" OnClick="submit" runat="server" />
<br /><br />
<asp:Label id="lbl1" runat="server" />
<br />
<asp:RangeValidator
ControlToValidate="tbox1"
MinimumValue="1"
MaximumValue="100"
Type="Integer"
EnableClientScript="false"
Text="The value must be from 1 to 100!"
runat="server" />
</form>
</body>
</html>
2. Use of Regular Expression Validator
public void submit(Object sender, EventArgs e)
{
{
if(Page.IsValid)
lbl1.Text="Page is valid."
else
lbl1.Text="Page is not valid!!"
}
<html>else
lbl1.Text="Page is not valid!!"
}
<body>
<form runat="server">
Enter a US zip code:
<asp:TextBox id="txtbox1" runat="server" />
<br /><br />
<asp:Button text="Submit" OnClick="submit" runat="server" />
<br /><br />
<asp:Label id="lbl" runat="server" />
<br />
<asp:RegularExpressionValidator
ControlToValidate="txtbox1"
ValidationExpression="\d{5}"
EnableClientScript="false"
ErrorMessage="The zip code must be 5 numeric digits!"
runat="server" />
</form>
</body>
</html>
3. Use of Required Field Validator
<html>
<body>
<form runat="server">
Name: <asp:TextBox id="name" runat="server" />
<br />
Age: <asp:TextBox id="age" runat="server" />
<br /><br />
<asp:Button runat="server" Text="Submit" />
<br /><br />
<asp:RequiredFieldValidator
ControlToValidate="name"
Text="The name field is required!"
runat="server" />
</form>
</body>
</html>
<body>
<form runat="server">
Name: <asp:TextBox id="name" runat="server" />
<br />
Age: <asp:TextBox id="age" runat="server" />
<br /><br />
<asp:Button runat="server" Text="Submit" />
<br /><br />
<asp:RequiredFieldValidator
ControlToValidate="name"
Text="The name field is required!"
runat="server" />
</form>
</body>
</html>
4. Use of Compare Validator
<html>
<body>
<form id="Form1" runat="server">
<body>
<form id="Form1" runat="server">
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:Label id="Label1" runat="server" TextMode=”Password”>Password</asp:Label>
<asp:Label id="Label2" runat="server" TextMode=”Password”>Confirm Password</asp:Label>
<asp:TextBox id="TextBox2" runat="server"></asp:TextBox>
<asp:CompareValidator id="CompareValidator1" runat="server" ErrorMessage="Password Mismatch" ControlToValidate="TextBox2" ControlToCompare="TextBox1"></asp:CompareValidator>
</form>
AddRotator Example
<%@ Page language="C#" Codebehind="adrotator.aspx.cs"%>
<script runat="server">
void AdCreated_Event(Object sender, AdCreatedEventArgs e)
{
e.NavigateUrl="http://www.w3schools.com" ;
}
}
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:AdRotator id="AdRotator1" runat="server" AdvertisementFile="AdRotatorInfo.xml"> </asp:AdRotator>
</form>
</body>
</html>
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad><ImageUrl>a.jpg</ImageUrl>
<AlternativeText>Picture1</AlternativeText></Ad>
<Ad><ImageUrl>b.jpg</ImageUrl>
<AlternativeText>Picture2</AlternativeText></Ad>
</Advertisements>
No comments:
Post a Comment