avatar

Andres Jaimes

How to create a simple gradient in C#

Creating a simple gradient using two colors is very simple: Rectangle rect = new Rectangle(0, 0, 100, 100); LinearGradientBrush lgb = new LinearGradientBrush(rect, Color.White, Color.Blue, 90); e.Graphics.FillRectangle(lgb, rect); This code will generate a gradient in the given rectangle that goes from white to blue in a vertical way (see last parameter in constructor). In this case, e, is any class that encapsulates the System.Drawing.Graphics class. Once the gradient is ready, well, you have to actually draw it by calling the FillRectangle function.

Printing in C# – The easy way

Believe me, it is easy. As with any class, before we can use any of the Classes, Events and Objects available to us in the .Net Framework we need to import the Namespaces we need. For this we need 3 namespaces. VB.Net users only required 2 because VB.Net assumes the System Namespace, whereas C# isn’t so kind: System System.Drawing System.Drawing.Printing These 3 Namespaces contain everything we need for this class, so you will need to add the following lines to the top of your class file:

How to choose a printer using C#

You can assign a printer and other settings by using the basic PrintDocument and PrintDialog controls properties. Look at the next example: if (printDialog.ShowDialog() == DialogResult.OK) { printDocument.PrinterSettings.PrinterName = printDialog.PrinterSettings.PrinterName; printDocument.PrinterSettings.Copies = printDialog.PrinterSettings.Copies; }

Some words on Java, C# and C++

I have always considered myself a C++ guy. That was one of the first languages I learned. But, life has taken me through many different paths, and I have needed to learn others. It was seven years ago, when I tried my first cup of Java and I realized objects were a must: Why did I need to create an additional class to return a compound value? another file?, I could do a “one-liner” in C++.