Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m trying to practice programing by creating a simple application which, I thi

ID: 642215 • Letter: I

Question

I'm trying to practice programing by creating a simple application which, I think, I can manage to do in .Net C# in VisualStudio 2010.

I'm working on simple application which will let me to create small pictures (icons) in sizes such as 8x8, 16x16, 32x32 (ect) pixels. I will be creating a grid representing each size by scaling to amount of pixels. Each pixel will be represented in a small square which will be able to click to change color ect.

So here's my question regarding what elements such app should have:

What VS tool would let me to create a grid for my project? Keeping in mind that each small square should be generated automatically by using X/Y size provided by user and boxes should be clickable. Also, I probably should be able to be able to click one pixel and drag mouse to select other pixels.

What simple functions should such small app have? Ex. choosing colors.

What minimal functions should I have?

I hope this is place for such question. I'm trying to get the general idea of how to make such small app work and what user might expect when opening small, icon creating, application.

Explanation / Answer

You will probably have to create a Custom Control for the drawing surface. If you are creating a WinForms application, you can start by inheriting from System.Windows.Forms.Control. Then you override the OnPaint method and draw pixels as desired. I gave this advice to someone wanting to draw a LED-board, which looks pretty much like a zoomed icon. Here is the original answer with a VB example.

Here the translated example in C#

public class LedBoard : Control
{
private Random _rand = new Random();

protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
e.Graphics.FillRectangle(Brushes.Black, 0, 0, Width, Height);

const int nx = 40;
const int ny = 25;

int w = (Width - 1) / nx - 1;
int h = (Height - 1) / ny - 1;
for (int x = 0; x <= nx - 1; x++) {
for (int y = 0; y <= ny - 1; y++) {
if (_rand.NextDouble() < 0.8) {
e.Graphics.FillRectangle(Brushes.Red, x * (w + 1) + 1, y * (h + 1) + 1, w, h);
}
}
}
}
}
It is just to give you an idea. If you want to "draw" an icon with buttons or labels for each pixel, you will need 32 x 32 = 1024 controls! A Custom Control allows you to do more than just draw the pixels of the icon. You could also draw selection marks, for instance.