C# equivalent to "Pset"

G

Guest

I've been playing with "classic" VB since version 3. I have VB6 Learning
Edition. Recently, I wanted to try VB.NET. I got a beginner's book with a CD
with the software & installed it. There are things that I like about VB.NET &
there are things that I don't like. I like to do graphics like plotting math
functions & fractals & stuff. VB has Pset. In VB6, it's easy to plot a pixel.
Just use Pset. In VB.NET, it isn't. I have to create a bitmap & then set the
pixels & then draw the bitmap. VB6 makes it easier to plot pixels.

Anyway, does C# have something in the language itself, NOT in the.NET
Framework, equivalent to Pset? It obviously isn't easy to plot pixels using
the .NET Framework, that's why I'm hoping that there is something in C#
itself that's equivalent to Pset. Is there?

Thank you.

David
 
B

Barry Kelly

pcnerd said:
I've been playing with "classic" VB since version 3. I have VB6 Learning
Edition. Recently, I wanted to try VB.NET. I got a beginner's book with a CD
with the software & installed it. There are things that I like about VB.NET &
there are things that I don't like. I like to do graphics like plotting math
functions & fractals & stuff. VB has Pset. In VB6, it's easy to plot a pixel.
Just use Pset. In VB.NET, it isn't. I have to create a bitmap & then set the
pixels & then draw the bitmap. VB6 makes it easier to plot pixels.

Anyway, does C# have something in the language itself, NOT in the.NET
Framework, equivalent to Pset?

C# knows nothing about user interfaces, graphics, etc. The only things
it intrinsically knows about the framework are things from the System
namespace: string, int, etc.
It obviously isn't easy to plot pixels using
the .NET Framework, that's why I'm hoping that there is something in C#
itself that's equivalent to Pset. Is there?

It's actually very, very easy. As you say, Bitmap.SetPixel is the
closest equivalent. You can set a bitmap as the background for a form or
the picture in a picturebox. Here's a complete program which uses
SetPixel to draw on the bitmap when you click on the form. If you create
a new, empty application in C# (i.e. with no forms and no classes) and
add this class to the project, it will compile. Alternatively, put it
all into a text file with a .cs extension and pass it as an argument to
csc.exe (in the C:\windows\microsoft.net\framework\v2.0.50727
directory).

---8<---
using System;
using System.Drawing;
using System.Windows.Forms;

class App
{
static void Main()
{
Bitmap picture = new Bitmap(500, 500);

// Draw a nice border around the picture.
using (Graphics g = Graphics.FromImage(picture))
g.DrawRectangle(Pens.Orange, 0, 0, 499, 499);

Form form = new Form();
form.BackgroundImage = picture;
form.Click += delegate
{
for (int i = 0; i < 500; ++i)
picture.SetPixel(i, i, Color.White);
form.Invalidate();
};

Application.Run(form);
}
}
--->8---

The form background causes the image to tile, but you can easily use a
PictureBox instead to avoid tiling if you want.

-- Barry
 
G

Guest

pcnerd,
One point to note is that using SetPixel is simple from a programming point
of view but unfortunately it is very inefficient and if you want any kind of
decent performance you should not use that and use the LockBits method
instead which allows you to maipulate raw pixel values very efficiently. See
http://www.bobpowell.net/lockingbits.htm for an excellent overview.

Thanks
Mark
http://www.markdawson.org
 
M

Michael A. Covington

Anyway, does C# have something in the language itself, NOT in the.NET
C# knows nothing about user interfaces, graphics, etc. The only things
it intrinsically knows about the framework are things from the System
namespace: string, int, etc.

In fact, if you look back at the remote history of Basic, you'll find that
PSET dates from a time when Basic ran without an operating system! The
original 1981 IBM PC didn't have to have diskette drives. You could run
"Cassette Basic" from ROM and store your files on (believe it or not) a
cassette tape recorder.

Almost no one did this, but the point is that Basic could run with no
operating system at all (not even DOS). Thus all of the physical functions
of the machine had to be in the *language*, not in OS calls.

Today it's different. Today all but the simplest i/o operations are done by
passing requests to the operating system. That's why graphics is the
province of the .NET Framework rather than existing as fundamental language
constructs.

(I have on my desk a diskette drive from a 1983 PC XT. It cost $650 at the
time, so you can understand why people might want to do without them, if
they used their PC mainly as a calculator. Hard disks cost many thousands
of dollars.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top