Click here to Skip to main content
15,911,474 members
Home / Discussions / C#
   

C#

 
AnswerRe: About Keyword in .NET Pin
DaveyM6921-May-10 22:54
professionalDaveyM6921-May-10 22:54 
AnswerRe: About Keyword in .NET Pin
OriginalGriff21-May-10 23:07
mveOriginalGriff21-May-10 23:07 
GeneralRe: About Keyword in .NET Pin
Isaac Gordon21-May-10 23:21
Isaac Gordon21-May-10 23:21 
GeneralRe: About Keyword in .NET Pin
Pete O'Hanlon21-May-10 23:58
mvePete O'Hanlon21-May-10 23:58 
GeneralRe: About Keyword in .NET Pin
OriginalGriff22-May-10 0:09
mveOriginalGriff22-May-10 0:09 
GeneralRe: About Keyword in .NET Pin
harold aptroot22-May-10 0:24
harold aptroot22-May-10 0:24 
GeneralRe: About Keyword in .NET Pin
OriginalGriff22-May-10 0:35
mveOriginalGriff22-May-10 0:35 
GeneralRe: About Keyword in .NET Pin
Isaac Gordon22-May-10 0:55
Isaac Gordon22-May-10 0:55 
GeneralRe: About Keyword in .NET Pin
Pete O'Hanlon22-May-10 2:10
mvePete O'Hanlon22-May-10 2:10 
GeneralRe: About Keyword in .NET Pin
OriginalGriff22-May-10 2:24
mveOriginalGriff22-May-10 2:24 
AnswerRe: About Keyword in .NET Pin
Abhinav S22-May-10 0:28
Abhinav S22-May-10 0:28 
QuestionInserting multiple IDs in Items table but the same ID should go into MasterRequest table just once. Pin
Omar Akhtar 200921-May-10 20:51
Omar Akhtar 200921-May-10 20:51 
AnswerRe: Inserting multiple IDs in Items table but the same ID should go into MasterRequest table just once. Pin
Mohsiul Haque21-May-10 22:46
Mohsiul Haque21-May-10 22:46 
GeneralRe: Inserting multiple IDs in Items table but the same ID should go into MasterRequest table just once. Pin
Omar Akhtar 200922-May-10 1:57
Omar Akhtar 200922-May-10 1:57 
GeneralIt Works! Pin
Roger Wright21-May-10 18:33
professionalRoger Wright21-May-10 18:33 
GeneralRe: It Works! Pin
Luc Pattyn21-May-10 22:36
sitebuilderLuc Pattyn21-May-10 22:36 
GeneralRe: It Works! Pin
Roger Wright22-May-10 4:20
professionalRoger Wright22-May-10 4:20 
GeneralRe: It Works! Pin
Luc Pattyn22-May-10 4:30
sitebuilderLuc Pattyn22-May-10 4:30 
GeneralRe: It Works! Pin
DaveyM6921-May-10 22:46
professionalDaveyM6921-May-10 22:46 
GeneralRe: It Works! Pin
Roger Wright22-May-10 4:23
professionalRoger Wright22-May-10 4:23 
GeneralRe: It Works! Pin
Roger Wright27-May-10 16:55
professionalRoger Wright27-May-10 16:55 
GeneralRe: It Works! Pin
DaveyM6928-May-10 8:47
professionalDaveyM6928-May-10 8:47 
Hi Roger,

You're nearly there! Firstly a few comments/points...

1. Dispose of anything that is disposable if you are creating it yourself. In your code above dc and bluePen should both be disposed as you have created them.

1a. If the system creates them for you (i.e. if you used Pens.Blue instead) then don't dispose!
1b. If you are storing them in class member variables for use elsewhere, make sure they are disposed of in the class's Dispose method instead.
1c. If 1a and 1b don't apply, wrapping in a using block automatically disposes for you:
C#
using (Pen bluePen = new Pen(Color.Blue, 3))
{
    // ...
}// bluePen is now out of scope and Dispose has automatically been called!


2. Drawing anywhere but in OnPaint is sure to create you problems. The window/control will repaint for many reasons - if another window is moved over or from the top, restore from minimized, resized etc... If you are drawing in the contructor, that is never going to get called when such things happen so your drawing will disappear! Also, creating your own Graphics is an expensive operation, OnPaint supplies you one for free! OnPaint gets called automatically when any repainting is required. You can force it by calling Invalidate(); as well.

To get yourself an OnPaint method, override the existing one. The free Graphics object is available as e.Graphics. So the code in your constructor can be moved and becomes:
C#
protected override void OnPaint(PaintEventArgs e)
{
    using (Pen bluePen = new Pen(Color.Blue, 3))
    {
        e.Graphics.DrawRectangle(bluePen, 170, 10, 100, 100);
    }
    base.OnPaint(e);
}

If you need any more help, post back. Always happy to help if I can Thumbs Up | :thumbsup:
Dave

If this helped, please vote & accept answer!


Binging is like googling, it just feels dirtier. (Pete O'Hanlon)

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

GeneralRe: It Works! Pin
Roger Wright28-May-10 15:45
professionalRoger Wright28-May-10 15:45 
GeneralRe: It Works! Pin
Mohsiul Haque21-May-10 22:52
Mohsiul Haque21-May-10 22:52 
GeneralRe: It Works! Pin
Ravi Bhavnani22-May-10 6:05
professionalRavi Bhavnani22-May-10 6:05 

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.