Click here to Skip to main content
15,898,036 members
Home / Discussions / C#
   

C#

 
AnswerRe: regex Pin
dan!sh 7-Sep-09 21:37
professional dan!sh 7-Sep-09 21:37 
GeneralRe: regex Pin
TheCardinal7-Sep-09 21:54
TheCardinal7-Sep-09 21:54 
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 
First of all, wrong forum... but never the less

How are you trying to draw?

The right way to do it is firstly create a DoubleBufferedPannel. To do that create a new cs file in your solution and add the following code in there.

namespace DoubleBufferPanelNameSpace
{
    public class DoubleBufferPanel : Panel
    {
        public DoubleBufferPanel()
        {
            this.SetStyle(ControlStyles.AllPaintingInWmPaint |
                          ControlStyles.UserPaint |
                          ControlStyles.DoubleBuffer |
                          ControlStyles.ResizeRedraw,
                          true);
            this.UpdateStyles();
        }
    }
}


compile your project and the you'll see the DoubleBufferPanel in your toolbox. Drop that on the form you want to draw on.

Then to do your GDI code all you have to do is use the panels paint handler like so

private void doubleBufferPanel1_Paint(object sender, PaintEventArgs e)
{
    e.Graphics.DrawLine(new Pen(Brushes.Black), 0, 0, 10, 10);
}


If you want the image to be redrawn cause some of the variables that affect the drawing has changed you can call doubleBufferPanel1.Invalidate(); which forces the control to be redrawn.

Using this aproach there is no need to worry about disposing graphics objects as its done for you.

Hope this helps

Harvey Saayman - South Africa
Software Developer
.Net, C#, SQL

you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

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 
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 

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.