Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 01-10-2006, 01:46 AM   #1 (permalink)
 
Super Techie

Join Date: Mar 2003

Posts: 337

shdwsclan

Send a message via AIM to shdwsclan
Default problems with C#

Problem 1.
When printing to a status bar, I get 0 and in theory it should not do this.
Quote:
//here is my code
private void button1_Click(object sender, System.EventArgs e)
{
// i test the status bar to see if it works
statusBar1.Text = "Write Test";
// the for loop which generates number i
for( int i = 1; i<=1000; i++)
{
// this will update the status bar with the percentage of the
// completeness of the loop
statusBar1.Text = ((i/1000)*100).ToString();

}
}
Problem 2.
I am having trouble printing an array(to a printer)
...specifically the issue where printing an array to multiple pages.
Ive put in a simple array from my program since my list class is way too long.
Can anyone tell my what hasmorepages does, when does it change and what changes and how to implement it

// here is my code
Quote:
private void mainmenu_file_print_Click(object sender, System.EventArgs e)
{
// if the dialog box returns event OK.....
if (printDialog1.ShowDialog() == DialogResult.OK)
{
//....then print......
// indirectly calling the OnPrintPage method
printDocument1.Print();
}
}
private void OnPrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
// gets margins
int xMargin = e.MarginBounds.Left;
int yMargin = e.MarginBounds.Top;
// initializes line printed
int linesPrinted = 0;

// creates the arial font
Font printFont = new Font("Arial",12);

// calculates lines per page but implementation is unknown
//linesPerPage = (e.MarginBounds.Height / printFont.GetHeight(e.Graphics));

int times = 200;
// creating and filling array - start
int [] intArray = new int[times];
for( int x = 0; x<times; x++)
{
intArray[x] = x;
}
// creating and filling array - end

// a while loop that will print each cell of the array
while (linesPrinted < intArray.Length)
{
// this line prints a cell of the array
e.Graphics.DrawString (intArray[linesPrinted].ToString(),printFont, Brushes.Black, xMargin,yMargin );
// this line prints a line return - specifically a windows line return
e.Graphics.DrawString ("\r\n",printFont, Brushes.Black, xMargin,yMargin );
// incrementation of the line counter
linesPrinted++;

}

// supposedly tells the printer that there are more pages
// but i dont know how to implement it
//e.HasMorePages = true;

}
Any help is appreciated.....
shdwsclan is offline  
Old 01-10-2006, 02:57 PM   #2 (permalink)
void's Avatar
 
True Techie

Join Date: Oct 2005

Posts: 198

void

Default

Problem 1

This line
Quote:
statusBar1.Text = ((i/1000)*100).ToString();
(i/1000)*100 will result in numbers less than 1 e.g when i = 1 the result is 0.1, 0.1 is rounded by .ToString() to 0. Why instead of creating a percentage using the loop from 0 to 1000, instead 1 to 100, then us i directly as the percentage, I doubt you need to be so precise.
void is offline  
Old 01-10-2006, 07:43 PM   #3 (permalink)
 
Ultra Techie

Join Date: Jul 2005

Posts: 530

TheHeadFL

Send a message via AIM to TheHeadFL
Default

The problem in the first thing as stated above is with the line

Code:
statusBar1.Text = ((i/1000)*100).ToString();
The problem here is that (i/1000) is cast as an integer.

You need to either explicitly cast float(i/1000) or implicitly cast (i/1000.) [Note the decimal]

The integer division of any number under 1000 into 1000 is always 0.
__________________
Desktop machine: 2 x Opteron 246, Asus K8N-DL, 2GB PC3200 ECC Reg., XFX GeForce 6600GT, 74gb WD Raptor, 2 x 19\" LCDs, Windows XP x64
Server machine: Intel P4 3.0GHz 2MB EM64T, ECS i865pe, 1GB PC3200, 36gb WD Raptor, Windows Server 2003
Laptop: Dell Inspiron 9100 (Intel P4 3.2GHz 1MB Prescott, i865pe, 512MB PC3200, Mobility Radeon 9700, DVD+R/DL Burner), Windows XP
Linux: P3 450Mhz, 386MB ram, Slackware 10.1 (Running mySQL/Apache)
TheHeadFL is offline  
Old 01-11-2006, 02:32 AM   #4 (permalink)
 
Super Techie

Join Date: Mar 2003

Posts: 337

shdwsclan

Send a message via AIM to shdwsclan
Default

The type casting worked..thanks

Math.Ceiling(((i/(double)times)*100));

and then using .toString(); will generate a non decimal number
that will display as a string in the status bar.......

anyone up for the printing challenge....?????
.................also does anyone know the framework restriction code for AssemblyInfo...i remember seeing a sample on msdn but i cant find it......
shdwsclan is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On