In this article, we draw a rectangle in a web application using TypeScript.
First we download some files in the following attachment:
-
Kinect.d.ts
-
Kinectic.min.js
These files are added to the project, then use the following procedure.
Step 1
Open Visual Studio 2012 and click "File" -> "New" -> "Project...". A window is opened. In this window, click "HTML Application for TypeScript" under Visual C#.
Provide the name of your application as "Draw_Rectangle" and then click ok.
Step 2
After this session the project has been created; a new window is opened on the right side. This window is called the Solution Explorer. The Solution Explorer contains the ts file, js file and CSS file and aspx page.
![solution-explorer.jpg]()
Coding
Rectangle.ts
/// <reference path="Kinect.d.ts" />
class Draw_Rectangle {
Rectangle() {
var stage = new Kinetic.Stage({ container: 'content'});
var layer = new Kinetic.Layer();
var rectangle = new Kinetic.Rect({width:200,height:200,cornerRadius:5,
fill:'Blue',strokeWidth:10,stroke:'Black'});
layer.add(rectangle);
stage.add(layer);
}
}
window.onload = () =>
{
var obj = new Draw_Rectangle();
obj.Rectangle();
};
Rectangle_Demo.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Rectangle_Demo.aspx.cs" Inherits="Draw_Rectangle.Rectangle_Demo" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script src="Rectangle.js"></script>
<script src="Kinetic.min.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>Rectangle In TypeScript Using Web Application</h3>
<div id="content"></div>
</div>
</form>
</body>
</html>
Rectangle.js
/// <reference path="Kinect.d.ts" />
var Draw_Rectangle = (function () {
function Draw_Rectangle() { }
Draw_Rectangle.prototype.Rectangle = function () {
var stage = new Kinetic.Stage({
container: 'content'
});
var layer = new Kinetic.Layer();
var rectangle = new Kinetic.Rect({
width: 200,
height: 200,
cornerRadius: 5,
fill: 'Blue',
strokeWidth: 10,
stroke: 'Black'
});
layer.add(rectangle);
stage.add(layer);
};
return Draw_Rectangle;
})();
window.onload = function () {
var obj = new Draw_Rectangle();
obj.Rectangle();
};
//@ sourceMappingURL=Rectangle.js.map
Output
![rectangle.jpg]()
For more information, download the attached sample application.