Click here to Skip to main content
15,901,373 members
Home / Discussions / C#
   

C#

 
Questionodbc firebird C# Pin
mark_me5-May-09 16:03
mark_me5-May-09 16:03 
AnswerRe: odbc firebird C# Pin
Giorgi Dalakishvili5-May-09 20:03
mentorGiorgi Dalakishvili5-May-09 20:03 
QuestionEasy way to create a save/load functionality to an Application Pin
sodevrom5-May-09 13:47
sodevrom5-May-09 13:47 
AnswerRe: Easy way to create a save/load functionality to an Application Pin
Dave Kreskowiak5-May-09 17:23
mveDave Kreskowiak5-May-09 17:23 
QuestionWinForms Comboboxes Pin
Illegal Operation5-May-09 13:32
Illegal Operation5-May-09 13:32 
AnswerRe: WinForms Comboboxes Pin
dotnetmember5-May-09 16:42
dotnetmember5-May-09 16:42 
AnswerRe: WinForms Comboboxes Pin
Mycroft Holmes5-May-09 17:24
professionalMycroft Holmes5-May-09 17:24 
QuestionTo Dispose() or not Dispose(), that is the question. Pin
Peter Trevor5-May-09 13:02
Peter Trevor5-May-09 13:02 
Okay, I’m confused on what to Dispose and when. Below is a subroutine called from a loop. First time through it is okay, the second time through it throws a System.Exception “Parameter is not valid” on the DrawString line. But if I remove all the Dispose commands at the bottom I can call this subroutine a dozen times without error.

Obviously in this instance I can just remove the Dispose commands and move on but I want to understand when I should or shouldn’t call Dispose. (After all I might be missing some Dispose calls elsewhere in my program.)

private void DrawRotatedText(Graphics Canvas, string text, Rectangle DestRect)
{
    //Create temp workspace
    Bitmap bmp = new Bitmap(500, 500, PixelFormat.Format64bppArgb);
    Graphics g = Graphics.FromImage(bmp);
    g.Clear(Color.White);

    //Write on it
    Font font = new Font("Arial", 12, FontStyle.Regular, GraphicsUnit.Pixel);
    Brush brush = Brushes.Black;
    StringFormat stringFormat = new StringFormat();
    stringFormat.Alignment = StringAlignment.Center;
    stringFormat.LineAlignment = StringAlignment.Center;
    g.DrawString(text, font, brush, (bmp.Width / 2), (bmp.Height / 2), stringFormat);

    //Rotate image here
    Bitmap bmp2 = Rotator.RotateImage(bmp, (360 - 45));

    // Set the transparency color key based on the upper-left pixel of the image.
    ImageAttributes attr = new ImageAttributes();
    attr.SetColorKey(bmp.GetPixel(0, 0), bmp.GetPixel(0, 0));

    // Draw the image using the image attributes.
    Rectangle SrcRect = new Rectangle((bmp2.Width / 2) - (DestRect.Width / 2),
      (bmp2.Height / 2) - (DestRect.Height / 2), DestRect.Width, DestRect.Height);
    Canvas.DrawImage(bmp2, DestRect, SrcRect.Left, SrcRect.Top, SrcRect.Width,
      SrcRect.Height, GraphicsUnit.Pixel, attr);

    //Tidy up
    bmp.Dispose();
    font.Dispose();
    brush.Dispose();
    stringFormat.Dispose();
    bmp2.Dispose();
    attr.Dispose();
    g.Dispose();
}

AnswerRe: To Dispose() or not Dispose(), that is the question. Pin
Luc Pattyn5-May-09 13:25
sitebuilderLuc Pattyn5-May-09 13:25 
GeneralRe: To Dispose() or not Dispose(), that is the question. Pin
fly9045-May-09 14:22
fly9045-May-09 14:22 
GeneralRe: To Dispose() or not Dispose(), that is the question. Pin
Luc Pattyn5-May-09 14:47
sitebuilderLuc Pattyn5-May-09 14:47 
JokeRe: To Dispose() or not Dispose(), that is the question. Pin
fly9045-May-09 15:24
fly9045-May-09 15:24 
GeneralRe: To Dispose() or not Dispose(), that is the question. Pin
Luc Pattyn5-May-09 15:42
sitebuilderLuc Pattyn5-May-09 15:42 
QuestionExpose Property of Constituent Control in UserControl Pin
xfitr25-May-09 11:18
xfitr25-May-09 11:18 
AnswerRe: Expose Property of Constituent Control in UserControl Pin
Christian Graus5-May-09 12:26
protectorChristian Graus5-May-09 12:26 
GeneralRe: Expose Property of Constituent Control in UserControl Pin
xfitr26-May-09 3:47
xfitr26-May-09 3:47 
JokeSolve this...... Pin
Rajdeep.NET is BACK5-May-09 9:09
Rajdeep.NET is BACK5-May-09 9:09 
GeneralRe: Solve this...... Pin
Luc Pattyn5-May-09 9:19
sitebuilderLuc Pattyn5-May-09 9:19 
GeneralRe: Solve this...... Pin
harold aptroot5-May-09 9:27
harold aptroot5-May-09 9:27 
RantRe: Solve this...... Pin
fly9045-May-09 9:25
fly9045-May-09 9:25 
GeneralRe: Solve this...... Pin
harold aptroot5-May-09 9:30
harold aptroot5-May-09 9:30 
GeneralRe: Solve this...... Pin
EliottA5-May-09 11:24
EliottA5-May-09 11:24 
GeneralRe: Solve this...... Pin
Dave Kreskowiak5-May-09 9:59
mveDave Kreskowiak5-May-09 9:59 
GeneralRe: Solve this...... Pin
CPallini5-May-09 10:53
mveCPallini5-May-09 10:53 
GeneralRe: Solve this...... Pin
Pete O'Hanlon5-May-09 11:22
mvePete O'Hanlon5-May-09 11:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.