Click to See Complete Forum and Search --> : Helper to beautify your code snapshots here!


KingTermite
May 26th, 2003, 07:49 AM
Ok....I have been learning C#.NET all new and posting as various problems/questions arose lately.

Here is the result. I did this really just as a fun project for another website I frequent who happens to also use vBulletin boards (just like these codeguru boards).

vBulletin uses vBCode formatting or pseudo-Html to format color, bold, etc....


Here is a zip of my project's executable which you can use to copy the code (which in Visual Studio is in RTF format to show the syntax highlighting) and convert it to vBCode so that when you post a code sample, it maintains the syntax highlighting and is much more readable.

Hope you enjoy.

-----------------
Ok....attach file size is too small (100 K ? Come on mods...that's not big enough to attach anything).

Ok...I'll host it at this location (which may die one day before long as its a school account which I have graduated from already).

http://www.csee.usf.edu/~chartier/codeguru/vbCodeGen.zip

KingTermite
May 26th, 2003, 07:52 AM
An example:
// DrawItem override for the AddSmiley context menu item owner draw
private void DrawAddSmileyMenuItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
MenuItem mi = (MenuItem)sender;

// Default menu font
Font menuFont = SystemInformation.MenuFont ;
SolidBrush menuBrush = null ;

// Determine menu brush for painting
if ( mi.Enabled == false )
{
// disabled text
menuBrush = new SolidBrush( SystemColors.GrayText ) ;
}
else
{
if ( (e.State & DrawItemState.Selected) != 0)
{
// Text color when selected (highlighted)
menuBrush = new SolidBrush( SystemColors.HighlightText ) ;
}
else
{
// Text color during normal drawing
menuBrush = new SolidBrush( SystemColors.MenuText ) ;
}
}

// Center the text portion (out to side of image portion)
StringFormat strfmt = new StringFormat();
strfmt.LineAlignment = System.Drawing.StringAlignment.Center;

// Smiley #2 is the image
CSmilies oSmile = new CSmilies(2);
Bitmap bmSmiley = new Bitmap(typeof(vBCodeGenForm),oSmile.SmileyIconFileName);

// Rectangle for image portion
Rectangle rectImage = e.Bounds;

// Set image rectangle same dimensions as image
rectImage.Width = bmSmiley.Width;
rectImage.Height = bmSmiley.Height;
Rectangle rectText = e.Bounds;
rectText.X += rectImage.Width;

// Start Drawing the menu rectangle

// Fill rectangle with proper background [use this instead of e.DrawBackground() ]
if ( (e.State & DrawItemState.Selected) != 0)
{
e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds); }
else
{
e.Graphics.FillRectangle(SystemBrushes.Menu, e.Bounds);
}

e.Graphics.DrawImage(bmSmiley, rectImage);
e.Graphics.DrawString( mi.Text, menuFont, menuBrush, e.Bounds.Left + bmSmiley.Width, e.Bounds.Top + ((e.Bounds.Height - menuFont.Height) / 2), strfmt ) ;
}


// Measure Item override for the AddSmiley context menu item owner draw
private void MeasureItemAddSmileyMenuItem(object obj, MeasureItemEventArgs miea)
{
MenuItem mi = (MenuItem)obj;
Font menuFont = SystemInformation.MenuFont ;
StringFormat strfmt = new StringFormat();
SizeF sizef = miea.Graphics.MeasureString(mi.Text, menuFont, 1000, strfmt);

// Smiley #2 is the eBeer image
CSmilies oSmile = new CSmilies(2);
Bitmap bmSmiley = new Bitmap(typeof(vBCodeGenForm),oSmile.SmileyIconFileName);

miea.ItemWidth = (int)Math.Ceiling(sizef.Width) + bmSmiley.Width;
miea.ItemHeight = (int)Math.Ceiling(sizef.Height) + bmSmiley.Height;
}

KingTermite
June 1st, 2003, 01:04 PM
Can now be found at http://www.kingtermite.net