Exemple #1
0
        } // SetHorizontalAlignment

        //
        // Calculate font baseline for baseline alignment.
        //
        private int GetFontBaseline(string strFont, int cptHeight)
        {
            int cyReturn;

            // Fetch a Win32 DC.
            IntPtr hdc = GdiGraphics.GetDC(m_hwndForm);

            // Create a Win32 font.
            IntPtr hfont = GdiFont.Create(hdc, strFont, cptHeight, 0);

            // Select font into DC.
            IntPtr hfontOld = GdiGraphics.SelectObject(hdc, hfont);

            // Allocate font metric structure.
            GdiFont.TEXTMETRIC tm =
                new GdiFont.TEXTMETRIC();

            // Fetch font metrics.
            GdiFont.GetTextMetrics(hdc, ref tm);

            // Fetch return value.
            cyReturn = tm.tmAscent;

            // Disconnect font from DC -- *Critical* because....
            GdiGraphics.SelectObject(hdc, hfontOld);

            // ... clean up of Win32 font object requires font to
            // be disconnected from any and all DCs.
            GdiGraphics.DeleteObject(hfont);

            // Disconnect from Win32 DC.
            GdiGraphics.ReleaseDC(m_hwndForm, hdc);

            return(cyReturn);
        } // GetFontBaseline
Exemple #2
0
        cmdFanBlade_Click(object sender, EventArgs e)
        {
            int cIncrement = degRotate;

            if (cIncrement == 0)
            {
                cIncrement = 45;
            }

            IntPtr hdc = GdiGraphics.GetDC(m_hwndForm);

            for (int i = 0; i < 360; i += cIncrement)
            {
                IntPtr hfont    = GdiFont.Create(hdc, "Tahoma", 12, i);
                IntPtr hfontOld = GdiGraphics.SelectObject(hdc, hfont);

                GdiGraphics.ExtTextOut(hdc, m_xText, m_yText, 0,
                                       IntPtr.Zero, "Rotated Text", 12, IntPtr.Zero);

                GdiGraphics.SelectObject(hdc, hfontOld);
                GdiGraphics.DeleteObject(hfont);
            }

            GdiGraphics.ReleaseDC(m_hwndForm, hdc);
        }
Exemple #3
0
        FormMain_Paint(object sender, PaintEventArgs e)
        {
            // Fetch a Win32 DC.
            IntPtr hdc = GdiGraphics.GetDC(m_hwndForm);

            // Create a Win32 font.
            IntPtr hfont = GdiFont.Create(hdc, "Tahoma", 12, m_degRotate);

            // Select font into DC.
            IntPtr hfontOld = GdiGraphics.SelectObject(hdc, hfont);

            // Draw using Win32 text drawing function.
            GdiGraphics.ExtTextOut(hdc, m_xText, m_yText, 0,
                                   IntPtr.Zero, "Rotated Text", 12, IntPtr.Zero);

            // Disconnect font from DC -- *Critical* because....
            GdiGraphics.SelectObject(hdc, hfontOld);

            // ... clean up of Win32 font object requires font to
            // be disconnected from any and all DCs.
            GdiGraphics.DeleteObject(hfont);

            // Disconnect from Win32 DC.
            GdiGraphics.ReleaseDC(m_hwndForm, hdc);
        }
Exemple #4
0
        mitemFilePrint_Click(object sender, EventArgs e)
        {
            // Display dialog to select printer & port.
            PAGESETUPDLGSTRUCT psd;

            psd = new PAGESETUPDLGSTRUCT();
            PrintSetupDlg.InitDlgStruct(ref psd, hwndForm);
            int iErr = PrintSetupDlg.ShowDialog(ref psd);

            if (iErr == 0)
            {
                // Either error...
                string strErr = PrintSetupDlg.GetErrorString();
                if (strErr != "Ok")
                {
                    MessageBox.Show(strErr, "PrintGdi");
                }
                // ...Or user clicked <Cancel>
                return;
            }

            IntPtr hdcPrinter = IntPtr.Zero;
            IntPtr hfont      = IntPtr.Zero;
            IntPtr hfontOld   = IntPtr.Zero;

            try
            {
                // Connect to printer by creating a DC.
                hdcPrinter = Printing.CreatePrinterDC(ref psd);
                if (hdcPrinter != IntPtr.Zero)
                {
                    // Select font.
                    hfont = GdiFont.Create(tboxInput.Font.Name,
                                           (int)tboxInput.Font.Size, 0, hdcPrinter);
                    hfontOld = GdiGraphics.SelectObject(hdcPrinter, hfont);

                    // Print
                    PrintJob_Gdi.PrintText(tboxInput, hdcPrinter);
                }
                else
                {
                    throw new System.Exception();
                }
            }
            catch
            {
                MessageBox.Show("Error connecting to printer.", "PrintGdi");
            }
            finally
            {
                // Cleanup
                GdiGraphics.SelectObject(hdcPrinter, hfontOld);
                GdiGraphics.DeleteObject(hfont);
                Printing.DeleteDC(hdcPrinter);

                // Clean up resources associated with print dialog.
                PrintSetupDlg.Close(ref psd);
            }
        }
Exemple #5
0
        mitemFilePrint_Click(object sender, EventArgs e)
        {
            IntPtr hdcPrinter = IntPtr.Zero;
            IntPtr hfont      = IntPtr.Zero;
            IntPtr hfontOld   = IntPtr.Zero;

            try
            {
                // Connect to printer by creating a DC.
                hdcPrinter = mPrint.mPrintRenderWrapper.CreatePrinterContext();
                if (hdcPrinter != IntPtr.Zero)
                {
                    // Select font.
                    hfont = GdiFont.Create(tboxInput.Font.Name,
                                           (int)tboxInput.Font.Size, 0, hdcPrinter);
                    hfontOld = GdiGraphics.SelectObject(hdcPrinter, hfont);

                    // Print
                    PrintJob_Gdi.PrintText(tboxInput, hdcPrinter);
                }
                else
                {
                    throw new System.Exception();
                }
            }
            catch
            {
                MessageBox.Show("Error connecting to printer.",
                                "PrintHPMobile");
            }
            finally
            {
                // Cleanup
                GdiGraphics.SelectObject(hdcPrinter, hfontOld);
                GdiGraphics.DeleteObject(hfont);
                mPrint.mPrintRenderWrapper.DeletePrinterContext(hdcPrinter);
            }
        }