The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

import-bot (20211) [Avatar] Offline
[Originally posted by raju_shrestha]

How to draw a pixel in a form (like putpixel() in C) with DotNet?

import-bot (20211) [Avatar] Offline
Re: Drawing a pixel
[Originally posted by fgrimes]

Hi Raju,

For lines, circles, etc. use GDI+, as follows:

private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) {
Pen p = new Pen(Color.Yellow, 5);
Graphics g = e.Graphics;
g.DrawLine(p, 10, 10, 90, 90);

But you probably know that already. I don't see anything in the help for
individual pixels, but you can always place an empty PictureBox on the form,
then create a blank Bitmap object inside it and use Bitmap.SetPixel.

import-bot (20211) [Avatar] Offline
Re: Drawing a pixel
[Originally posted by raju_shrestha]

Thanks Fergal,

Yeah I already knew about drawing lines, circles using GDI+. But I was trying
to use my own drawing algorithms in C# which needs C's putpixel equivalent.
Using bitmap as you suggested will work, but it might not be efficient to use
in such algorithms.

I'd appreciate for any better solution.