"PrintVisual wpf scale" Code Answer's

You're definitely familiar with the best coding language C# that developers use to develop their projects and they get all their queries like "PrintVisual wpf scale" answered properly. Developers are finding an appropriate answer about PrintVisual wpf scale related to the C# coding language. By visiting this online portal developers get answers concerning C# codes question like PrintVisual wpf scale. Enter your desired code related query in the search bar and get every piece of information about C# code related question on PrintVisual wpf scale. 

PrintVisual wpf scale

By Arin FarajArin Faraj on Jan 25, 2021
private void Print(Visual v)
    {

        System.Windows.FrameworkElement e = v as System.Windows.FrameworkElement ;
        if (e == null)
            return;

        PrintDialog pd = new PrintDialog();
        if (pd.ShowDialog() == true)
        {
            //store original scale
            Transform originalScale = e.LayoutTransform;
            //get selected printer capabilities
            System.Printing.PrintCapabilities capabilities = pd.PrintQueue.GetPrintCapabilities(pd.PrintTicket);

            //get scale of the print wrt to screen of WPF visual
            double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / e.ActualWidth, capabilities.PageImageableArea.ExtentHeight /
                           e.ActualHeight);

            //Transform the Visual to scale
            e.LayoutTransform = new ScaleTransform(scale, scale);

            //get the size of the printer page
            System.Windows.Size sz = new System.Windows.Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);

            //update the layout of the visual to the printer page size.
            e.Measure(sz);
            e.Arrange(new System.Windows.Rect(new System.Windows.Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));

            //now print the visual to printer to fit on the one page.
            pd.PrintVisual(v, "My Print");

            //apply the original transform.
            e.LayoutTransform = originalScale;
        }
    }

Source: stackoverflow.com

Add Comment

0

All those coders who are working on the C# based application and are stuck on PrintVisual wpf scale can get a collection of related answers to their query. Programmers need to enter their query on PrintVisual wpf scale related to C# code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about PrintVisual wpf scale for the programmers working on C# code while coding their module. Coders are also allowed to rectify already present answers of PrintVisual wpf scale while working on the C# language code. Developers can add up suggestions if they deem fit any other answer relating to "PrintVisual wpf scale". Visit this developer's friendly online web community, CodeProZone, and get your queries like PrintVisual wpf scale resolved professionally and stay updated to the latest C# updates. 

C# answers related to "PrintVisual wpf scale"

View All C# queries

C# queries related to "PrintVisual wpf scale"

PrintVisual wpf scale unity set object scale unity ar scale c# form set auto scale scale between tow ranges c# instantiate scale object how to disable scale anti-aliasing in monogame c# wpf image source from resource programmatically wpf save file dialog visibility bound to radio button wpf aforge wpf webcam telerik wpf gridviewcombobox itemsource property on item c# wpf initializecomponent does not exist textbox gotfocus wpf page parent wpf allelrt box wpf CONTROLS DONT EXIST IN THE CURRENT CONTEXT AFTER REBUILD WPF C# wpf binding to static property in code behind c# wpf passwordbox binding Read csv file into wpf C# wpf itemscontrol in itemscontrol how to change text in richtextbox wpf wpf busy indicator c# wpf datagrid extra column wpf button to return to last window wpf get name of clicked element how to detected WindowCloseEvent in other window wpf telerik raddatepicker default date today wpf wpf binding object get value wpf label foreground in c# wpf bind image source to string c# wpf control to windw size wpf settings core wpf find child control by name wpf use enum description wpf datatrigger enum binding wpf label content nullpointerexception wpf relativesource wpf how to focus on element how to implement FluentValidation in wpf wpf clock conrt create a dialog in wpf wpf get dependency property in code rad grid column wpf telerik enum start wpf application when windows start wpf icollectionview filter set margin programmatically wpf c# c# async in wpf wpf scoll to on new item datagrtid wpf textbox insert text at caret position wpf set button text color

Browse Other Code Languages

CodeProZone