I've got a custom control that I'm trying to print. I've tried changing the margin's on my window to "indent" my control, but it still cuts off the left and top. I've also tried the following in my print method:
private void bttnPrint_Click(object sender, RoutedEventArgs e)
{
UserControl hddc = HDDC;
var printDlg = new PrintDialog
{PrintTicket = {PageOrientation = PageOrientation.Landscape, PageBorderless = PageBorderless.Unknown}};
//printDlg.PrintTicket.PageMediaSize.PageMediaSizeName = PageMediaSizeName.NorthAmerica11x17;
if (printDlg.ShowDialog() == true)
{
printDlg.PrintVisual(hddc, "HDDC Report");
}
else
{
MessageBox.Show("Print Canceled");
}
}
Still, no joy. I've got the feeling there's a silly setting I'm missing, but I just can't seem to find it. Why is my print cutting off on the top and left?
public void Printing() {
try {
streamToPrint = new StreamReader (filePath);
try {
PrintDocument prd = new PrintDocument();
prd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
prd.PrinterSettings.PrinterName = printer;
// Set the page orientation to landscape.
prd.DefaultPageSettings.Landscape = true;
prd.Print();
}
finally {
streamToPrint.Close() ;
}
}
catch(Exception ex) {
MessageBox.Show(ex.Message);
}
}
Namespace: System.Drawing.Printing
or maybe this link can help u
Page truncate in right side for landscape orientation with trimmargins using PdfSharp
Related
that drives me nuts. I try to silent print a ribbon (1000 mm height, 150 mm width). The content is a Canvas containing a formatted Text.
If I use "Microsoft Print To PDF" it works and looks OK. When i go on and use the OKI Printer from the pdf it is fine!
If I directly try to print using the OKI, I will get a blank ribbon or (if i change some parameters) I get a very small text in the middle of nowhere.
Any ideas? Unfortunatly it is nearly impossible to Debug.
This is the print function:
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
PrintDialog prnt = new PrintDialog();
//PrintQueue queue = new LocalPrintServer().GetPrintQueue("Microsoft Print To PDF");
PrintQueue queue = new LocalPrintServer().GetPrintQueue("OKI C3450");
prnt.PrintQueue = queue;
//var f = queue.GetPrintCapabilities();
prnt.PrintTicket = new PrintTicket();
prnt.PrintTicket.PageMediaSize = new PageMediaSize(3779.53, 566.93);
prnt.PrintTicket.PageOrientation = PageOrientation.Landscape;
//if (prnt.ShowDialog() == true)
//{
Size pageSize = new Size(3779.53, 566.93);
var canvasToPrint = this.backgroundCanvasSchleife1;
this.backgroundCanvasSchleife1.Measure(pageSize);
this.backgroundCanvasSchleife1.Background = new SolidColorBrush(Colors.Transparent);
this.backgroundCanvasSchleife1.Children.RemoveRange(0, this.backgroundCanvasSchleife1.Children.Count-1);
this.backgroundCanvasSchleife1.Arrange(new Rect(0, 0, pageSize.Width, pageSize.Height));
//if (prnt.ShowDialog() == true)
//{
// try
//{
prnt.PrintVisual(this.backgroundCanvasSchleife1, "Printing Canvas");
//}catch (Exception ex)
//{
// var t = ex;
//}
//}
//}
//this.Close();
}
I'm trying to create a WPF which can preview documents(word,pdf,png,jpg) located on my HDD. I've tried using printPreviewControl but I cant get it working.
Code:
public Form1()
{
InitializeComponent();
initComponents();
}
public void initComponents()
{
try
{
string fname = "C:\\Users\\Gebruiker\\Desktop\\PDF en DOC\\test.pdf";
streamToPrint = new StreamReader(fname, Encoding.UTF8);
try
{
PrintDocument pd = new PrintDocument();
pd = new PrintDocument();
pd.DocumentName = fname;
//Get responsive width and height.
System.Drawing.Rectangle workingRectangle = Screen.PrimaryScreen.WorkingArea;
int height = workingRectangle.Height / 100 * 85;
int width = workingRectangle.Width / 100 * 75;
//Settings printPreviewControl
printPreviewControl1.ClientSize = new System.Drawing.Size(width, height);
printPreviewControl1.Location = new System.Drawing.Point(0, 0);
printPreviewControl1.Document = pd;
}
finally
{
streamToPrint.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
*It says its generating the preview, but stays empty, watch image below:
If you guys have any other solution, I'm open to try.
Thanks
I am trying to preview an image in picture box from Thumb Impression device. I am doing this successfully on button click which shows an image of my thumb on button click. But my requirement is, when i keep my thumb it should immediately shows my thumb without button click. Following is the code which i am using in button click. Please anyone guide.
private void GetMinDataBtn_Click(object sender, EventArgs e)
{
SGFingerPrintManager manager = new SGFingerPrintManager();
int deviceInfo = manager.Init(SGFPMDeviceName.DEV_AUTO);
deviceInfo = manager.OpenDevice(0);
try
{
this.m_TestMin.Initialize();
SGFPMDeviceInfoParam pInfo = new SGFPMDeviceInfoParam();
deviceInfo = manager.GetDeviceInfo(pInfo);
byte[] buffer = new byte[pInfo.ImageWidth * pInfo.ImageHeight]; //Here sometime it fails to load image through device. And sometimes it continously works without an issue.
deviceInfo = manager.GetImageEx(buffer, 0x1388, (int)this.FDxPicBox.Handle, 50);
if (manager.CreateTemplate(buffer, this.m_TestMin) == 0)
{
this.FdxToFIRBtn.Enabled = true;
this.VerifyBtn.Enabled = true;
this.StatusBar.Text = "Get Minutiae Data Success";
deviceInfo = manager.CloseDevice();
}
}
catch (Exception ex)
{
deviceInfo = manager.CloseDevice();
MessageBox.Show(ex.ToString());
this.StatusBar.Text = "Thumb data failed to get";
}
}
I have another WPF Window i've created.. say window2.xaml. I have a button.. and on click i want it to load that window.. i've tried Googling but nothing seems to be working. It just loads a blank page. I know this is really simple, but I really can't find how to do it through my searches.
This is what i have tried:
GameClock temp = new GameClock();
temp.ShowDialog(); //just shows blank window
temp.Show(); //just shows a blank window too
EDIT: I figured out the problem. I took out the initialize component because there an an error. I thought it was something only the main window needed. When I put it back, it works. Thanks, everyone.
try this... u can use like a generic methode
private void button_ItemClick(object sender, ItemClickEventArgs e)
{
try
{
OpenWin("window2", new Uri(#"window2.xaml", UriKind.Relative), "Window2Label");
}
catch (Exception ex)
{
Message.Show(ex);
}
}
public static DocumentPanel OpenWin(string namePainelItem, Uri xamlPath, string caption = "", RoutedEventHandler unloadEvent = null, bool closeOpenWin = false)
{
try
{
if (closeOpenWin)
{
CloseWin(namePainelItem, false);
}
DocumentPanel panel1 = GetWin(namePainelItem);
if (panel1 == null)
{
panel1 = new DocumentPanel();
panel1.Caption = caption;
panel1.Name = namePainelItem;
panel1.Content = xamlPath;
if (unloadEvent != null)
{
panel1.Unloaded += unloadEvent;
}
hdl.dockLayoutManager.DockController.Insert(hdl.documentGroup1, panel1, 1);
hdl.dockLayoutManager.DockController.ActiveItem = panel1;
}
else
{
if (panel1.Visibility != Visibility.Visible)
panel1.Visibility = Visibility.Visible;
if(panel1.IsClosed)
panel1.Closed = false;
hdl.dockLayoutManager.DockController.ActiveItem = panel1;
}
return panel1;
}
catch (Exception ex)
{
Message.Show(ex);
}
return new DocumentPanel();
}
public static void CloseWin(string namePainelItem)
{
try
{
BaseLayoutItem item = hdl.dockLayoutManager.GetItem(namePainelItem);
if (item != null)
{
hdl.documentGroup1.Items.Remove(item);
hdl.dockLayoutManager.DockController.RemovePanel((DocumentPanel)item);
item = null;
}
}
catch (Exception ex)
{
Message.Show(ex);
}
}
You may need to read the XAML file before creating the instance of GameClock. Something like this:
GameClock clock;
FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
clock = (GameClock)XamlReader.Load(fs);
JAB
note I am new in Wpf >
I have project that decode qr code by using opencv library throw web cam >
and it running successfully
now I wanna to using this project in new Wpf project >
after adding new wpf project and make reference to WinForms application >
and this my simple code to open WinForm >
public void runnow(){
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new CameraCapture.cameraCapture()); }
by ruining give me this exception >
The type initializer for 'Emgu.CV.CvInvoke' threw an exception.>
what can I do for solve this
C# code
public partial class CameraCapture : Form
{
Capture capture;
bool Capturing;
Bitmap bimap;
private Reader reader;
private Hashtable hint;
libAES libEncryption = new libAES();
string Mykey = "";
public static String dataDecrypted="";
public CameraCapture()
{
InitializeComponent();
}
private void Mains(object sender, EventArgs arg) // Start function main to encode Qr code
{
Image<Bgr, Byte> image = capture.QueryFrame();
if (image != null)
{
bimap = image.ToBitmap();
pictureBox1.Image = bimap;
reader = new QRCodeReader();
hint = new Hashtable(); // Add some elements to the hash table. There are no duplicate keys, but some of the values are duplicates.
hint.Add(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);
RGBLuminanceSource source = new RGBLuminanceSource(bimap, bimap.Width, bimap.Height); //This class is used to help decode images from files which arrive as RGB data from* Android bitmaps. It does not support cropping or rotation.
BinaryBitmap img = new BinaryBitmap(new GlobalHistogramBinarizer(source));
Result result = null;
try
{
result = reader.decode(img, hint);
dataDecrypted = libEncryption.Decrypt(result.Text, Mykey);
}
catch
{
dataDecrypted = "";
}
if (result == null)
{
label1.Text = " no decode";
}
else
{
label4.Text = result.Text;
label1.Text = dataDecrypted;
capture.Dispose();
}
}
} // end function Main
private void btnStart_Click(object sender, EventArgs e)
{
if (capture == null)
{
try
{
capture = new Capture(); // **the exption thown here**
}
catch (NullReferenceException exception)
{
MessageBox.Show(exception.Message);
}
}
if (capture != null)
{
if (Capturing)
{
btnStart.Text = "Start Capture";
Application.Idle -= Mains;
}
else
{
btnStart.Text = "Stop Capture";
Application.Idle += Mains;
}
Capturing = !Capturing;
}
}
private void Release()
{
if (capture != null)
capture.Dispose();
}}
If you want to host WinForm in WPF, you need to use host control System.Windows.Forms.Integration.WindowsFormsHost
WPF provides many controls with a rich feature set. However, you may
sometimes want to use Windows Forms controls on your WPF pages. For
example, you may have a substantial investment in existing Windows
Forms controls, or you may have a Windows Forms control that provides
unique functionality.
Example code
private void Window_Loaded(object sender, RoutedEventArgs e)
{
// Create the interop host control.
System.Windows.Forms.Integration.WindowsFormsHost host =
new System.Windows.Forms.Integration.WindowsFormsHost();
// Create the MaskedTextBox control.
MaskedTextBox mtbDate = new MaskedTextBox("00/00/0000");
// Assign the MaskedTextBox control as the host control's child.
host.Child = mtbDate;
// Add the interop host control to the Grid
// control's collection of child controls.
this.grid1.Children.Add(host);
}
Check =>
http://msdn.microsoft.com/en-us/library/ms751761.aspx