473,394 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 6666
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: John | last post by:
Is there an equivalent of COM on Linux that I can get through Python. My need is to have some sort of language independent component framework. I can think of CORBA but I have to have a server...
2
by: Michael Foord | last post by:
Please pardon my ignorance on this one - but I'm not certain how the sign bt is treated in python bitwise operators. I've trying to convert a javascript DES encryption routine into python. ...
3
by: Robert Dodier | last post by:
Hello, Here's a thought that I'm sure has already occurred to someone else, I just can't find any record of it yet. An XML document is just a more verbose and clumsy representation of an...
1
by: Vannela | last post by:
Is there any equivalent control in .NET for the Power builder DataWindow control? I am explaining the Datawindow architecture to some extent. Power Builder DataWindow Control has got different...
6
by: Frank Rachel | last post by:
So I can focus on the correct areas of research, I was wondering if someone could give me the .NET equivelents for this J2EE architecture: JSP's make calls to local JavaBean Controls. The...
3
by: Marty | last post by:
Hi, What is the VB.NET equivalent of the VB6 ADODB.Connector and ADODB.Recordset? Thanks Marty
7
by: Tim Conner | last post by:
Hi, I am an ex-delphi programmer, and I having a real hard time with the following simple code (example ): Which is the equivalent to the following code ? var chars : PChar; sBack, s :...
10
by: karch | last post by:
How would this C# contruct be represented in C++/CLI? Or is it even possible? PolicyLevel level = (enumerator->Current) as PolicyLevel; Thanks, Karch
9
by: Alan Silver | last post by:
Hello, I'm converting some old VB6 code to use with ASP.NET and have come unstuck with the Asc() function. This was used in the old VB6 code to convert a character to its ASCII numeric...
14
by: grid | last post by:
Hi, I have a certain situation where a particular piece of code works on a particular compiler but fails on another proprietary compiler.It seems to have been fixed but I just want to confirm if...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.