I've been working on a label system in VB web app that prints to the Toshiba TEC Barcode printers for quite a while lately and it never seems to line up properly. I've tried changing the settings, and adjusting paper size, only re-calibrating the printer seems to help for a bit and then the alignment goes off again.
What I've been thinking of trying to do to overcome this issue is place a Button on the page that would allow the user to re-set/re-calibrate the printer. Figure this is better than them pulling on the label to line it back up again.
Here is the code used to print the label:
Public Sub SetPrintSettings(ByVal pd As PrintDocument, ByVal printer As String, ByVal printerselected As Integer)
Dim pSize As PaperSize
'set the printer
pd.PrinterSettings.PrinterName = printer
pd.DefaultPageSettings.Landscape = False
pSize = New PaperSize("USER", 400, 202)
pd.DefaultPageSettings.PaperSize = pSize
pd.DefaultPageSettings.Margins = New Margins(0, 0, 0, 0)
End Sub
I've gone through the PrinterSettings and DefaultPageSettings and there is nothing in there that will allow me to reset the printer.
Anyone have any ideas?
This is a comment really but I have put it as an answer so it formats better:
My guesses on what is causing this problem.
Too small a gap between labels. These printers can be very fussy about detecting the gap
Broken gap sensor on the printer
Incorrect commands being sent to the printer e.g. specifying a label size bigger than it actually is.
Related
I am using EDRAW to browse a Microsoft Word and can be Print , Preview , ETC... And I am planning to add some features to it. I am adding 2 buttons for Print Short (8.5 by 11 inches) and Print Long (8.5 by 13 inches) and I have 2 printers for long and short. How to set the properties of the printers in each button?. If I click button short it will print short using printer 1 same as the button long but it is in printer 2.
I am following the code in the Link provided above.
Anyone has an idea about it?. Any suggestion well help and well be accepted. Thanks.. Cheers.. I will give a 50 bounty to it after two days..
Code as #Hadi request
Here is my button code for print.
Private Sub btnPrint_Click(sender As System.Object, e As System.EventArgs) Handles btnPrint.Click
AxEDOffice1.SetActivePrinter("Printer Name")
AxEDOffice1.ActiveDocument.PageSetup.PaperSize = Microsoft.Office.Interop.Word.WdPaperSize.wdPaperA4
AxEDOffice1.PrintDialog()
End Sub
and getting an error Object variable or With block variable not set in the line code of AxEDOffice1.ActiveDocument.PageSetup.PaperSize = Microsoft.Office.Interop.Word.WdPaperSize.wdPaperA4
After Checking the library all you have to do is using SetActivePrinter Method to change your default printer like the following:
AxEDOffice1.SetActivePrinter("Adobe PDF")
And to change PaperSize you have to use the following
AxEDOffice1.ActiveDocument.PageSetup.PaperSize = Microsoft.Office.Interop.Word.WdPaperSize.wdPaperA4
AxEDOffice1.ActiveDocument is an instance of Microsoft.Office.Interop.Word.WordDocumentClass
Code tested it and it works fine.
EDIT 1:
Object variable or With block variable not set
Read more about it on this MSDN article there are many suggestions.
EDIT 2:
To Print your document directly without showing PrintDialog you have to use PrintOut Function.
AxEDOffice1.PrintOut(EDOfficeLib.WdPrintOutRange.wdPrintAllDocument)
It looks like Change printername in PrintDialog through code deals with making sure a print dialog box pre-selects the printer based on printer name in vb.net.
I have created a COM VB.NET (v3.5 under VS2013) usercontrol which i have included in an old VB6 project. The control communicates with its VB6 host just fine. It works as expected, opens the DB, reads / writes stuff. Everything is OK except one thing, which i'm not sure what it is. It seems i cannot properly set either its font(?) or its language(?) to Greek in order to be able to type Greek characters in a contained textbox.
This usercontrol contains several other .NET controls. Listboxes, buttons and textboxes. I read stuff from DB, set the text property of all those controls to the contents of the database and Greek are shown properly. If i try to switch the O/S language to Greek and type something in a textbox, strange characters are shown instead of the proper Greek ones (i assume from another codepage). I have programmatically changed its font to "[Font: Name=Arial, Size=9, Units=3, GdiCharSet=161, GdiVerticalFont=False]". GdiCharSet=161 is Greek. It should work. And it does work from within the .NET environment or from a test .NET exe. I can type Greek in the textbox. When i try to use it from within the VB6 program, it seems switching to Greek and typing Greek chars is not possible. Loading Greek from DB and showing them is no problem though.
I have also tried setting GdiCharSet to 0, 1, 2 (yup, it did show Symbols as expected) and to change the culture in the usercontrol constructor but no luck:
System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("el-GR")
System.Threading.Thread.CurrentThread.CurrentUICulture = New System.Globalization.CultureInfo("el-GR")
Any ideas someone, what to check / try?
Wow... After spending more hours than i could spare on this matter, i have finally found a solution.
Private Sub txtMessage_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtMessage.KeyPress
If InputLanguage.CurrentInputLanguage.Culture.Equals(New Globalization.CultureInfo("el-GR")) Then
FixKeyChar(e)
End If
End Sub
Public Sub FixKeyChar(ByRef e As KeyPressEventArgs)
Dim myUnicodeBytes As Byte() = Encoding.Unicode.GetBytes(e.KeyChar)
Dim myUTF32Bytes As Byte() = Encoding.Convert(Encoding.Default, Encoding.UTF32, myUnicodeBytes)
e.KeyChar = ChrW(myUTF32Bytes(1) * 256 + myUTF32Bytes(0))
End Sub
I hope it proves to be helpful for some other poor soul messing with these things...
I'm having difficulties in using Win API GetWindowDC to get a valid hDC for drawing.
I'm using vb.net 2013, and I tried to bitblt images to a form, draw string, draw rectangle, and nothing.
I'm running in Win7 all the tests.
Do I have to disable aero with DWM functions, is it a handle trick, or what is? I already posted a "draw in titlebar vb.net 2013" question that had no answer, where I have some code used, but right now, I just need a working example to start. All help is appreciated.
But here goes some more code that doesn't work either.
Select Case m.Msg
Case WinAPI.Win32Messages.WM_NCPAINT
Dim hDC As IntPtr = WinAPI.GetWindowDC(m.HWnd)
Dim g As Graphics = Graphics.FromHwnd(hDC)
g.DrawString("TESTE", New Font("ARIAL", 16), New SolidBrush(Color.Black), 5, 5)
g.Dispose()
WinAPI.ReleaseDC(m.HWnd, hDC)
The error is OutOfMemory, and nothing gets drawn anywhere, even with tests done to clientarea.
It's a simple purpose. Getting to draw in all the areas of a form, and from that on, I'll handle the drawing.
Well, thanks at least for the help on correctly editing. About the Graphics.FromHDC, yes, I tried it.
But here goes some more code that doesn't work either.
Select Case m.Msg
Case WinAPI.Win32Messages.WM_NCPAINT
Dim hDC As IntPtr = WinAPI.GetWindowDC(m.HWnd)
Dim g As Graphics = Graphics.FromHwnd(hDC)
g.DrawString("TESTE", New Font("ARIAL", 16), New SolidBrush(Color.Black), 5, 5)
g.Dispose()
WinAPI.ReleaseDC(m.HWnd, hDC)
The error is OutOfMemory, and nothing gets drawn anywhere, even with tests done to clientarea.
It's a simple purpose. Getting to draw in all the areas of a form, and from that on, I'll handle the drawing. And too bad for the negative votes. Doesn't help, cause if people where fast on the negative voting...try to be as fast on reading all of what's placed in a question, and finding out that it is not just "gimme gimme codez" - the other referenced question has code.
People that know a lot forget that once you where like me, and didn't know a lot about the subject...might not even know how to ask the right questions...
Thanks for the help, if someone can provide it.
Graphics.FromHwnd() takes a window handle, not a DC (the clue is in the name). Try Graphics.FromHdc() instead.
So I'm trying to make an overlay for a full screen game. Firstly this isn't for hacking purposes, the game shows times as little clocks and I find this difficult to read, so when I press a key to activate something I want to be able to see how long ago I activated it etc.
I currently have this code to write the time to the screen:
Private Shared Sub DrawOverlay(ByVal OverlayString As String)
Dim Processes = Process.GetProcessesByName("GAMECLIENT")
Dim deviceContext As Graphics = Graphics.FromHwnd(Processes(0).MainWindowHandle)
Dim drawFont As New Font("Arial", 14, FontStyle.Bold)
Dim myBrush As New Drawing2D.LinearGradientBrush(deviceContext.ClipBounds, Color.Black, Color.SkyBlue, Drawing2D.LinearGradientMode.Horizontal)
Dim drawFormat As New StringFormat()
drawFormat.FormatFlags = StringFormatFlags.NoFontFallback
deviceContext.DrawString(OverlayString, drawFont, myBrush, 100, 100, drawFormat)
End Sub
To be clear this code isn't mine. It's just what I've found from research. This works, however it's extremely slow. It actually makes the game free for about 5 seconds. I think the time consuming line is:
deviceContext.DrawString(OverlayString, drawFont, myBrush, 100, 100, drawFormat)
By process of playing around with other lines it seems to be almost defiantly this line. However I can't work out how to speed it up. I even published the application, just in case it was the debugger. No difference. However this doesn't work for full screen which isn't ideal, if anyone could explain why that would probably help me out.
On a related note if anyone has/knows of a DLL I can reference to do this quickly and more effectively (ESPECALLY FOR FULL SCREEN) that would be great!
So to sum up:
1) Why is that line so slow
2) How should I speed it up
3) Is there another way to do this that works with full screen.
Thanks!
Hey, making a media player and need to know something.
I have a menu which reads file info, but for some reason, when I open a video that I KNOW is 1280x720, the width and height come up as 1292x758.
Edit:
When I open a video which is 640x480, it says it's 656x518
That, and an extra preview box pops up due to:
labFR.Text = "Frame rate: " & Strings.FormatNumber((1 / AudioVideoPlayback.Video.FromFile(labinput.text, True).AverageTimePerFrame), 3)
This needs to be playing so I can get the frame rate, but how to I close it once I have the frame rate?
Working in VB.NET Framework 4.0. (VS2010)
Answers to either of these problems are highly appreciated.
Got it. I have to Dim the Video outside of all the modules with autoplay set to false, then I can grab all the properties from the video without constantly opening the video on several threads over and over.
Dim openerfile As Video
Public Sub btnInputBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInputBrowse.Click
openerfile = Video.FromFile(labinputfile.Text, False) 'labinputfile is a textbox which is given the path of an openfiledialog
End Sub
Then all I have to do is use "openerfile" and its properties for what I wish.