473,472 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

want to create custom control using graphics

Hi All,

I want to create a webcontrol which will generate a bar (bar chart). I
have done some graphics code in my ASPX page and it's working fine, but
how do i create a Custom Control or User Control for same (custom
control is prefarable).

Below is my code of ASPX page which is working fine....
Here i have used Response, to generate the bar but how do i use it in
the webcontrols...

Thanks & Regards,
Rushikesh

CODE:

<%@ Page Language="C#" debug="true"%>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>

<script language="C#" runat="server">

void Page_Load(Object sender, EventArgs e)
{
Bitmap objBitmap = new Bitmap(200,200);

Graphics objGraphic = Graphics.FromImage(objBitmap);

SolidBrush redBrush = new SolidBrush(Color.Red);
SolidBrush blueBrush = new SolidBrush(Color.Blue);
SolidBrush greenBrush = new SolidBrush(Color.Green);
SolidBrush whiteBrush = new SolidBrush(Color.White);
Pen blackPen = new Pen(Color.Black, 2);

objGraphic.FillRectangle(whiteBrush, 0, 0, 200, 200);

objGraphic.DrawLine(blackPen, new Point(0,195), new Point(195,195));
objGraphic.DrawLine(blackPen, new Point(5,5), new Point(5,200));

Single sngHighestValue, sngHeight1, sngHeight2, sngHeight3;
Single sngValue1, sngValue2, sngValue3;

sngValue1 = Convert.ToSingle(Request["v1"]);
sngValue2 = Convert.ToSingle(Request["v2"]);
sngValue3 = Convert.ToSingle(Request["v3"]);

if (sngValue1 > sngValue2)
sngHighestValue = sngValue1;
else
sngHighestValue = sngValue2;

if (sngValue3 > sngHighestValue)
sngHighestValue = sngValue3;

if (sngHighestValue == 0)
sngHighestValue = 1;

sngHeight1 = (sngValue1 / sngHighestValue) * 190;
sngHeight2 = (sngValue2 / sngHighestValue) * 190;
sngHeight3 = (sngValue3 / sngHighestValue) * 190;

objGraphic.FillRectangle(redBrush, 10, 194-sngHeight1, 50,
sngHeight1);
objGraphic.FillRectangle(blueBrush, 70, 194-sngHeight2, 50,
sngHeight2);
objGraphic.FillRectangle(greenBrush, 130, 194-sngHeight3, 50,
sngHeight3);

Response.ContentType = "image/gif";

objBitmap.Save (Response.OutputStream, ImageFormat.Gif);

}

</script>

Thanks
Rushikesh

Mar 29 '06 #1
2 1513
Hi Rushikesh,

You could also put an image tag on an ASPX and use as source the path to
the aspx that generates the image.
--
Ward Bekker
"Asp.Net Discussions for the Professional Developer"
http://www.dotnettaxi.com

"Free .Net 2.0 C# to/from VB.Net Code Converter"
http://www.dotnettaxi.com/Tools/Converter.aspx
Mar 29 '06 #2
Hi Ward,

Thankyou for your quick response,

Yes you are right, but i want to generate this image based on some
parameter. I want to pass the parameters in Array form and based on
that i want to create the image and because of that i want to create a
control.

Is there anyother way around?

thanks & regards
rushikesh

Mar 29 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Sagaert Johan | last post by:
I have made a custom control that draws a rectangle when the mouse is down, and does nothing when the mouse is up. I set/reset a flag in MouseDown/Mouse up and use this to do the drawing in the...
2
by: anand | last post by:
Hi all, I have created a custom control which displays Image using Graphics.. I am using this control in a different windows application. I am dynamically creating the control and putting that...
1
by: Dan Bass | last post by:
I've got a custom control that makes use of DrawString and DrawBezier, drawn from the graphics object passed by in the PaintEventArgs for the Paint event. I've not printed anything via c#...
3
by: Richard Skopal | last post by:
In .NET Windows forms I can create a metafile using this code: Graphics grph = aControl.CreateGraphics(); IntPtr ipHDC = grph.GetHdc(); Metafile mf = new Metafile(aImgFilePath, ipHDC,...
1
by: Brian Henry | last post by:
I am trying to make a custom user control that gets a list of users from our database and populates the list, its an owner drawn control also, the problem is, I placed the item onto a form and...
0
by: Brian Henry | last post by:
Ok I've never implemented a snap location before so I dont really know what im doing wrong here... anyways, I am making a custom slider control that takes dates as its values instead of integers......
3
by: Dean Craig | last post by:
I'm working with the new ASP.NET AJAX Control Toolkit. I have a map that has several key areas (hot spots) where when the user hovers over them, I want to pop up a small window with information in...
2
by: Ron | last post by:
I would like some more information on custom controls, what they can do and things like that, what you would use them for etc... Can anyone here share some examples of what you have used a custom...
11
by: Mark B | last post by:
I want to display a pre-designed graphical 'performance badge' on certain webpages (round, about 2cm diameter) next to a salesperson's details. I have a function,...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.