CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2002
    Location
    Seattle Area, WA
    Posts
    241

    Helper to beautify your code snapshots here!

    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/co.../vbCodeGen.zip

  2. #2
    Join Date
    Jul 2002
    Location
    Seattle Area, WA
    Posts
    241
    An example:
    Code:
            // 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;
            }

  3. #3
    Join Date
    Jul 2002
    Location
    Seattle Area, WA
    Posts
    241
    Can now be found at http://www.kingtermite.net

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured