The C Sharp language has a good support for creating random entities such as integers, bytes or doubles. First we need to create the Random Object. The next step is to call the Next() function in which we may supply a minimum and maximum value for the random integer. In our case we have set the minimum to 1 and maximum to 9. So, each time we click the button we have a set of random values in the three labels. Next, we check for the equivalence of the three values; and if they are then we append two zeroes to the text value of the label thereby increasing the value 100 times. Finally we use the MessageBox() to show the amount of money won.
.Net C# 5 Codes on various topics & Visual Studio 2012 Source Codes available to direct download.
AutoComplete Feature in C#
This is a very useful feature for
any graphical user interface which makes it easy for users to fill in
applications or forms by suggesting them suitable words or phrases in
appropriate text boxes. So, while it may look like a tough job; its actually
quite easy to use this feature. The text boxes in C Sharp contain an
AutoCompleteMode which can be set to one of the three available choices i.e.
Suggest , Append or SuggestAppend. Any choice would do but my favourite is the
SuggestAppend. In SuggestAppend, Partial entries make intelligent guesses if
the ‘So Far’ typed prefix exists in the list items. Next we must set the
AutoCompleteSource to CustomSource as we
will supply the words or phrases to be suggested through a suitable data source.
The last step includes calling the AutoCompleteCustomSouce.Add() function with
the required. This function can be used at runtime to add list items in the
box.
Insert & Retrieve from Service Based Database
Fetch Data from Table in C# 5
Fetching data from a table in C Sharp is quite easy. It First of all requires creating a connection to the database in the form of a connection string that provides an interface to the database with our development environment. We create a temporary DataTable for storing the database records for faster retrieval as retrieving from the database time and again could have an adverse effect on the performance. To move contents of the SQL database in the DataTable we need a DataAdapter. Filling of the table is performed by the Fill() function. Finally the contents of DataTable can be accessed by using a double indexed object in which the first index points to the row number and the second index points to the column number starting with 0 as the first index. So, if you have 3 rows in your table then they would be indexed by row numbers 0 , 1 & 2.
Drawing with Mouse in C# 5.0
This C# Windows Forms tutorial is a bit advanced program which shows a glimpse of how we can use the graphics object in C#. Our aim is to create a form and paint over it with the help of the mouse just as a 'Pencil'. Very similar to the 'Pencil' in MS Paint. We start off by creating a graphics object which is the form in this case. A graphics object provides us a surface area to draw to. We draw small ellipses which appear as dots. These dots are produced frequently as long as the left mouse button is pressed. When the mouse is dragged, the dots are drawn over the path of the mouse. This is achieved with the help of the MouseMove event which means the dragging of the mouse. We simply write code to draw ellipses each time a MouseMove event is fired.
Subscribe to:
Posts (Atom)