Interested in mastering .Net Training? Enroll now for a FREE demo on ".Net Training".
Place a button on the form
Code for Button1-click
{
Var x = 1500;
Message box. show(X. Get Type().name);
}
Property Auto Implemented property
Data type var name; Public data type Property name Public
Data type pname {
{
set” (no logic) Set{var name - value Get:
Get{return var name} }
}
Auto implemented property is a collection of set and get methods without any logic.
Auto implemented property are required for object initializes and collection initializes.
Class em {
Private int double SQL, Eno;
Public string e name;
Public emp(int){}
Emp E1= new Emp(id)
P Emp(string x){}
Emp E2= new Emp(‘Teja’) (double x)…
Emp E3 = NEW Emp(71.3) Emp
E4 = NEW Emp(101,teja)
------- =
NEW Emp()
EMP E1=new EMP(101,”Teja”);
4.Syntax to create an object with object Initialize EMP E1=New EMP{Property name=value} Auto Implemented property 5. The main objective of the object Initializes to reduce the number of lines in the source.
Code
Place a button on the form
code in GD Class emp
{
Public int eno
{
set;get;
}
Public string ename
{
set; get;
}
Public int SQL
{
set; get;
} }//Emp
{
Emp E1 New EMP{Eno=101, Ename=”Bangaru”, SQL=5000};
Message Box.show(E1.Eno+””+E1.Ename+”” E.SQL);
}
Int x; Int[] x= new int[10]
EMP[]X=new EMP[10]; //Orcate an array with 10 elements but not with 10 objects If we want 10 objects.
Example
Place a button
Code in GD Class EMP { Public int Eno {set; get;} Public string Ename{ set; get;} }//Emp
{
List<Emp>x=new List<Emp>
{
New Emp {Eno=101,Ename=”Teja”},
New Emp {Ename=”ravi”},
New Emp {Eno=203},
}//print the data For each
(EMP e1 in x) Message Box. Show (e1.Eno+””+e1.Ename);
}
Var x=new
{eno=101,ename=”teja”}
Message box. show(x.eno+””+x. ename);
Class form1 { Class test{} Inline class }//form1 Class best{} outline class
Adding a new method to an existing data type int
Open windows forms application project
Place a button
Code after form1 class { } }
//form1 Static class test
{
Public static void print(this int1)
{
Message box. show(i+””);
}//print method
}
//test
code for button1-click
{
Int x =10;
print();
}
Partial class test { Partial void print(); } Partial class test { Partial void print() { Message box. Show(“from print”); } Public void display { PRINT(); }
place a button on the form
code in GD Partial class test
{
Partial void print();
//declaration
}
Partial class test
{
Partial void print();
//default private
{
Message box. Show(“from print”);
}
Public void display
{
PRINT();
}
}//test
Code for button1-click
{
Test t = new test();
display();
}
(a) Shapes (b) Graphics (c) Allows to use brushes (d)Transformations (e)Animations
XAML is similar to XML Syntactically.
HTML | XML | XAML |
|
To describe the data | To develop WPF Applications |
|
case sensitive | case sensitive |
|
Structured Language | Structured Language |
|
Collection of user defined tags | Collection of pre defined tags |
<peers> Root element
<student>entity <sno>101
</sno > sub entities <sno> taja</sn> (or)
Attributes
</stu>
<faculty <FN>Ravi</FN>
<SAL>3800</SAL>
</Faculty>
</peers>
<Window>
<GRID>
<Button>------< /Button >
<Label>------< /Label >
< /GRID >
</Window>
Open WPF Application project.
Write the following with in Grid tag.
< Grid >
<Text block text=”MICROSOFT”>
<Font size=”40” Font family=”Arial”>
<Text block. Fore ground>
<Linear Gradient brush>
< Gradient stop offset=”.1”color=”Red”/>
< Gradient stop offset=”.3”color=”yellow”/>
< Gradient stop offset=”.5”color=”blue”/>
< Gradient stop offset=”.8”color=”Green”/>
< / Linear gradient brush>
< / Text block. Fore ground>
< / Text block >
< / Grid >
Obs:-
offset value must be in between 0 to1.
offset indicates the color starting point.
<Grid>is called a container.
WPF Supports two types of containers GRID Container
Example on Grid with multiple rows and columns
Open WPF
Write the following within Grid tag
<Grid>
<Grid. Row Definitions>
<Row Definition Height=”150”>
</ Row Definitions>
</Grid. Row Definitions>
<Grid. Column Definitions>
< Column Definitions width=”150”>
< /Column Definitions>
</Grid. Column Definitions>
<Button Grid. Row =”o” Grid. Column=”o”>Click1< /Button >
< Button Grid. Row =”o” Grid. Column=”1”>Click1< /Button >
</Grid>
</Grid. Row Definitions>
<Row Definitions Height=”150”>
</ Row Definitions >
Working with brushes
WPF supports 4 types of brushes
Solid color Brush
Linear Gradient Brush
Radial gradient Brush
Image Brush
Technology
Open WPF Application project Remove Grid tag and type canvas Type the following within canvas tag.
<canvas>
<Ellipse width=”200”Height=”200” Stroke=”Red” Stroke Think news=”5” Canvas. top=”20”canvas.left=”40”>
< Ellipse. Fill>
<solid color brush color=”blue”>
</solid color brush>
< /Ellipse>
< Elliple. Fill>
< /Convas>
< Ellipse. Fill>
< Linear Gradient brush>
< Gradient stop offset =”2” color=”Blue”/ >
< Gradient stop offset =”4” color=”yellow”/ >
< Gradient stop offset =”6” color=”Red”/ >
< Gradient stop offset =”7” color=”Green”/ >
< Gradient stop offset =”9” color=”Orange”/ >
< /Linear Gradient brush>
</ Ellipse. Fill>
(or) <Radial gradient Brush>
</Radia L Gradient Brush>
Example on Image Brush
open WPF Application project
ViewàSolution ExploreràRt click on project Name
AddExisting ItemChoose an image Type the following within grid tag
<Grid>
<Text block Text=”Microsoft” Font family=”Arial” Font size=”200”>
<Text block. fore ground>
<Image brush Image source=”Sybset.jpg”>
</Image brush>
</Text block. fore ground>
</text block>
</Grid>
Working with wpf transformations
Trans formation is the concept of moving an object in a particular angle
WPF Supports 3 types of transformations.
Rotate transformation
Skew Transformation
Scale transformation
<control>
< control. Render Transform>
<Rotate Transform . . . . ./>
</control. Render Transform >
</control>
Obs Transformations must be the part of render transform tag.
Open WPF Application project
Replace Grid tag with canvas
< canvas>
<Button width=”100”Height=”60” Convas. Top=”30” Convas. Left=”20”>
click
<Button. Render. Transform>
<Rotate Transform Angle=”45”>
<Rotate Transform>
</Button. Render. Transform>
</Button>
</ Convas >
The syntax for skew Transformation
<Skew Transform Angle x =”50”>
Angle y =”20”></skew Transform >
<canvas> <Button width=”100”Height=”60” > <Scale Transform scale x=”2” scale y=”2”></ scale Transform >
<canvas>
<Control---------->
<Controls. Triggers>
<Event Trigger------>
<Begin story board>
<Story board>
<Double Animation -------->
</Story board>
</Begin Story board >
</Control. Triggers>
</Control>
</Control>
àOpen WPF Application project. Replace Grid with canvas tag top
<canvas>
Ellipse /
<Line x1=”10” y1=”10”x2=”50”y2=”10” Stroke=”RED” Stroke Thickness =”5”> X:Name =”abc”>
Line object name
<Line. Triggers>
<Event Triggers Routed Event= “Convas. Loaded”>
<Begin story board>
<Story board >
<Double Animation Story board . Target name=”abc” Story board Target property=”(canvas. left)” From = “o” To =”800”>
Auto reverse =”True” Repeat Behavior=”Forever” Duration=”00:00:03”>
</Double animation>
</ Story board >
</Begin story board>
</Event Trigger>
</Line. Triggers>
</Line>
</Canvas>
Working with LINQ[Language integrated Query]
C#.NET
Oracle Int[]x=new int[]
Works on tables {7,5,8,2,7,6,1}
All the records From I in x
select I; Select*from emp: select I;
Select*from emp: Where SQL>1000; >5 From i in x where i>5 Select i;
Sorting
SQL Ascending order
From I in x order by I
select * from emp Ascending select I;
order by SQL ASC;
SUM(),Average(),MAX(),Min() etc.
Open windows form application project
place a button
Code for Button 1-click
{
Int[]x=new int[]{4,6,2,6,8,9,1,3};
Strings=””;
//print the values which are>5 Var v=from I in x where i>5 select I;
//Sort the numbers in ascending order.
Var v = from I in x order by I ascending select I;
//printing distinct numbers
Var v=(from in x select i)Distinct();
//printing the sum of the numbers
Int total=x.sum();
Message box. show(total+””);
//Printing the arrange of the numbers
Double total =x. average();
Message box. show(total+””);
For each(int k in v) S=s+k+””;
Message box. show(s);
Place one more button(button2)
code for button2-click
{
Int[]x=new int[]{4,6,2,6,8,9,1,3};
Strings=””;
//print the values which are>5 Var v=from I in x where i>5 select I;
//Sort the numbers in ascending order.
Var v = from I in x order by I ascending select I;
//printing distinct numbers
Var v=(from in x select i)Distinct();
//printing the sum of the numbers
Int total=x.sum();
Message box. show(total+””);
//Printing the arrange of the numbers
Double total =x. average();
Message box. show(total+””);
For each(int k in v) S=s+k+””;
Message box. show(s);
Example: LINQ With a data set
Open windows form application project place a button and a data grid view Using system.
Data. Sql client;
Code for button1-click
{
Sql connection cn = new sql connection (user id=SQ;
Password=;database=north wind; Server = Local host” );
SQL Data Adapter da=new Sql data Adapter (“Select*from products”,cn);
Data set ds= new dataset(); Da. fill(ds, ”d”); Data table dt=ds. Tables[“d”];
Innumerable<data Row>ie=dt. as Enumerable();
IQuery able<data row>dr=i.e. As Query able();
Dr=from I in dr select I;
Dr=from I in dr where i[“Product name”]. To string()==”chai” select I;
Dr=from I in dr where int. parle(i[“product id”]. To string())<5 select I;
Data grid viewl. data sources= dr. copy to data table();
}
You liked the article?
Like: 0
Vote for difficulty
Current difficulty (Avg): Medium
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.