Click here to Skip to main content
15,913,487 members
Home / Discussions / C#
   

C#

 
GeneralC# for Internet Explorer Pin
pmasknguyen22-Aug-04 7:11
pmasknguyen22-Aug-04 7:11 
GeneralRe: C# for Internet Explorer Pin
sreejith ss nair22-Aug-04 20:24
sreejith ss nair22-Aug-04 20:24 
GeneralDataView.RowFilter question Pin
WillemM22-Aug-04 6:49
WillemM22-Aug-04 6:49 
GeneralRe: DataView.RowFilter question Pin
sreejith ss nair22-Aug-04 21:45
sreejith ss nair22-Aug-04 21:45 
QuestionHow to set fontsize in inch to print exactly Pin
I2A4U22-Aug-04 5:43
I2A4U22-Aug-04 5:43 
AnswerRe: How to set fontsize in inch to print exactly Pin
Werdna23-Aug-04 7:33
Werdna23-Aug-04 7:33 
GeneralRe: How to set fontsize in inch to print exactly Pin
Werdna23-Aug-04 7:34
Werdna23-Aug-04 7:34 
GeneralRe: How to set fontsize in inch to print exactly Pin
I2A4U23-Aug-04 23:09
I2A4U23-Aug-04 23:09 
Thanks Werdna,

Please see comment in this suorce code.


using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.Windows.Forms;

namespace TestPrint
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	public class PrintingExample 
	{
		private Font printFont;

		public PrintingExample() 
		{
			Printing();
		}

		public void Printing()
		{
			try 
			{
				PrintDocument pd = new PrintDocument();

				// font-height = 0.78 inchs = 78 hundredths of inch?
				printFont = new Font("Arial", 0.78f,System.Drawing.GraphicsUnit.Inch);

				//The width and height of pagper, in hundredths of inch.
				pd.DefaultPageSettings.PaperSize= new PaperSize("MP", 826, 468);

				//The left, right, top, bottom margin, in hundredths of inch.
				pd.DefaultPageSettings.Margins = new Margins (78,78,78,78);
				/*
				 * pageheight=468-78-78 = 312.
				 * Wanted: print 4 lines per page: 4 = 312/78
				 * If not, how can I...
				 * 
				 */

				pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
				// Print the document.
				pd.Print();
			} 
			finally 
			{
			}
		} 
  
		// The PrintPage event is raised for each page to be printed.
		private void pd_PrintPage(object sender, PrintPageEventArgs ev) 
		{
			float linesPerPage = 0;
			float yPos =  0;
			int count = 0;
			float leftMargin = ev.MarginBounds.Left;
			float topMargin = ev.MarginBounds.Top;
			float fontHeight = printFont.GetHeight(ev.Graphics);
            
			// Calculate the number of lines per page.
			linesPerPage = ev.MarginBounds.Height  / fontHeight;

			System.Console.Out.Write("MarginBounds.Height: " + ev.MarginBounds.Height.ToString() + "\n");
			System.Console.Out.Write("Font Height        : " + fontHeight.ToString() + "\n");
			System.Console.Out.Write("Line(s) per Page   : " + linesPerPage.ToString() + "\n\n");
			/*
			 * Expected:
			 * MarginBounds.Height: 312
			 * Font Height        : 78
			 * Line(s) per Page   : 4
			 * 
			 * On my computer, it print out:
			 * 
			 * MarginBounds.Height: 312
			 * Font Height        : 89.69238
			 * Line(s) per Page   : 3.478556
			 * 
			 * Press any key to continue
			 * 
			 * You known, I want to set the fontHeight to 78, because of MarginBounds.Height = 312.
			 * 
			 */

			// Iterate over the file, printing each line.
			while (count < linesPerPage && count < 4) 
			{
				string s = count.ToString() + ":" + fontHeight.ToString() + "/" + ev.MarginBounds.Height.ToString();

				yPos = topMargin + (count * fontHeight);

				ev.Graphics.DrawString (s, printFont, Brushes.Black, leftMargin, yPos, new StringFormat());
				// Draw a line to
				ev.Graphics.DrawLine(new Pen(System.Drawing.Color.Black),leftMargin,yPos,leftMargin+400,yPos);

				count++;
			}

			yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
			ev.Graphics.DrawLine(new Pen(System.Drawing.Color.Black),leftMargin,yPos,leftMargin+400,yPos);
		}

		// This is the main entry point for the application.
		public static void Main(string[] args) 
		{
			new PrintingExample();
		}
	}
}




Nghĩa - I2A4U Group
GeneralTabcontrol Pin
Neko0322-Aug-04 4:45
Neko0322-Aug-04 4:45 
GeneralRe: Tabcontrol Pin
steven shingler22-Aug-04 10:09
steven shingler22-Aug-04 10:09 
GeneralRe: Tabcontrol Pin
leppie22-Aug-04 10:45
leppie22-Aug-04 10:45 
GeneralTrouble in setting up for a project Pin
intrigued22-Aug-04 4:32
intrigued22-Aug-04 4:32 
GeneralRe: Trouble in setting up for a project Pin
sreejith ss nair22-Aug-04 20:03
sreejith ss nair22-Aug-04 20:03 
GeneralRe: Trouble in setting up for a project Pin
bestwsfz3j26-Aug-04 19:45
bestwsfz3j26-Aug-04 19:45 
GeneralMSI Pin
intrigued22-Aug-04 4:24
intrigued22-Aug-04 4:24 
GeneralRe: MSI Pin
sreejith ss nair22-Aug-04 20:00
sreejith ss nair22-Aug-04 20:00 
GeneralSticky tabs in RichTextBox Pin
RichGuk22-Aug-04 2:53
RichGuk22-Aug-04 2:53 
GeneralRe: Sticky tabs in RichTextBox Pin
leppie22-Aug-04 3:48
leppie22-Aug-04 3:48 
GeneralRe: Sticky tabs in RichTextBox Pin
Aaron Eldreth22-Aug-04 7:27
Aaron Eldreth22-Aug-04 7:27 
GeneralRe: Sticky tabs in RichTextBox Pin
leppie22-Aug-04 7:58
leppie22-Aug-04 7:58 
GeneralRe: Sticky tabs in RichTextBox Pin
RichGuk23-Aug-04 1:40
RichGuk23-Aug-04 1:40 
Generalone of my friends wants sourcecode of game flat eagerly Pin
bestwsfz3j22-Aug-04 2:26
bestwsfz3j22-Aug-04 2:26 
GeneralRe: one of my friends wants sourcecode of game flat eagerly Pin
leppie22-Aug-04 3:49
leppie22-Aug-04 3:49 
GeneralRe: one of my friends wants sourcecode of game flat eagerly Pin
heile25-Aug-04 7:41
heile25-Aug-04 7:41 
GeneralRe: one of my friends wants sourcecode of game flat eagerly Pin
bestwsfz3j26-Aug-04 19:41
bestwsfz3j26-Aug-04 19:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.