Click here to Skip to main content
15,917,005 members
Home / Discussions / C#
   

C#

 
GeneralRe: regex Pin
OriginalGriff7-Sep-09 22:49
mveOriginalGriff7-Sep-09 22:49 
GeneralRe: regex Pin
dan!sh 8-Sep-09 0:27
professional dan!sh 8-Sep-09 0:27 
GeneralRe: regex Pin
TheCardinal8-Sep-09 20:40
TheCardinal8-Sep-09 20:40 
Questionneed to clear the previous graphics object b4 making a new one ? Pin
Saad Shuja7-Sep-09 20:32
Saad Shuja7-Sep-09 20:32 
AnswerRe: need to clear the previous graphics object b4 making a new one ? Pin
stancrm7-Sep-09 20:36
stancrm7-Sep-09 20:36 
AnswerRe: need to clear the previous graphics object b4 making a new one ? Pin
Harvey Saayman7-Sep-09 21:22
Harvey Saayman7-Sep-09 21:22 
GeneralRe: need to clear the previous graphics object b4 making a new one ? Pin
Saad Shuja7-Sep-09 21:57
Saad Shuja7-Sep-09 21:57 
GeneralRe: need to clear the previous graphics object b4 making a new one ? Pin
DaveyM697-Sep-09 22:16
professionalDaveyM697-Sep-09 22:16 
Two reasons. Every time a control needs to be redrawn by the OS it's OnPain't gets called. Creating your own class derrived from the control in question (Panel) gives you access to this method so you can guarantee your code is going to get called every time it is needed.

Doing it this way, you get a Graphics object for free. No need to use more resources and no need to remember to dispose of it.

A proposal for a slight improvement to Harvey's code:
C#
public class DoubleBufferPanel : Panel 
{ 
    public DoubleBufferPanel() 
    { 
        this.SetStyle(
            ControlStyles.AllPaintingInWmPaint |
            ControlStyles.UserPaint |
            ControlStyles.DoubleBuffer |
            ControlStyles.ResizeRedraw, true);
        this.UpdateStyles();
    }

    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);
        using (Pen pen = new Pen(Color.Black))
        {
            e.Graphics.DrawLine(pen, 0, 0, 10, 10);
        }
    }
}


Dave

Generic BackgroundWorker - My latest article!
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Why are you using VB6? Do you hate yourself? (Christian Graus)

GeneralRe: need to clear the previous graphics object b4 making a new one ? Pin
Harvey Saayman7-Sep-09 22:21
Harvey Saayman7-Sep-09 22:21 
Questioncontroling a form controls from another form in c# Pin
Ageesh7-Sep-09 19:43
Ageesh7-Sep-09 19:43 
AnswerRe: controling a form controls from another form in c# Pin
Harvey Saayman7-Sep-09 21:25
Harvey Saayman7-Sep-09 21:25 
Questionhow to find if a file is already open or not Pin
Swetha Srinivasan7-Sep-09 19:10
Swetha Srinivasan7-Sep-09 19:10 
AnswerRe: how to find if a file is already open or not Pin
Arun Jacob7-Sep-09 19:17
Arun Jacob7-Sep-09 19:17 
GeneralRe: how to find if a file is already open or not Pin
Swetha Srinivasan7-Sep-09 19:34
Swetha Srinivasan7-Sep-09 19:34 
GeneralRe: how to find if a file is already open or not Pin
Arun Jacob7-Sep-09 19:36
Arun Jacob7-Sep-09 19:36 
GeneralRe: how to find if a file is already open or not Pin
Arun Jacob7-Sep-09 19:39
Arun Jacob7-Sep-09 19:39 
GeneralRe: how to find if a file is already open or not Pin
Swetha Srinivasan7-Sep-09 19:40
Swetha Srinivasan7-Sep-09 19:40 
QuestionHow to determine which control raised an event Pin
GavinSV7-Sep-09 18:48
GavinSV7-Sep-09 18:48 
AnswerRe: How to determine which control raised an event Pin
Arun Jacob7-Sep-09 18:55
Arun Jacob7-Sep-09 18:55 
GeneralRe: How to determine which control raised an event Pin
GavinSV7-Sep-09 19:07
GavinSV7-Sep-09 19:07 
GeneralRe: How to determine which control raised an event Pin
OriginalGriff7-Sep-09 22:10
mveOriginalGriff7-Sep-09 22:10 
GeneralRe: How to determine which control raised an event Pin
DaveyM697-Sep-09 22:35
professionalDaveyM697-Sep-09 22:35 
GeneralRe: How to determine which control raised an event Pin
OriginalGriff7-Sep-09 22:57
mveOriginalGriff7-Sep-09 22:57 
GeneralSend an web page as an attachmnet to clint in outlook 2007. Pin
coolchampniks7-Sep-09 18:40
coolchampniks7-Sep-09 18:40 
QuestionRun Winform at Startup Pin
Abdul Rahman Hamidy7-Sep-09 18:12
Abdul Rahman Hamidy7-Sep-09 18:12 

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.