How can I stop the illumination of the form ? GDI+

Hi, wile I was trying to draw on the form every 100 ms , I had a problem that the form illuminates like the flash light every time I tried to draw on it, I know that I mustn't clear the form that much but I have to because I'm trying to let the form take a shape I've drawn in a PNG file .

what can I do to stop this Illumination or if you know a better way to shape the form as I want please write it here .

and I want to tell you something great :
I have taken 98% in my high school final exam ( the one before the university ) which means I can choose to enter any faculty I want in Damascus University .


Answer this question

How can I stop the illumination of the form ? GDI+

  • Boise83716


    sorry I didn't understand it

    " Avoid it by painting the form area not covered by the bitmap "

    !!

    I'm trying to draw a non-rectangular form and I know that the G.Clear() causes the trouble but I call it to let my form become transparent .

  • su45937

    I just have founded the best way and it has stopped the flickering forever

    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    e.Graphics.Clear(Color.Transparent)
    e.Graphics.DrawImage(BMP, 0, 0, 500, 500)
    End Sub

    and it's over .

    Thank you for participating your opinions with mine, see you soon in another thread .

  • jortiz

    you can use double buffering to reduce flickering double buffering is drawing in offscreen and when finished it copy the graphics

    all you need to do to use double buffering is to SetStyle flags

    SetStyle method is protected so you can not access it except from inhertid class

    as you Drawing in the form you can write something like

    this.SetStyle(ControlStyles.UserPaint, true); //ControlStyles.UserPaint the control draw itself rather than operating system

    this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); //reduce the flicker by ignoring WM_ERASEBKGND

    this.SetStyle(ControlStyles.DoubleBuffer, true);//drawin g in the buffer and display when finished

    for more info look at

    SetStyle

    ControlStyles

    and then do your painting in paint event handler



  • keith_co

    sorry I didn't understand id " Avoid it by painting the form area not covered by the bitmap " !!

    I'm trying to draw a non-rectangular form and I know that the G.Clear() causes the trouble but I call it to let my form become transparent .

  • Wojtek

    Ignore that please. I saw no evidence of flicker with this:

    mports System.Drawing.Drawing2D
    Imports System.Drawing
    Public Class Form1
    Dim BMP As New Bitmap("c:\temp\formback.bmp")
    Dim drg As Boolean = False, pnt As New Point()
    Dim rgn As Region
    Sub New()
    InitializeComponent()
    BMP.MakeTransparent(Me.TransparencyKey)
    Me.SetStyle(ControlStyles.UserPaint, True)
    Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
    Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
    End Sub
    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
    drg = True
    pnt = e.Location
    End Sub
    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
    If drg Then
    Me.Left += (e.X - pnt.X)
    Me.Top += (e.Y - pnt.Y)
    End If
    End Sub
    Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
    drg = False
    End Sub
    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    e.Graphics.Clear(Me.TransparencyKey)
    e.Graphics.DrawImage(BMP, 0, 0, 500, 500)
    End Sub

    End Class


  • nglow

    The G.Clear() call causes the flicker. Avoid it by painting the form area not covered by the bitmap. And do *not* use the G member, use e.Graphics instead; you'll have problems when you resize the form.


  • Mark from NH

    Thank you guys I'll try them and tell you what happened with me

    Thanx

  • My Vizai

    Sorry Guys !!!
    I wanna stop the flickering for good, every thing I make just decreases the flickering but it doesn't stop it !

    Lets say that I wanna draw a skin for my application just like the windows media player, you can see that the windows media player doesn't
    flicker at all . How can I do it

  • Amde

    sorry I didn't understand it " Avoid it by painting the form area not covered by the bitmap " !!

    I'm trying to draw a non-rectangular form and I know that the G.Clear() causes the trouble but I call it to let my form become transparent .

  • peterjp

    This is the code but it is in VB.NET and I don't know why my thread has been moved to the C# forum, anyway I think you can understand it

    Imports System.Drawing.Drawing2D
    Imports System.Drawing
    Public Class Form1
    Dim BMP As New Bitmap("c:\1.png")
    Dim drg As Boolean = False, pnt As New Point()
    Dim G As Graphics, rgn As Region
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    BMP.MakeTransparent(Me.TransparencyKey)
    Me.SetStyle(ControlStyles.UserPaint, True)
    Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
    Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
    G = Me.CreateGraphics
    End Sub
    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
    drg = True
    pnt = e.Location
    End Sub
    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
    If drg Then
    Me.Left += (e.X - pnt.X)
    Me.Top += (e.Y - pnt.Y)
    End If
    End Sub
    Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
    drg = False
    End Sub
    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    G.Clear(Me.TransparencyKey)
    G.DrawImage(BMP, 0, 0, 500, 500)
    End Sub
    End Class

  • JacksonJones

    You may post your code this will help others to see the problem

  • Software Engineer

    Try drawing in a PictureBox's OnPaint event. Set the PictureBox's DoubleBuffered property to True.

    Congrats on your freedom of choice...


  • How can I stop the illumination of the form ? GDI+