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/