|
Hi duncan.
Thanks for your tip. I actually tried using printdoc.originatmargins= true
but didnt notice any improvement. are you able to tell me if there's another
way of using this if there is one.
Kind Regards
Robbo
|
|
|
|
|
I think he as eluding to the fact that every printer as unprintable margins and that this is where the margins that you are talking about start at. For example:
Edge of paper
------------------------------------------------------+
(unprintable margin) |
----------------------------------------------------+ |
Top Margin 0.0" | |
| |
---document begins here with a margin of 0.5" | |
but is actually 0.75" from the top of the page | |
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi Dave
So i take it from you that its ok to see one thing in print preview and get something close on paper right ?... please clear this up for me.
also if this is the case is it ok for me to consider creating an xml file used to manipulate margins for different printers if need be.
i guess what i need to know is what is the proper standard for this type of thing.
many thanks Dave
Robbo
Robbo
|
|
|
|
|
It looks like your print preview code is making certain assumption about the page and not taking into account the margins. The one thing you haven't done is posted any code to show us how your seting up your printing.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi Dave
Here is my code as you requested . Just to remind you print preview margins are great but printouts are not but only slightly off. i look forward to your comments to hopefully include some things to do.
CODE
====
RE: Imports System.Drawing.Printing
Public Class supreport
Private m_PagesPrinted As Integer
Private totalpages As Integer
' Display a print preview.
Private Sub btnPrintPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintPreview.Click
' Make a PrintDocument and attach it to
' the PrintPreview dialog.
dlgPrintPreview.Document = PreparePrintDocument()
dlgPrintPreview.WindowState = FormWindowState.Maximized
dlgPrintPreview.PrintPreviewControl.Zoom = 1.0 'set zoom preview to %100
' Preview.
dlgPrintPreview.WindowState = FormWindowState.Maximized
dlgPrintPreview.ShowDialog()
End Sub
Private Function PreparePrintDocument() As PrintDocument
' Make the PrintDocument object.
Dim print_document As New PrintDocument
With PageSetupDialog1
.PageSettings = print_document.DefaultPageSettings
End With
If PageSetupDialog1.ShowDialog = Windows.Forms.DialogResult.Yes Then
print_document.DefaultPageSettings = PageSetupDialog1.PageSettings
End If
AddHandler print_document.BeginPrint, AddressOf Print_BeginPrint
AddHandler print_document.QueryPageSettings, AddressOf Print_QueryPageSettings
AddHandler print_document.PrintPage, AddressOf Print_PrintPage
AddHandler print_document.EndPrint, AddressOf Print_EndPrint
' Return the object.
Return print_document
End Function
' Get ready to print pages.
Private Sub Print_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs)
m_PagesPrinted = 0
getdata() 'load data to print/preview
End Sub
' Print the next page.
Private Sub Print_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
' Increment the page number.
m_PagesPrinted += 1
'**********RECTANGLES
Dim headingrect As New Rectangle(130, 100, 600, 800)
Dim DateRect As New Rectangle(e.MarginBounds.Left, 170, 100, 800)
Dim InvRect As New Rectangle(e.MarginBounds.Left + 130, 170, 130, 800)
Dim NameRect As New Rectangle(e.MarginBounds.Left + 281, 170, 100, 800)
Dim PDRect As New Rectangle(390, 170, 100, 800)
'*****************
'********FONTS
Dim headingfont As Font
headingfont = New Font("Times New Roman", 12, FontStyle.Underline, GraphicsUnit.Point)
Dim datafont As Font
datafont = New Font("Times New Roman", 10, FontStyle.Regular, GraphicsUnit.Point)
Dim subheadingsfont As Font
subheadingsfont = New Font("Time New Roman", 10, FontStyle.Regular, GraphicsUnit.Point)
'**************
'********STRING FORMATS
Dim headingstringformat As New StringFormat
headingstringformat.Alignment = StringAlignment.Center
Dim datastringformat As New StringFormat
datastringformat.Alignment = StringAlignment.Near
'********************
Dim reportheading As String = "Supplier Report As Of " & Today
Dim companyheading As String = "Company"
Dim addressheading As String = "Address"
Dim suburbheading As String = "Suburb"
Dim pcodeheading As String = "Postcode"
Dim ph1heading As String = "Phone 1"
Dim ph2heading As String = "Phone 2"
Dim contactheading As String = "Contact"
e.Graphics.DrawString(reportheading, headingfont, _
Brushes.Black, headingrect, headingstringformat) ' draw company heading details
e.Graphics.DrawString(ComData, datafont, Brushes.Black, DateRect, datastringformat)
e.Graphics.DrawString(AddressData, datafont, Brushes.Black, InvRect, datastringformat)
e.Graphics.DrawString(SubData, datafont, Brushes.Black, NameRect, datastringformat)
e.Graphics.DrawString(PcodeData, datafont, Brushes.Black, PDRect, datastringformat)
e.Graphics.DrawString(companyheading, subheadingsfont, Brushes.Black, e.MarginBounds.Left, 150)
e.Graphics.DrawString(addressheading, subheadingsfont, Brushes.Black, e.MarginBounds.Left + 130, 150)
e.Graphics.DrawString(suburbheading, subheadingsfont, Brushes.Black, 320, 150)
e.Graphics.DrawString(pcodeheading, subheadingsfont, Brushes.Black, 390, 150)
e.Graphics.DrawString(ph1heading, subheadingsfont, Brushes.Black, 480, 150)
e.Graphics.DrawString(ph2heading, subheadingsfont, Brushes.Black, 560, 150)
e.Graphics.DrawString(contactheading, subheadingsfont, Brushes.Black, 660, 150)
' Draw the margins (for debugging).
e.Graphics.DrawRectangle(Pens.SkyBlue, e.MarginBounds)
Dim the_font As Font
Dim string_format As New StringFormat
the_font = New Font("Times New Roman", _
8, FontStyle.Regular, GraphicsUnit.Point)
Dim getwidth As Int32 = e.PageBounds.Width
Dim getbottom As Int32 = e.MarginBounds.Bottom
getwidth = getwidth / 2
' MsgBox("getwidth " & getwidth)
e.Graphics.DrawString("( Page " & m_PagesPrinted.ToString & ")", _
the_font, Brushes.Black, getwidth, _
(120), _
string_format)
End Sub
End Class
|
|
|
|
|
Your code is based on the MarginBounds of the page, not the page bounds. It treating the top-left corner of the MarginBounds as the top-left corner of the page. Try using PageBounds instead of MarginBounds and see what happens.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thankyou Dave. I'll try your suggestion and get back to you.
Many thanks as always.
Robbo
|
|
|
|
|
Have been programming not just .net but as a whole for 2 years now and am self taught so I still am a begginner and far from intermediate. I cannot find any good resources or tutorials for working with the right click event. The only thing I wish to learn really is how to implement right click functionality to a row/record in a listview. If any of you guys know of any websites or text that could help me out with this, please let me know. Also, if you could help me to just get started because I really dont even know where to start!!! Thank you in advance for your help.
|
|
|
|
|
|
Hi all, my other question about Graphics.DrawString is that:
When I'm writing shoot date on the horizontal photo everything is great but the same things are not applied to vertical taken photos. On 2560x1920 string is great but on 1920x2560 so small. I'm taking position with
<br />
Dim f As New Font(FontFamily.GenericSerif, 35.0F, FontStyle.Regular, GraphicsUnit.Point)<br />
graph.DrawString(enc.GetString(bytes), f, Brushes.Yellow, CSng(img.Width) - 400.0F, CSng(img.Height) - 50.0F)<br />
Something wrong? Thanks..
Savas Cilve
|
|
|
|
|
There's nothing wrong with the code you've posted. An image is an image is an image. It doesn't matter what orientation the camera was in when the shot was taken. It's entirely possible that there's something wrong with the code that is passing in the image to this code that you posted.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
That's my entire code for the writing string.
<br />
For Each img As Image In _images<br />
Dim changed As Boolean = False<br />
Dim f As New Font(FontFamily.GenericSerif, 35.0F, FontStyle.Regular, GraphicsUnit.Point)<br />
Dim graph As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(img)<br />
Dim pi() As Drawing.Imaging.PropertyItem = img.PropertyItems<br />
Dim bytes() As Byte<br />
Dim enc As New System.Text.UTF8Encoding<br />
<br />
For Each pItem As Drawing.Imaging.PropertyItem In pi<br />
If pItem.Id = 36867 Then<br />
bytes = pItem.Value<br />
graph.DrawString(enc.GetString(bytes), f, Brushes.Yellow, CSng(img.Width) - 400.0F, CSng(img.Height) - 50.0F)<br />
changed = True<br />
Exit For<br />
End If<br />
Next<br />
<br />
If changed Then<br />
img.Save(_imagesHash.Item(img).ToString() & ".jpg")<br />
End If<br />
Next<br />
and I'm storing images and their paths in the hashtable.
oh last thing: When the image saved its size decreasing from 2mb to 250kb
Savas Cilve
|
|
|
|
|
Again, nowhere in your code do you call Dispose() on the Graphics object you're creating. You MUST ALWAYS call .Dispose() on a Graphics object when you're done using it, otherwise you get odd behavior, kind of like changes not being saved, when manipulating images and your app is suddenly leaking GDI Handles and will eventually crash the system! BTW, you also have to .Dispose() Font objects when you're done with them too.
Since you're only using the Graphics object when a property item contains a certain value, I suggest not creating any Graphics or Font objects unless you need them:
Imports System.Drawing.Imaging
.
.
.
For Each img As Image In _images
Dim changed As Boolean = False
Dim pi() As Drawing.Imaging.PropertyItem = img.PropertyItems
For Each pItem As Drawing.Imaging.PropertyItem In pi
If pItem.Id = 36867 Then
Dim bytes() As Byte = pItem.Value
Dim f As New Font(FontFamily.GenericSerif, 35.0F, FontStyle.Regular, GraphicsUnit.Point)
Dim graph As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(img)
Dim enc As New System.Text.UTF8Encoding
graph.DrawString(enc.GetString(bytes), f, Brushes.Yellow, CSng(img.Width) - 400.0F, CSng(img.Height) - 50.0F)
graph.Dispose()
f.Dipose()
' Create a JPEG Encoder and set it's Compression quality
Dim jpegCodec As ImageCodecInfo = GetEncoderInfo("image/jpeg")
Dim encoderParams As New EncoderParameters(1)
encoderParams.Param[0] = New EncoderParameter(Encoder.Quality, 100)
' Save the image using the new encoder
img.Save(_imagesHash.Item(img).ToString() & ".jpg", jpegCodec, encoderParams)
Exit For
End If
Next
Next
.
.
.
Public Shared Function GetEncoderInfo(ByVal mimeType As String) As ImageCodecInfo
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders()
For i As Integer = 0 To codecs.Length
If codecs[i].MimeType = mimeType Then
Return codecs[i]
End If
Next
Return Nothing
End Sub
The reason why it's size changes is because you didn't specify the format to use when the image is saved. In your case, the image is saved as PNG format, not JPG. The filename you give doesn't determine the format of the image written. If you want to save an image in JPG format, you have to tell it to do so. If you want to control the compression used on the JPG image, you have to add EncoderParameters to spell out how the JPG should be handled. Those above has been modified to do this.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thanks a lot for making my code much more better
|
|
|
|
|
I am inserting text files into MySQL using vb.net. However, when I insert the files into the database it only insert every other file. For example, it will insert one file then the next row will be zeros. Does any one know why it might be doing this. Here is some code:
Dim myConnString AsString = "DRIVER={MySQL ODBC 3.51 Driver};" & _
"SERVER=192.168.1.27;" & _
"DATABASE=testship;" & _
"USER=?;" & _
"PASSWORD=?;" & _
"OPTION=3;"
Dim MyConnection AsNew Odbc.OdbcConnection(myConnString)
MyConnection.Open()
Dim MyCommand AsNew Odbc.OdbcCommand("INSERT INTO ls_orderitems (OrderDate, OrderCustomer, OrderAcctNum, OrderType, OrderSoNum, OrderItemPartNum, OrderItemPartDesc, OrderItemQty, OrderItemQtyRec, OrderItemQtyDtRec, OrderItemBO, OrderItemBODt,OrderItemCanceled, OrderItemCanceledDt, OrderItemNotes, OrderItemPONum, OrderItemRetailPrice, OrderItemSalePrice, Status, InsertDate) VALUES ('" & OrderDate & "','" & OrderCustomer & "','" & OrderAcctNum & "','" & OrderType & "','" & OrderSoNum & "','" & OrderItemPartNum & "','" & OrderItemPartDesc & "','" & OrderItemQty & "','" & OrderItemQtyRec & "','" & OrderItemQtyDtRec & "','" & OrderItemBO & "','" & OrderItemBODt & "','" & OrderItemCanceled & "','" & OrderItemCanceledDt & "','" & OrderItemNotes & "','" & OrderItemPONum & "','" & OrderItemRetailPrice & "','" & OrderItemSalePrice & "','" & Status & "','" & InsertDate & "')")
MyCommand.Connection = MyConnection
MyCommand.ExecuteNonQuery()
MyConnection.Close()
jds1207
|
|
|
|
|
jds1207 wrote: I am inserting text files into MySQL using vb.net. However, when I insert the files into the database it only insert every other file. For example, it will insert one file then the next row will be zeros
???
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Well, from the description of the problem, there's something wrong with either the code that reads the files, or the code that validates the data, or the code that inserts the file into the database. And what have we told you about using parameterized queries?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Oh! oh!! I know! I know! ** Sticks hand high in the air** We should use parameterised queries! We should use them becuase it makes the application safe from people trying to inject into it!
|
|
|
|
|
Colin Angus Mackay wrote: Oh! oh!! I know! I know! ** Sticks hand high in the air**
Ah, yes! The Scottish guy in the back there...
Colin Angus Mackay wrote: We should use parameterised queries! We should use them becuase it makes the application safe from people trying to inject into it!
Very good! You get a Gold Star for the day!
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Sounds nice but I am having trouble getting my parameterised query to work using MySQL. However, the code that I am currently using to insert is working fine now. Also, I found out why the empty rows are being inserted into the db. The file that I am cleaning is being cleaned and making the file double spaced. I could use a helping hand with this issue. Here is the code that I used to clean the file:
'Read file line by line
Dim file_name As String = "c:\Scanning files\lsprint_MO.txt"
Dim Temp_file As String = "c:\Scanning files\lsprint_MO_temp.txt"
Dim textline As String
If System.IO.File.Exists(file_name) = True Then
Dim objReader As New System.IO.StreamReader(file_name)
Do While objReader.Peek() <> "-1"
textline = String.Concat(objReader.ReadLine(), ControlChars.NewLine)
If textline.IndexOf("xxxxxxx") = 17 Then
Console.WriteLine(textline)
WriteFile(Temp_file, textline)
End If
Loop
objReader.Close()
My.Computer.FileSystem.DeleteFile(file_name)
End If
Any ideas would help!
|
|
|
|
|
jds1207 wrote: The file that I am cleaning is being cleaned and making the file double spaced.
It's called Validation and you're not doing anything to verify that what you're reading is valid. You're just assuming that what you have in your variables is good and that's why your database is comming up with zeros.
You're going about reading a text file the hard way.
Dim sourceFilename As String = "C:\Scanning files\lsprint_MO.txt"
Dim tempFilename As String = "C:\Scanning files\lsprint_MO_temp.txt"
Dim textline As String
If System.Io.File.Exists(sourceFilename) Then
Try
Dim sr As New StreamReader(sourceFilename)
Do
textline = sr.ReadLine()
' Why are you using String.Concat?? Your building a line and adding
' blank lines to the textline string. Why??
' Parse your line here and make sure that the values you got are VALID!
' If not, jump to some other method to report or log the problem.
' If we get here, the data looks good. Add it to the database.
' Call your database code here and pass the "cleaned" values to it.
Loop Until textline Is Nothing
Catch ex As Exception
' Something happened during the file read or database call.
' Log the error or report it somehow and forget the rest of the file.
Finally
If Not sr Is Nothing Then
sr.Close()
End If
End Try
It would also help to see a sample of the file you're trying to read and parse.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thanks! That worked fine.
|
|
|
|
|
Hi All,
Can anyone please tell me what does the Err.LastDllError() return?
|
|
|
|
|
|
What does the Err.LastDllError return?
|
|
|
|
|