469,646 Members | 1,558 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,646 developers. It's quick & easy.

C# equivalent to "Pset"

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
Jul 1 '06 #1
4 6300
pcnerd <pc****@discussions.microsoft.com> wrote:
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

--
http://barrkel.blogspot.com/
Jul 1 '06 #2
You'll enjoy this graphics example, which includes source code:

http://www.covingtoninnovations.com/...ex.html#040903

It actually plots curves, but it's a useful quick start for graphics in C#.
Jul 1 '06 #3
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
"Barry Kelly" wrote:
pcnerd <pc****@discussions.microsoft.com> wrote:
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

--
http://barrkel.blogspot.com/

Jul 1 '06 #4
>> 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.


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.)
Jul 1 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by John | last post: by
2 posts views Thread by Michael Foord | last post: by
6 posts views Thread by Frank Rachel | last post: by
7 posts views Thread by Tim Conner | last post: by
10 posts views Thread by karch | last post: by
9 posts views Thread by Alan Silver | last post: by
14 posts views Thread by grid | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.