This post will demonstrate how to show and convert colors when the Red Green & Blue values of those colors are given. We simple use a function and supply the Red, Green and Blue components in the parameter list. We shall also see how to Invert a color. In the image below the text color is set by the user. The background color is automatically set which is the Invert of the Text color. See image below to have a look at the final output of our WinForms application:
.Net C# 5 Codes on various topics & Visual Studio 2012 Source Codes available to direct download.
Named Arguments in .Net C#
Named Arguments are an alternative way for specifying parameter values in function calls. They work so that the position of the parameters would not pose problems. Therefore it reduces the headache of remembering the positions of all parameters for a function. It also helps to avoid the excess overloading of functions that contain less or more of the same set of parameters.
They work in a very simple way. When we call a function, we would write the name of the parameter before specifying a value for the parameter. In this way, the position of the argument will not matter as the compiler would tally the name of the parameter against the parameter value. This makes it unnecessary to remember the organisation of the parameters in the function definition.
They work in a very simple way. When we call a function, we would write the name of the parameter before specifying a value for the parameter. In this way, the position of the argument will not matter as the compiler would tally the name of the parameter against the parameter value. This makes it unnecessary to remember the organisation of the parameters in the function definition.
Optional Parameters in .Net
Optional Arguments were introduced in C#
4.0 and this article will show you how to use them. Optional Arguments are necessary when you
specify functions that have a large number of arguments. It can cut down time by making
you pass on argument values to the most needy parameters in a situation.
Optional Arguments are what their name
suggests i.e. even if you do not specify them, its perfectly OK. But it doesn't
mean that they have not taken a value. In fact we specify some default values
that the Optional Parameters take when values are not supplied in the function
call. In this way we gain the functionality of easily setting values once and
using these values several times as a default unless something different is
needed.
Printing a Windows Form to Printer and File in C#
The objective here is to print a Windows Form to the Printer or a File on the HDD. You can also have a Print Preview before you print a WinForm. See the Form below that we shall print. We will encounter one small problem i.e. the button, radio buttton and textbox are not required for printing. We only wish to print the written text written above in Green color. There is VS 2012 source code at the very end. See the code and explanations below the image:
How to Multithread in C#
This WinForms C# Application will show you the basics of creating and using a thread and a bit more. It will actually show you multiple threads working simultaneously. As you know that threads are meant to do multiple jobs at a time by utilizing the different logical cores of the CPU, we will use this to work the value of multiple Int64 variables. See the application screenshot when the application starts and look for the source code at the end:
Working With Enumerations in C#
.Net Enumeration Basics
Enumerations or simply Enums in short provide convenient ways to create and access named numeric constants. These constants can have custom Indexable values that represent each individual element. Unlike arrays, they can have values which are not incremental in steps of ‘1’. Also, these values can be of types other than integers (which is the default) such as bytes, Boolean etc.
A single Enumeration itself has a group of values associated with it. We create an Enum Object before attempting to use the functions that are offered. This value when used with a dot operator on an Enumeration gives the state of the Enumeration Object. When we initialize new Enums of a previously defined Enum, we don’t use the new operator. The new Enums are almost immediately created and initialized to an initial value within the Enum.
Create an Enum
Subscribe to:
Posts (Atom)