Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Progress Bar in C#

I am very busy these days and not getting time to do readings or writing on my blog. But today i manged to get some time so i decided to write this simple tutorial. I am going to write that how progress bar works in C#, ProgressBar class is part of .NET framework. In this tutorial i am going to use three members of class ProgressBar Minimum,Maximum and Value.
So first create a C# Application and add progress bar control on your form, you can give it any name but i am naming it "pb" here. Add timer and name it as "tr".Now paste the following code in form load event

private void frmProgressbar_Load(object sender, EventArgs e)
{
pb.Minimum = 0; // set Minimum to 0
pb.Maximum = 100;// set Maximum t0 100
tr.Interval = 100;// timer ticks each 100 milliseconds
tr.Enabled = true; // start the timer
}

Now paste the following code behind Timer Tick Event

private void tr_Tick(object sender, EventArgs e)
{
if(pb.Value!=100) // check if value below 100 as it shud not be greater than maximum value
{
pb.Value += 5;// add 5 to the Progressbar current value
}
}
Thats it!! its done, isn't it simple? :P.I hope this will help you

How to make a DLL file and use it in C#

I am assuming that you know about dll files.So i am going to show you a simple way by which you can make a dll file and can use it.There are many other ways also but this is the simplest.

1.Open new project and select "class library", and choose location where you want to save it.
2.Now create a simple function in class1 as shown below.You can add classes and functions as much as you need but for simplicity i am just writing 1 function "add" which add two numbers and returns the result.
3.Now Build Solution from menu bar
4.Your DLL file is ready and it will be in the debug folder of the project as shown below
the dll file that you have just created can be copied and pasted anywhere and can be used by number of programs.
5.Now create new windows application in C#
6.Build the windows form according to your need, i am just adding a button to the form
7.Now add reference off the DLL file that you have created.
8.We will use class and namespace of the dll file we had created
9.Double click on the button to create event handler and write the code as shown in templates below.
10.Now run the program and output will be according to the parameters that yiu passed to add function in your dll file.i passed 1 & 2 so output should be 3 :P
I hope this will help you :P