System.Drawing.Graphics

There you can draw rectangles, arcs, polygon, bezier,.... I tried all methods "draw", But i can't draw a single pixel. How do i



Answer this question

System.Drawing.Graphics

  • Terry Rossow

    Tongue Tied ohhh sorry, may be I was not well clearly. I can draw everything, the line, the arche, retangle...., everything. But i can't draw a only pixel. Like a DOT ".".


                                                    .


                                                 This.

    i seeking a method what look like this prototype: DrawPixel(pen as System.Drawing.Pen , x as floating, y as floating)

    Sorry english is not my firt language. Tank you for the cooperation.
    You can tell me in C++ to.


  • Rizzi Davide

    From the docs http://msdn2.microsoft.com/en-us/library/9dtfzwyx(en-US,VS.80).aspx:

    PSet Method

    In Visual Basic 6.0, the PSet method is used to change the color of a pixel on a form or PictureBox control. If the DrawWidth property is set to a value greater than 1, the PSet method draws a filled circle. An optional parameter is used to specify the color; if omitted ForeColor is used.

    In Visual Basic 2005, there is no equivalent for the PSet method. To change the color of a single pixel on a form or the PictureBox control, use the DrawEllipse method to draw a circle with a height and width of 1 pixel. To duplicate the functionality of PSet when DrawWidth is greater than 1, use the FillEllipse method.

    Hope this helps,

    Steve Hoag

    Visual Basic Express



  • DataCorrupt

    Well, this should work.  Is your form more than 200 pixels high Try starting at 0,0.



  • JEROPS

    Hello.

    FillRectangle(brush, new Rectangle(x, y, 1, 1))

    I guess you knew that allready. But this is the best answer I have, unless you want to use P/Invoke or scan lines.

    Hope I am helping.



  • Bernard C

    right. but i can't still draw the pixel.

    Public Class Form1

    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

    Panel1.BackColor = Color.White

    e.Graphics.DrawLine(Pens.Blue, 0, 200, 800, 200)

    End Sub

    End Class


  • blkeller

    yes, i made in VB. And this works.

    Public Class Form1

    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

    Dim panelGraphics As System.Drawing.Graphics

    Panel1.BackColor = Color.White

    panelGraphics = Me.Panel1.CreateGraphics()

    panelGraphics.DrawLine(Pens.Blue, 0, 200, 800, 200)

    panelGraphics.Dispose()

    End Sub

    End Class


  • trianta99

    Dim panelGraphics As System.Drawing.Graphics

    I repeat : your PaintEventArgs has a Graphics object in it, which you need to use.  You're just drawing into thin air with this code.


  • NeedSQLHelp

    I have the same problem. I know in earlier VB 6 and earlier you could use PSet or SetPixel to set a pixel. I think VB.net does not have PSet but I was able to use SetPixel to modify a bitmap but i wasn't able to get it to just draw a pixel without first drawing to a drawing.graphics.bitmap object.

    Obviously, you could draw a really tiny rectangle but that seems a bit stupid doesn't it.

    Could someone with experience tell us if there's a replacement for PSet


  • maui_desu

    How did you try it Your form has a Paint handler, which you can override.  The PaintEventArgs contains a Graphics object.  This is the object you need to use to draw onto your window.

  • System.Drawing.Graphics