Software Development : A dizzy job...keeping abreast and being competitive is a 24X7 involvement
Jun 26, 2007
Jun 20, 2007
C# : Drawing a Pie Chart and saving as jpeg
////Namespace:
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Text;
////Create canvas and fill the background
Bitmap objBitmap;
Graphics objGraphics;
objBitmap = new Bitmap(400, 440);
objGraphics = Graphics.FromImage(objBitmap);
objGraphics.Clear(Color.White);
////Draw the pie and fill
Pen p=new Pen(Color.Yellow,0);
Rectangle rect=new Rectangle(10,10,280,280);
objGraphics.DrawEllipse(p,rect);
Brush b1=new SolidBrush(Color.Red);
Brush b2=new SolidBrush(Color.Green);
Brush b3=new SolidBrush(Color.Blue);
objGraphics.FillPie(b1, rect, 0f, 60f);
objGraphics.FillPie(b2, rect, 60f, 150f);
objGraphics.FillPie(b3, rect, 210f, 150f);
////Draw font
FontFamily fontfml = new FontFamily(GenericFontFamilies.Serif);
Font font = new Font(fontfml, 16);
SolidBrush brush = new SolidBrush(Color.Blue);
objGraphics.DrawString("Drawing Graphics", font, brush, 70, 300);
////Export and save to picture
objBitmap.Save(Response.OutputStream, ImageFormat.Gif);
objBitmap.Save(Server.MapPath("x.jpg"), ImageFormat.Jpeg);
////End drawing
objBitmap.Dispose();
objGraphics.Dispose();
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Text;
////Create canvas and fill the background
Bitmap objBitmap;
Graphics objGraphics;
objBitmap = new Bitmap(400, 440);
objGraphics = Graphics.FromImage(objBitmap);
objGraphics.Clear(Color.White);
////Draw the pie and fill
Pen p=new Pen(Color.Yellow,0);
Rectangle rect=new Rectangle(10,10,280,280);
objGraphics.DrawEllipse(p,rect);
Brush b1=new SolidBrush(Color.Red);
Brush b2=new SolidBrush(Color.Green);
Brush b3=new SolidBrush(Color.Blue);
objGraphics.FillPie(b1, rect, 0f, 60f);
objGraphics.FillPie(b2, rect, 60f, 150f);
objGraphics.FillPie(b3, rect, 210f, 150f);
////Draw font
FontFamily fontfml = new FontFamily(GenericFontFamilies.Serif);
Font font = new Font(fontfml, 16);
SolidBrush brush = new SolidBrush(Color.Blue);
objGraphics.DrawString("Drawing Graphics", font, brush, 70, 300);
////Export and save to picture
objBitmap.Save(Response.OutputStream, ImageFormat.Gif);
objBitmap.Save(Server.MapPath("x.jpg"), ImageFormat.Jpeg);
////End drawing
objBitmap.Dispose();
objGraphics.Dispose();
TableLayoutPanel in C#
The Tablelayoutpanel is a easy way to add Controls in a Tabular format.
////--------Sample code-------
TextBox questionText = new TextBox();
questionText.Text = questionName;
questionText.MouseHover += new EventHandler(Question_MouseHover);
questionText.Width = 200;
questionText.BorderStyle = BorderStyle.FixedSingle;
questionText.BackColor = Color.Black;
questionText.ForeColor = Color.White;
GroupBox grRadios = new GroupBox();
grRadios.Height = 25;
grRadios.Width = 100;
grRadios.Padding = new Padding(2);
grRadios.Tag = questionId.ToString();
grRadios.Text = string.Empty;
RadioButton[] radios = new RadioButton[3];
radios[0] = new RadioButton();
radios[0].Tag = "Yes";
radios[1] = new RadioButton();
radios[1].Tag = "No";
radios[2] = new RadioButton();
radios[2].Tag = "Not Applicable";
////Add a event handler to the radio buttons
for (int i = 0; i < radios.Length; i++)
{
radios[i].Width = 20;
radios[i].MouseHover += new EventHandler(Radio_MouseHover);
if (i == checkedRadio)
{
radios[i].Checked = true;
}
}
grRadios.Controls.AddRange(radios);
radios[0].Left = 0;
radios[0].Top = radios[0].Top;
radios[1].Left = radios[1].Left + 20;
radios[1].Top = radios[0].Top;
radios[2].Left = radios[2].Left + 20;
radios[2].Top = radios[0].Top;
tblQuestions.Controls.Add(questionText);
tblQuestions.Controls.Add(grRadios);
////--------Sample code-------
TextBox questionText = new TextBox();
questionText.Text = questionName;
questionText.MouseHover += new EventHandler(Question_MouseHover);
questionText.Width = 200;
questionText.BorderStyle = BorderStyle.FixedSingle;
questionText.BackColor = Color.Black;
questionText.ForeColor = Color.White;
GroupBox grRadios = new GroupBox();
grRadios.Height = 25;
grRadios.Width = 100;
grRadios.Padding = new Padding(2);
grRadios.Tag = questionId.ToString();
grRadios.Text = string.Empty;
RadioButton[] radios = new RadioButton[3];
radios[0] = new RadioButton();
radios[0].Tag = "Yes";
radios[1] = new RadioButton();
radios[1].Tag = "No";
radios[2] = new RadioButton();
radios[2].Tag = "Not Applicable";
////Add a event handler to the radio buttons
for (int i = 0; i < radios.Length; i++)
{
radios[i].Width = 20;
radios[i].MouseHover += new EventHandler(Radio_MouseHover);
if (i == checkedRadio)
{
radios[i].Checked = true;
}
}
grRadios.Controls.AddRange(radios);
radios[0].Left = 0;
radios[0].Top = radios[0].Top;
radios[1].Left = radios[1].Left + 20;
radios[1].Top = radios[0].Top;
radios[2].Left = radios[2].Left + 20;
radios[2].Top = radios[0].Top;
tblQuestions.Controls.Add(questionText);
tblQuestions.Controls.Add(grRadios);
SQL Server - Parse a delimited string
alter procedure web_ParseArray
( @Array varchar(1000),
@separator char(1) )
AS
-- Created by graz@sqlteam.com
-- Modified to result a table by Bart@prove.be
set nocount on
-- @Array is the array we wish to parse
-- @Separator is the separator charactor such as a comma
declare @separator_position int -- This is used to locate each separator character
declare @array_value varchar(1000) -- this holds each array value as it is returned
create table #ParsedArrays (array_Value varchar(1000))
-- For my loop to work I need an extra separator at the end. I always look to the
-- left of the separator character for each array value
set @array = @array + @separator
-- Loop through the string searching for separtor characters
while patindex('%' + @separator + '%' , @array) <> 0
begin
-- patindex matches the a pattern against a string
select @separator_position = patindex('%' + @separator + '%' , @array)
select @array_value = left(@array, @separator_position - 1)
-- This is where you process the values passed.
-- Replace this select statement with your processing
-- @array_value holds the value of this element of the array
insert #ParsedArrays VALUES (@array_value)
-- This replaces what we just processed with and empty string
select @array = stuff(@array, 1, @separator_position, '')
end
set nocount off
select * from #ParsedArrays
drop table #ParsedArrays
go
Subscribe to:
Posts (Atom)