Archive for ASP.NET

Replicating a Tree table

Replicating a Tree table

source: http://www.maxdesign.com.au/presentation/tree-table/

Aim

The aim is to replicate a graphic table tree using HTML. This was based on a request from a Web Standards Group member. Posted here in case it is of use to someone else :)

Graphic example of a table tree

HTML example of a table tree

Name Location Color
House
Carrion Fly Worldwide gray
Office Fly California, Bay Area white
Common House Fly brown
Horse
Horn Fly Kansas red
Face Fly green
Stable Fly black

HTML code

<table summary="folder contents for fly types">
<thead>
<tr>
<th class="name">Name</th>
<th class="location">Location</th>
<th class="color">Color</th>
</tr>
</thead>
<tbody>
<tr>
<th colspan="3">House</th>
</tr>
<tr>
<th class="start">Carrion Fly</th>
<td>Worldwide</td>
<td>gray</td>
</tr>
<tr>
<th class="start">Office Fly</th>
<td>California, Bay Area</td>
<td>white</td>
</tr>
<tr>
<th class="end">Common House Fly</th>
<td></td>
<td>brown</td>
</tr>
<tr>
<th colspan="3">Horse</th>
</tr>
<tr>
<th class="start">Horn Fly</th>
<td>Kansas</td>
<td>red</td>
</tr>
<tr>
<th class="start">Face Fly</th>
<td></td>
<td>green</td>
</tr>
<tr class="end">
<th class="end">Stable Fly</th>
<td></td>
<td>black</td>
</tr>
</tbody>
</table>

CSS code

body
{
font-family: arial, helvetica, sans-serif;
}

table
{
border-collapse: collapse;
margin-bottom: 3em;
font-size: 70%;
line-height: 1.1;
}

tr:hover, td.start:hover, td.end:hover
{
background: #FF9;
}

th, td
{
padding: .3em .5em;
}

th
{
font-weight: normal;
text-align: left;
background: url(arrow.gif) no-repeat 2px 50%;
padding-left: 15px;
}

th.name { width: 12em; }
th.location { width: 12em; }
th.color { width: 10em; }

thead th
{
background: #c6ceda;
border-color: #fff #fff #888 #fff;
border-style: solid;
border-width: 1px 1px 2px 1px;
padding-left: .5em;
}

tbody th.start
{
background: url(dots.gif) 18px 54% no-repeat;
padding-left: 26px;
}

tbody th.end
{
background: url(dots2.gif) 18px 54% no-repeat;
padding-left: 26px;
}

Leave a Comment

Accessing ASP.NET Web Services with d…

Accessing ASP.NET Web Services with dojo.xhrGet

So I’ve been using the Dojo toolkit for a while now, but mainly for the Dijit and DojoX UI components. For the actual Ajax communication layer, I’ve been relying on the Microsoft Ajax framework because of it’s seamless integration with the ASP.NET Web Service model. Since I’ve got the whole mess of Dojo already being loaded into the browser, I figured I should drop the crutches, and work out how to work directly with the Dojo ajax framework.

The one downside of this is that you no longer get the client side proxies for your ASP.NET Web Services. Thus today’s article – how to directly access an ASP.NET JSON Web Service using dojo.xhrGet.

Part 1: Create a Web Service

This is pretty simple – just add a web service to your web site. I tend to put the code right in the asmx file, rather than in the code-behind in app_code, but that’s just personal preference.

<%@ WebService Language="C#" Class="ASPWebService" %>
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class ASPWebService  : System.Web.Services.WebService {

    [WebMethod]
 public string SayHello() {
 return "Hello to Dojo " + DateTime.Now.ToLongDateString();
 }
 }

By default your web service will be configured to “speak” SOAP, which is fine if you are consuming it from another application, but for Ajax based browser apps, it’s much easier to work with JSON.

Part 2: JSON-ify the Web Service

This is actually really simple – just include System.Web.Script.Services, and the [ScriptService] attribute to the web service as shown below.

<%@ WebService Language="C#" Class="ASPWebService" %>
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class ASPWebService  : System.Web.Services.WebService {

    [WebMethod]
 [ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet=true)]
 public string SayHello() {
 return "Hello to Dojo " + DateTime.Now.ToLongDateString();
 }   }

We also add a [ScriptMethod] attribute to the WebMethod. We do this for two reasons – first, we want to specify that the response format should be JSON, and we also want to allow access to this method via http Get’s (this is disabled by default).

At this point you can hit the web service in your web browser, and get the standard Web Service browser. But if you also stick /js on the end of the url, you will get the client side Javascript that integrates with the MS Ajax Framework. But we’re trying to work with Dojo, so we’ll move on…

Part 3: Testing the Service in a Browser

Our simple “SayHello” web method does not take any arguments, so we should be able to just “GET” it via a browser.

The tricky bit that took me some time to sleuth down was that you also need to edit web.config to tell the web service to respond to all Gets and Posts. Add this section (just copy out the parts you are missing – do not paste this whole thing into your web.config or you will get an error!):

 <system.web>
 <webServices>
 <protocols>
 <add name="HttpGet"/>
 <add name="HttpPost"/>
 </protocols>
 </webServices>
</system.web>

Once you do this, you will get the response back. Despite the fact that we have used the [ScriptMethod] attribute to specify that the SayHello web method should return Json, this will only occur if you sent the request content-type to “application/json; charset=utf-8″. Without that, you’ll still get xml.

Part 4: Create a Simple Page

For this, I created about the simplest page I could – just a button and a div that will be updated. Here’s the whole page…

<!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>
 <title>Dojo to ASP.NET WebServices</title>
 <script type="text/javascript"
 src="http://o.aolcdn.com/dojo/1.1.1/dojo/dojo.xd.js"
 djConfig="parseOnLoad:true, isDebug:true">
</script>
 <script type="text/javascript">
 function updateSampleOne(){
 var contentNode = dojo.byId("sampleone");
 dojo.xhrGet({
 url: "./ASPWebService.asmx/SayHello",
 handleAs: "json",
 contentType: "application/json; charset=utf-8",
 load: function(data,args){contentNode.innerHTML = data.d;},
 error: function(error,args){console.warn("error!",error);}
 });
 };
 </script>
 </head>
<body>
<h1>Using Dojo to Consume ASP.NET JSON WebServices</h1>
<input id="btGetString" type="button"
 value="Update" onclick="updateSampleOne();" />
<div id="sampleone">This will update</div>
</body>
</html>

Breaking down the dojo code…

var contentNode = dojo.byId(“sampleone”);

This simply get’s a the div that we’ll be updating.

dojo.xhrGet({
 url: "./ASPWebService.asmx/SayHello",
 handleAs: "json",
 contentType: "application/json; charset=utf-8",
 load: function(data,args){contentNode.innerHTML = data.d;},
 error: function(error,args){console.warn("error!",error);}
});

This is the actual ajax xhr request. Since we are using a GET, we are using dojo.xhrGet.

The Url of our web service is the asmx file followed by the name of the web method. Since it’s located in the same folder as this html file, we reference it as ./ASPWebService.asmx/SayHello.

The response will be json, so we set handleAs to json

We set the contentType to “application/json; charset=utf-8″ as per the ASP.NET security requirements.

When the response returns, we need to do something with it, this is where load comes in. Dojo uses anonymous functions a lot, and for a simple situation like this, it’s pretty easy to follow. The returned JSON is:

{“d”:”Hello to Dojo Tuesday, June 03, 2008″}.

So we set the contentNode.innerHTML is set to data.d

Should an error occur, the error function is called.

Summary:

So – while this is a little more convoluted than just using the MS Ajax client library and the Script Manager, it does save us from loading multiple client-side frameworks. Since I’m using Dojo for many other UI components, it seemed a waste to also drag along MS Ajax when this is a viable alternative.

One may ask why use the ASP.NET Web Services model? Well, from the server side it’s pretty easy to work with. Once a service is created you can access it via Json or SOAP. They are also easy to unit test.

I’ll likely extend this with some more complex examples – like submitting a form, or sending / receiving complex types, but I’ll leave it here for now.

Download the sample code

Comments (3)

Exposing Web Services to Client Scrip…

Accessing ASP.NET Web Services with dojo.xhrGet

So I’ve been using the Dojo toolkit for a while now, but mainly for the Dijit and DojoX UI components.  For the actual Ajax communication layer,  I’ve been relying on the Microsoft Ajax framework because of it’s seamless integration with the ASP.NET Web Service model. Since I’ve got the whole mess of Dojo already being loaded into the browser, I figured I should drop the crutches, and work out how to work directly with the Dojo ajax framework.

The one downside of this is that you no longer get the client side proxies for your ASP.NET Web Services. Thus today’s article – how to directly access an ASP.NET JSON Web Service using dojo.xhrGet.

Part 1: Create a Web Service

This is pretty simple – just add a web service to your web site. I tend to put the code right in the asmx file, rather than in the code-behind in app_code, but that’s just personal preference.

<%@ WebService Language="C#" Class="ASPWebService" %>using System;using System.Web;using System.Web.Services;using System.Web.Services.Protocols;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class ASPWebService  : System.Web.Services.WebService {

    [WebMethod]
public string SayHello() {        
return "Hello to Dojo " + DateTime.Now.ToLongDateString();
}
}

By default your web service will be configured to “speak” SOAP, which is fine if you are consuming it from another application, but for Ajax based browser apps, it’s much easier to work with JSON.

Part 2: JSON-ify the Web Service

This is actually really simple – just include System.Web.Script.Services, and the [ScriptService] attribute to the web service as shown below.

<%@ WebService Language="C#" Class="ASPWebService" %>
using System;using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class ASPWebService  : System.Web.Services.WebService {

    [WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet=true)]
public string SayHello() {        
return "Hello to Dojo " + DateTime.Now.ToLongDateString();
}
}

We also add a [ScriptMethod] attribute to the WebMethod. We do this for two reasons – first, we want to specify that the response  format should be JSON, and we also want to allow access to this method via http Get’s (this is disabled by default).

At this point you can hit the web service in your web browser, and get the standard Web Service browser. But if you also stick /js on the end of the url, you will get the client side Javascript that integrates with the MS Ajax Framework. But we’re trying to work with Dojo, so we’ll move on…

Part 3: Testing the Service in a Browser

Our simple “SayHello” web method does not take any arguments, so we should be able to just “GET” it via a browser.

The tricky bit that took me some time to sleuth down was that you also need to edit web.config to tell the web service to respond to all Gets and Posts. Add this section (just copy out the parts you are missing – do not paste this whole thing into your web.config or you will get an error!):

 <system.web>
 <webServices>
 <protocols>
 <add name="HttpGet"/>
 <add name="HttpPost"/>
 </protocols>
 </webServices>
</system.web>

Once you do this, you will get the response back. Despite the fact that we have used the [ScriptMethod] attribute to specify that the SayHello web method should return Json, this will only occur if you sent the request content-type to “application/json; charset=utf-8″. Without that, you’ll still get xml.

Part 4: Create a Simple Page

For this, I created about the simplest page I could – just a button and a div that will be updated. Here’s the whole page…

<!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>
<title>Dojo to ASP.NET WebServices</title>
<script type="text/javascript"
src="http://o.aolcdn.com/dojo/1.1.1/dojo/dojo.xd.js"         
djConfig="parseOnLoad:true, isDebug:true">
</script>
<script type="text/javascript">
function updateSampleOne(){
 var contentNode = dojo.byId("sampleone");
 dojo.xhrGet({
url: "./ASPWebService.asmx/SayHello",
 handleAs: "json",
contentType: "application/json; charset=utf-8",
load: function(data,args){contentNode.innerHTML = data.d;},
error: function(error,args){console.warn("error!",error);}
});    

};     </script>    <
/head>
<body>
<h1>Using Dojo to Consume ASP.NET JSON WebServices</h1>
<input id="btGetString" type="button" value="Update" onclick="updateSampleOne();" />
<div id="sampleone">This will update</div>
</body>
</html>

Breaking down the dojo code…

var contentNode = dojo.byId(“sampleone”);

This simply get’s a the div that we’ll be updating.

dojo.xhrGet({
url: "./ASPWebService.asmx/SayHello",
handleAs: "json",
contentType: "application/json; charset=utf-8",
load:
     function(data,args){contentNode.innerHTML = data.d;},
error: function(error,args){console.warn("error!",error);}});

This is the actual ajax xhr request. Since we are using a GET, we are using dojo.xhrGet.

The Url of our web service is the asmx file followed by the name of the web method. Since it’s located in the same folder as this html file, we reference it as ./ASPWebService.asmx/SayHello.

The response will be json, so we set handleAs to json

We set the contentType to “application/json; charset=utf-8″ as per the ASP.NET security requirements.

When the response returns, we need to do something with it, this is where load comes in. Dojo uses anonymous functions a lot, and for a simple situation like this, it’s pretty easy to follow. The returned JSON is:

{“d”:”Hello to Dojo Tuesday, June 03, 2008″}.

So we set the contentNode.innerHTML is set to data.d

Should an error occur, the error function is called.

Summary:

So – while this is a little more convoluted than just using the MS Ajax client library and the Script Manager, it does save us from loading multiple client-side frameworks. Since I’m using Dojo for many other UI components, it seemed a waste to also drag along MS Ajax when this is a viable alternative.

One may ask why use the ASP.NET Web Services model? Well, from the server side it’s pretty easy to work with. Once a service is created you can access it via Json or SOAP. They are also easy to unit test.

I’ll likely extend this with some more complex examples – like submitting a form, or sending / receiving complex types, but I’ll leave it here for now.

Download the sample code

Comments (1)

Windows Server 2003 Training CD-ROM 70-270 70-290 70-291 70-293 70-294 70-297 70-298 70-228 70-284

http://img299.imageshack.us/img299/8271/mcse03gj2.jpg


Installing, Configuring, and Administering Windows XP Pro 70-270 2CDS

http://www.microsoft.com/learning/en/us/exams/70-270.mspx

Schedule our instructor led classroom training at your convenience and never miss another lecture or fall behind. You are in complete control. We have invited the Best Microsoft Trainers in the industry to help us develop the ultimate training and certification program which includes everything you will need to fully prepare for the Microsoft certification exams.

Microsoft Windows XP Professional is the next version of the Windows operating system designed for businesses of all sizes. In this course, expert instructor Kevin Wolford uses real world scenarios to help corporate network administrators learn the new features of Windows XP Professional, the biggest Windows operating systems upgrade since Windows 95. At the conclusion of this course you will understand the best practices for deploying Windows XP Professional in a Windows 2000 environment.

Managing and Maintaining a Windows 2003 Network 70-290

http://www.microsoft.com/learning/en/us/exams/70-290.mspx

Schedule our instructor led classroom training at your convenience and never miss another lecture or fall behind. You are in complete control. We have invited the Best Microsoft Trainers in the industry to help us develop the ultimate training and certification program which includes everything you will need to fully prepare for the Microsoft certification exams.

Our multimedia instructor-led CBT MCSE 70-290 course provides students with the knowledge and skills to manage accounts and resources in a Microsoft Windows Server 2003 environment. The course is intended for systems administrator and systems engineer candidates who are responsible for managing accounts and resources. These tasks include managing user, computer, and group accounts; managing access to network resources; managing printers; managing an organizational unit in a network based on Active Directory service; and implementing Group Policy to manage users and computers. This is the first course in the Systems Administrator and Systems Engineer tracks for Windows Server 2003 and serves as the entry point for other courses in the Windows Server 2003 curriculum.

Implement, Manage, and Maintain a Network Infrastructure 70-291

http://www.microsoft.com/learning/en/us/exams/70-291.mspx

Schedule our instructor led classroom training at your convenience and never miss another lecture or fall behind. You are in complete control. We have invited the Best Microsoft Trainers in the industry to help us develop the ultimate training and certification program which includes everything you will need to fully prepare for the Microsoft certification exams.

Our multimedia instructor-led CBT MCSE Exam 70-291 course provides students with the knowledge and skills to implement, manage, and maintain a Microsoft Windows Server 2003 network infrastructure. The course is intended for systems administrator and systems engineer candidates who are responsible for implementing, managing, and maintaining server networking technologies. These tasks include implementing routing; implementing, managing, and maintaining Dynamic Host Configuration Protocol (DHCP), Domain Name System (DNS), and Windows Internet Name Service (WINS); securing Internet Protocol (IP) traffic with Internet Protocol security (IPSec) and certificates; implementing a network access infrastructure by configuring the connections for remote access clients; and managing and monitoring network access.

Plan and Maintain a Server 2003 Network Infrastructure 70-293 2CDs

http://www.microsoft.com/learning/en/us/exams/70-293.mspx

Schedule our instructor led classroom training at your convenience and never miss another lecture or fall behind. You are in complete control. We have invited the Best Microsoft Trainers in the industry to help us develop the ultimate training and certification program which includes everything you will need to fully prepare for the Microsoft certification exams.

Our multimedia instructor-led CBT MCSE 70-293 course is to provide students with the knowledge and skills necessary to plan and maintain a Windows Server 2003 network infrastructure. This course is appropriate for individuals employed as or seeking a position as a systems engineer. This course is also appropriate for individuals currently supporting a competitive platform who want to enhance their job skills on Microsoft Windows Server 2003 networking. Plan, Implement, & Maintain an Active Directory Infrastructure 70-294

http://www.microsoft.com/learning/en/us/exams/70-294.mspx

Schedule our instructor led classroom training at your convenience and never miss another lecture or fall behind. You are in complete control. We have invited the Best Microsoft Trainers in the industry to help us develop the ultimate training and certification program which includes everything you will need to fully prepare for the Microsoft certification exams.

Our multimedia instructor-led CBT MCSE 70-294 provides students with the knowledge and skills to successfully plan, implement, and troubleshoot a Microsoft Windows Server 2003 Active Directory service infrastructure. The course focuses on a Windows Server 2003 directory service environment, including forest and domain structure, Domain Name System (DNS), site topology and replication, organizational unit structure and delegation of administration, Group Policy, and user, group, and computer account strategies.

Design Server 2003 Active Directory and Network Infrastructure 70-297

http://www.microsoft.com/learning/en/us/exams/70-297.mspx

Schedule our instructor led classroom training at your convenience and never miss another lecture or fall behind. You are in complete control. We have invited the Best Microsoft Trainers in the industry to help us develop the ultimate training and certification program which includes everything you will need to fully prepare for the Microsoft certification exams.

Our multimedia instructor-led CBT MCSE Exam 70-297 course provides students with the knowledge and skills to design an Active Directory service and network infrastructure for a Microsoft Windows Server 2003 environment. The course is intended for systems engineers who are responsible for designing directory service and/or network infrastructures. This course is intended for individuals who are employed as or seeking employment as a systems engineer in a Windows Server 2003-based environment.

Designing Security for Windows 2003 Network 70-298

http://www.microsoft.com/learning/en/us/exams/70-298.mspx

Schedule our instructor led classroom training at your convenience and never miss another lecture or fall behind. You are in complete control. We invited the Best Microsoft Trainers in the industry to help us develop the ultimate training & certification program which includes everything you will need to fully prepare for the Microsoft certification exams.

Our multi-media instructor-led CBT MCSE Exam 70-298 course provides you with the knowledge and skills to design a secure network infrastructure. Topics include assembling the design team, modeling threats, and analyzing security risks in order to meet business requirements for securing computers in a networked environment. The course encourages decision-making skills through an interactive tool that simulates real-life scenarios that the target audience may encounter. You are given the task of collecting the information and sorting through the details to resolve the given security requirement.

Administer SQL Server 2000 70-228

http://www.microsoft.com/learning/en/us/exams/70-228.mspx

Schedule our instructor led classroom training at your convenience and never miss another lecture or fall behind. You are in complete control. We invited the best SQL Trainers in the industry to help us develop the ultimate training & certification program.

With the SQL Server 2000 Administration training course, network administrators will learn techniques for installing, configuring, and administering SQL Server 2000. Expert instructor Kenneth Mayer’s friendly presentation style makes this complex technical subject matter easy to understand. At the conclusion of this course you’ll be prepared for successful system administration and be ready to pass exam #70-228, which provides core credit toward MCDBA certification and elective credit toward MCSE certification upon successful completion.

Exchange 2003 70-284

http://www.microsoft.com/learning/en/us/exams/70-284.mspx

Schedule our instructor led classroom trainings at your convenience and never miss another lecture or fall behind. You are in complete control. We invited the Best Microsoft Trainers in the industry to help us develop the ultimate training & certification program which includes everything you will need to fully prepare for the Microsoft certification exams.

Our multi-media instructor-led CBT MCSE Exam 70-284 course provides students with the knowledge and skills that are needed to update and support a reliable, secure messaging infrastructure. This infrastructure is used for creating, storing, and sharing information by using Microsoft Exchange Server 2003 in a medium-sized to large-sized (250 to 5,000 seats) messaging environment. This course offers a significant amount of demonstrations, discussions and assessments that assist students in becoming proficient in the skills that are needed to update and support Exchange Server 2003.

FULLY DOWNLOADED AND TESTED BY ME

Download Links

http://rapidshare.com/files/119729528/TO10M123.part01.rar
http://rapidshare.com/files/119740341/TO10M123part02.rar
http://rapidshare.com/files/119741980/TO10M123.part03.rar
http://rapidshare.com/files/119742950/TO10M123.part04.rar
http://rapidshare.com/files/119743273/TO10M123.part05.rar
http://rapidshare.com/files/119745751/TO10M123.part06.rar
http://rapidshare.com/files/119745739/TO10M123.part07.rar
http://rapidshare.com/files/119746189/TO10M123.part08.rar
http://rapidshare.com/files/119746608/TO10M123.part09.rar
http://rapidshare.com/files/119747551/TO10M123.part10.rar
http://rapidshare.com/files/119748453/TO10M123.part11.rar
http://rapidshare.com/files/119785370/TO10M123.part12.rar
http://rapidshare.com/files/120248708/TO10M123.part13.rar
http://rapidshare.com/files/119924070/TO10M123.part14.rar
http://rapidshare.com/files/119924305/TO10M123.part15.rar
http://rapidshare.com/files/119924804/TO10M123.part16.rar
http://rapidshare.com/files/119925243/TO10M123.part17.rar
http://rapidshare.com/files/119925752/TO10M123.part18.rar
http://rapidshare.com/files/119926893/TO10M123.part19.rar
http://rapidshare.com/files/119927427/TO10M123.part20.rar
http://rapidshare.com/files/119927730/TO10M123.part21.rar
http://rapidshare.com/files/119929404/TO10M123.part22.rar
http://rapidshare.com/files/119954534/TO10M123.part23.rar
http://rapidshare.com/files/120249101/TO10M123.part24.rar
http://rapidshare.com/files/119960134/TO10M123.part25.rar
http://rapidshare.com/files/120272035/TO10M123.part26.rar
http://rapidshare.com/files/119958189/TO10M123.part27.rar
http://rapidshare.com/files/119960149/TO10M123.part28.rar
http://rapidshare.com/files/119960740/TO10M123.part29.rar
http://rapidshare.com/files/119961695/TO10M123.part30.rar
Password is www.arabdl.com

Leave a Comment

Create image from Text

The following code create image from text

   1: private Bitmap CreateBitmapImage(string sImageText)
   2: {
   3:     Bitmap objBmpImage = new Bitmap(1, 1);
   4:
   5:     int intWidth = 0;
   6:     int intHeight = 0;
   7:
   8:     // Create the Font object for the image text drawing.
   9:     Font objFont = new Font(“Arial”, 20, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel);
  10:
  11:     // Create a graphics object to measure the text’s width and height.
  12:     Graphics objGraphics = Graphics.FromImage(objBmpImage);
  13:
  14:     // This is where the bitmap size is determined.
  15:     intWidth = (int)objGraphics.MeasureString(sImageText, objFont).Width;
  16:     intHeight = (int)objGraphics.MeasureString(sImageText, objFont).Height;
  17:
  18:     // Create the bmpImage again with the correct size for the text and font.
  19:     objBmpImage = new Bitmap(objBmpImage, new Size(intWidth, intHeight));
  20:
  21:     // Add the colors to the new bitmap.
  22:     objGraphics = Graphics.FromImage(objBmpImage);
  23:
  24:     // Set Background color
  25:     objGraphics.Clear(Color.White);
  26:     objGraphics.SmoothingMode = SmoothingMode.AntiAlias;
  27:     objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;
  28:     objGraphics.DrawString(sImageText, objFont, new SolidBrush(Color.FromArgb(102, 102, 102)), 0, 0);
  29:     objGraphics.Flush();
  30:
  31:     return (objBmpImage);
  32: }

Leave a Comment