RichTextBox EM_FORMATRANGE RotateTransform cloudly output RRS feed

  • Frage

  • Hello,

    i have the problem that the output of my Program is in one case total cloudly.

    So i use a RichTextBox and the EM_FORMATRANGE Message to render the output to Metafile.

    IntPtr hdc = _g.GetHdc();
    Metafile metafile = new Metafile(hdc, new RectangleF(0, 0, iWidth, iHeight), MetafileFrameUnit.Pixel); 
    Graphics g1 = Graphics.FromImage(metafile); 
    IntPtr hDCEMF = g1.GetHdc();
    fRange.chrg.cpMin = 0;
    fRange.chrg.cpMax = -1;
    fRange.hdc = hDCEMF;
    fRange.hdcTarget = hDCEMF;
    fRange.rcPage = LayoutAreaPage;
    fRange.rc = LayoutArea;
    IntPtr wparam = IntPtr.Zero;
    wparam = new IntPtr(1);
    IntPtr lparam = IntPtr.Zero;
    lparam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fRange));
    Marshal.StructureToPtr(fRange, lparam, false);
    SendMessage(m_RichTextCtrl.Handle, EM_FORMATRANGE, wparam, lparam);
    SendMessage(m_RichTextCtrl.Handle, EM_FORMATRANGE, (IntPtr)0, (IntPtr)0);
    _g.TranslateTransform(iLeft, iTop);
    _g.DrawImage(metafile, 0, 0, iWidth, iHeight);


    Scenario 1:

    When i use a default RichtextBox, everthing is OK.


    Scenario 2:

    When i use a override RichTextBox with transparent background.

     class RichTextCtrl : RichTextBox
            public const int WS_EX_TRANSPARENT = 0x20;
            public RichTextCtrl()
                this.SetStyle(ControlStyles.Opaque, true);            
                this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            protected override CreateParams CreateParams
                    CreateParams createParams = base.CreateParams;
                    // Transparent background
                    createParams.ExStyle |= WS_EX_TRANSPARENT;
                    Visible = false;
                    return createParams;

    Everthing is Ok, except rotate 180 degree.

    I meen only exact 180 degree. 179.95 or 180.05 are working fine.


    For me it seems like a problem in the .net framework.

    Thanks for every help in advanced,



    Mittwoch, 18. Januar 2012 08:59