Ok, the way things are organized, the
Sharel
displays 4 pages.
There are several things you need:
- first, you need a way to remember which page is actually displayed. Since existing buttons deal with static values, you are using these values as the
start
parameter. But, with
previous
and
next
buttons, you do not have static data; you need a value so that the compiler know which previous or next page to deal with.
You could add a private member variable in your form, something like
int currentPage;
- second, when you create this member variable, you must then affect it a useful value when a page is actually displayed. For example, you could add:
currentPage = start;
somewhere in the
Sharel
method.
- finally, from here you ahev an actual value which you can use in the
next
and
previous
methods. But, you also have to take care of the edge cases where you are displaying the first and last pages. For the first page, this is simple since its index is zero. For the last page, again you need a way to have an actual, valid value for the number of pages which you are actually displaying. This could be declared this way
int pageCount;
You will have to give it a meaningful value yourself, at the time you are loading the pages in the control; because you will be able to get this value at that time. Then you could write the methods this way:
public void prev(object sender,EventArgs e)
{
int a = Math.Max(0, currentPage - 1);
int b = Math.Min(pageCount, a + 4);
Sharel(a, b);
}
public void next(object sender, EventArgs e)
{
int a = Math.Min(pageCount, currentPage + 1);
int b = Math.Min(pageCount, a + 4);
Sharel(a, b);
}