Today in Engineer's World,
we are discussing ASP.NET & C# query faced by a developer in very easy way. Posted By- +Manish Kumar Gautam +LIVE VIAR +ASP.NET SOLUTIONS
How to use System.Drawing namespace in Asp.net
C#
In this, article we will learn how to
use System.Drawing
namespace?
There are two ways of using namespace in your project:
(1) Writing the namespace to the top of the web form
(2) Writing namespace to the inline
Note: Color class is present in
the System.Drawing Namespace
Practical
Implementation:
Design Code(Default.aspx)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD
XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblMsg" runat="server"
Text="LIVEVIAR- Education For All"></asp:Label>
</div>
</form>
</body>
</html>
Choice-1:
Writing the namespace to the top of the
web form
Practical Implementation:
Server-Side Code (Default.aspx.cs)
using
System;
using
System.Drawing;
public
partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object
sender, EventArgs e)
{
lblMsg.ForeColor = Color.MediumTurquoise;
}
}
OUTPUT:
Choice-2: Or we can write the complete namespace in the
inline code
Practical
Implementation:
Server-Side Code (Default.aspx.cs)
using
System;
public
partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object
sender, EventArgs e)
{
lblMsg.ForeColor = System.Drawing.Color.MediumTurquoise;
}
}
OUTPUT:
For any query, comment us
below.
Related Questions:
Q-1 Which namespace
declaration choice is good to use and when?
Ans. We knows both are providing
the same result. But, when to use it is really very important.
If you want to use the Drawing Namespace
functionality multiple times, then declare the namespace at the top. Otherwise,
declare it inline code.
Q-2 What is the
use of drawing namespace?
Ans. System.Drawing namespace provides us Graphics Display operations and
functionality. It contains various Classes
include font, image, bitmap, etc., Structures include color, rectangle,
size, etc., Enumerations and Delegates.
Keep
learning and sharing…
No comments:
Post a Comment