Wednesday, July 19, 2006

guess what, this substantial code works in linux mono c# yipee!!! :D

to compile in mono:


mcs m.cs -r:System.Data -r:System.Windows.Forms -r:System.Drawing

to run:

mono m.exe




-----------------------------------



original article:

http://www.bobpowell.net/dropshadowtext.htm

using System;

using System.Drawing;

using System.Drawing.Text;

using System.Drawing.Drawing2D;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;



namespace textdropshadow

{

///

/// Summary description for Form1.

///


public class Form1 : System.Windows.Forms.Form

{

///

/// Required designer variable.

///


private System.ComponentModel.Container components = null;



public Form1()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();



this.SetStyle(ControlStyles.ResizeRedraw,true);

}



///

/// Clean up any resources being used.

///


protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}



#region Windows Form Designer generated code

///

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

///


private void InitializeComponent()

{

//

// Form1

//

this.AutoScaleBaseSize = new System.Drawing.Size(16, 36);

this.BackColor = System.Drawing.Color.White;

this.ClientSize = new System.Drawing.Size(376, 293);

this.Font = new System.Drawing.Font("Tahoma", 21.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));

this.Name = "Form1";

this.Text = "Form1";

this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);



}

#endregion



///

/// The main entry point for the application.

///


[STAThread]

static void Main()

{

Application.Run(new Form1());

}



protected override void OnPaintBackground(PaintEventArgs e)

{

LinearGradientBrush b=new LinearGradientBrush(this.ClientRectangle,Color.Blue,Color.AliceBlue,90f);

e.Graphics.FillRectangle(b,this.ClientRectangle);

b.Dispose();

}



private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)

{

//Make a small bitmap

Bitmap bm=new Bitmap(this.ClientSize.Width/4,this.ClientSize.Height/4);

//Get a graphics object for it

Graphics g=Graphics.FromImage(bm);

// must use an antialiased rendering hint

g.TextRenderingHint=TextRenderingHint.AntiAlias;

//this matrix zooms the text out to 1/4 size and offsets it by a little right and down

Matrix mx=new Matrix(0.25f,0,0,0.25f,3,3);

g.Transform=mx;

//The shadow is drawn

g.DrawString("Text with a dropshadow",Font,new SolidBrush( Color.FromArgb(128, Color.Black)), 10, 10, StringFormat.GenericTypographic );

//Don’t need this anymore

g.Dispose();

//The destination Graphics uses a high quality mode

e.Graphics.InterpolationMode=InterpolationMode.HighQualityBicubic;

//and draws antialiased text for accurate fitting

e.Graphics.TextRenderingHint=TextRenderingHint.AntiAlias;

//The small image is blown up to fill the main client rectangle

e.Graphics.DrawImage(bm,this.ClientRectangle,0,0,bm.Width,bm.Height,GraphicsUnit.Pixel);

//finally, the text is drawn on top

e.Graphics.DrawString("Text with a dropshadow",Font,Brushes.White,10,10,StringFormat.GenericTypographic);

bm.Dispose();

}

}

}

No comments: