I have a sample code.. below with my Print problem... I am not able to get
the Label on Image print at the right location..
VJ
private Label label4 = new Label();
Form1's Load...
label4.BackColor=Color.White;
label4.BorderStyle=BorderStyle.FixedSingle;
label4.Text = "label4";
label4.Location=new Point(300,1450);
label4.Size = new Size(50,50);
pictureBox1.Controls.Add(label4);
// pictureBox1 is a control on Form1, inisde Panel1
// with a large enough image to have scroll bars...
// the picturebox1.SizeMode = SizeMode.Normal
Button Click Event
PrintDocument printDoc = new PrintDocument();
printDoc.PrintPage+=new PrintPageEventHandler(printDoc_PrintPage);
PrintPreviewDialog printPreviewDlg = new PrintPreviewDialog();
printPreviewDlg.Document = printDoc;
printPreviewDlg.ShowDialog();
private void printDoc_PrintPage(object sender, PrintPageEventArgs e)
{
Bitmap imageForPrinting = new Bitmap(pictureBox1.Width,
pictureBox1.Height);
using (Graphics graphicsImage = Graphics.FromImage(imageForPrinting))
using (DibGraphicsBuffer dib = new DibGraphicsBuffer())
// Create temporary screen graphics
using (Graphics graphicsForm = this.CreateGraphics())
// Create temporary graphics from the Device Independent Bitmap
using (Graphics graphicsTemp =
dib.RequestBuffer(graphicsForm, e.PageBounds.Width,
e.PageBounds.Height))
{
graphicsTemp.DrawImage(pictureBox1.Image,
e.PageBounds,
0, 0, pictureBox1.Width, pictureBox1.Height,
GraphicsUnit.Pixel);
// The below piece of code is not printing.. on the Print Documents.. I
know
// we have to transform points.. but How do we do that???
PointF labelLocation = new PointF(label3.Left, label3.Top);
graphicsTemp.DrawString(label3.Text, label3.Font,
new SolidBrush(Color.Black), labelLocation);
// Use the buffer to paint onto the final image
dib.PaintBuffer(graphicsImage, 0, 0);
// Draw this image onto the printer graphics,
// adjusting for margins
e.Graphics.DrawImage(imageForPrinting,
e.MarginBounds.Left, e.MarginBounds.Top);
}
} 1 11337
Ok sorry people... that was a momentary loss of Math Mindset......I got
it... just add these lines instead of the existing text printing...
PointF ptAtt = new PointF(
((float)e.PageBounds.Width/(float)pictureBox1.Width)
, ((float)e.PageBounds.Height/(float)pictureBox1.Height) );
PointF labelLocation = new PointF(ptAtt.X * (float)label4.Left, ptAtt.Y
* (float)label4.Top);
graphicsTemp.DrawString(label4.Text, label4.Font,
new SolidBrush(Color.Black), labelLocation);
VJ
"VJ" <vi********@yahoo.com> wrote in message
news:O1**************@TK2MSFTNGP10.phx.gbl... I have a sample code.. below with my Print problem... I am not able to get the Label on Image print at the right location.. VJ
private Label label4 = new Label();
Form1's Load...
label4.BackColor=Color.White; label4.BorderStyle=BorderStyle.FixedSingle; label4.Text = "label4"; label4.Location=new Point(300,1450); label4.Size = new Size(50,50); pictureBox1.Controls.Add(label4);
// pictureBox1 is a control on Form1, inisde Panel1 // with a large enough image to have scroll bars... // the picturebox1.SizeMode = SizeMode.Normal
Button Click Event
PrintDocument printDoc = new PrintDocument(); printDoc.PrintPage+=new PrintPageEventHandler(printDoc_PrintPage);
PrintPreviewDialog printPreviewDlg = new PrintPreviewDialog(); printPreviewDlg.Document = printDoc; printPreviewDlg.ShowDialog();
private void printDoc_PrintPage(object sender, PrintPageEventArgs e) {
Bitmap imageForPrinting = new Bitmap(pictureBox1.Width, pictureBox1.Height); using (Graphics graphicsImage = Graphics.FromImage(imageForPrinting)) using (DibGraphicsBuffer dib = new DibGraphicsBuffer()) // Create temporary screen graphics using (Graphics graphicsForm = this.CreateGraphics()) // Create temporary graphics from the Device Independent Bitmap using (Graphics graphicsTemp = dib.RequestBuffer(graphicsForm, e.PageBounds.Width, e.PageBounds.Height)) {
graphicsTemp.DrawImage(pictureBox1.Image, e.PageBounds, 0, 0, pictureBox1.Width, pictureBox1.Height, GraphicsUnit.Pixel);
// The below piece of code is not printing.. on the Print Documents.. I know // we have to transform points.. but How do we do that???
PointF labelLocation = new PointF(label3.Left, label3.Top); graphicsTemp.DrawString(label3.Text, label3.Font, new SolidBrush(Color.Black), labelLocation);
// Use the buffer to paint onto the final image dib.PaintBuffer(graphicsImage, 0, 0); // Draw this image onto the printer graphics, // adjusting for margins e.Graphics.DrawImage(imageForPrinting, e.MarginBounds.Left, e.MarginBounds.Top);
}
} This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Kate |
last post by:
Hi:
I have a picturebox control, and at runtime various usercontrols are
added to it to make a diagram. As dynamically added usercontrols, they
are of type VBExtender.
Is there a way to save...
|
by: Pavan Arise |
last post by:
Dear all..
I have a picturebox filled on a form. The picturebox has some
graphics displayed on it.I was trying to save the picturebox, but
continuesly failed to do so. I am clueless of why it is...
|
by: Neal |
last post by:
Hi,
I saw the VB6 Code to do this at this link:
http://www.dotnet247.com/247reference/msgs/11/56581.aspx
The VB6 Code reads as follows:
Private Type Rect
Left As Long
|
by: Ikey |
last post by:
I am trying to allow a user to drag a Picturebox control around the
form and drop it in a new location.
Currently, I was trying to use the following:
Private Sub PictureBox1_MouseMove(ByVal...
|
by: CG3000 |
last post by:
I have an Image in a picture box in VS 2005 that I want to print using
the following event handlers:
Private Sub btnPrintLabels_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs)...
|
by: mungelwar |
last post by:
Hi friend,
I need to print picturebox or form in vb6, which contain other controls & user controls. I used several methods like capture screen or printform method but the form size which i m using...
|
by: Christie |
last post by:
In my application, lines (shapes such as circles) and text are drawn in
a picturebox. I am struggling to find a way to print the text and
shapes. There is no images in the picturebox. Could...
|
by: kaymaf |
last post by:
Hi , i wrote an application to make ID Card, i used textbox, label and picturebox on a panel. i want to print the panel and the control on it but when i preview the document, the image on the...
|
by: VICTOR DIACONO |
last post by:
I have the following problem.
I am trying to print the contents of a number of Textboxes into Labels on a Picturebox. Then I wish to output the Picturebox to the screen.
Ok, it is a simple...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |