powered by simpleCommunicator - 2.0.54     © 2025 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / WinForms, .Net Framework [игнор отключен] [закрыт для гостей] / rtf для чайников
4 сообщений из 4, страница 1 из 1
rtf для чайников
    #38727434
bobsoft
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Rtf оказалась проблемой в net .
Нарыл в инете несколько исходников , но в одних случаях table не работает в других этот rtf не имеет вывода на печать . К счастью моих знаний в copy/paste оказалось достаточно для совмещения нарытого . Вот этот rtf работает с table как надо и имеет вывод на печать .
Код: c#
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
using System;
//using System.Collections.Generic;
//using System.ComponentModel;
using System.Drawing;
using System.Drawing.Printing;
using System.Data;
//using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
//using System.Security.AccessControl;
using System.Security.Permissions;

namespace FullTableRich
{
    public partial class FullTableRichTextBox : RichTextBox
    {
        public FullTableRichTextBox()
        {
            InitializeComponent();
        }
        [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern IntPtr LoadLibrary(string libname);
        private static IntPtr RichEditModuleHandle;
        private const string RichEditDllV3 = "RichEd20.dll";
        private const string RichEditDllV41 = "Msftedit.dll";
        private const string RichEditClassV3A = "RichEdit20A";
        private const string RichEditClassV3W = "RichEdit20W";
        private const string RichEditClassV41W = "RICHEDIT50W";
        protected override CreateParams CreateParams
        {
            [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
            get
            {
                if (RichEditModuleHandle == IntPtr.Zero)
                {
                    RichEditModuleHandle = LoadLibrary(RichEditDllV41);
                    if (RichEditModuleHandle == IntPtr.Zero)
                    {
                        return base.CreateParams;
                    }
                }
                CreateParams theParams = base.CreateParams;
                theParams.ClassName = RichEditClassV41W;
                return theParams;
            }
        }
        private const int WM_USER = 0x0400;
        private const int EM_FORMATRANGE = WM_USER + 57;
        private const double anInch = 14.4;
        [StructLayout(LayoutKind.Sequential)]
        private struct RECT
        {
            public int Left;
            public int Top;
            public int Right;
            public int Bottom;
        }
        [StructLayout(LayoutKind.Sequential)]
        private struct CHARRANGE
        {
            public int cpMin;         //First character of range (0 for start of doc)
            public int cpMax;           //Last character of range (-1 for end of doc)
        }
        [StructLayout(LayoutKind.Sequential)]
        private struct FORMATRANGE
        {
            public IntPtr hdc;             //Actual DC to draw on
            public IntPtr hdcTarget;       //Target DC for determining text formatting
            public RECT rc;                //Region of the DC to draw to (in twips)
            public RECT rcPage;            //Region of the whole DC (page size) (in twips)
            public CHARRANGE chrg;         //Range of text to draw (see earlier declaration)
        }
        [DllImport("USER32.dll")]
        private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);

        // Render the contents of the RichTextBox for printing
        //	Return the last character printed + 1 (printing start from this point for next page)
        public int Print(int charFrom, int charTo, PrintPageEventArgs e)
        {
            //Calculate the area to render and print
            RECT rectToPrint;
            rectToPrint.Top = (int)(e.MarginBounds.Top * anInch);
            rectToPrint.Bottom = (int)(e.MarginBounds.Bottom * anInch);
            rectToPrint.Left = (int)(e.MarginBounds.Left * anInch);
            rectToPrint.Right = (int)(e.MarginBounds.Right * anInch);

            //Calculate the size of the page
            RECT rectPage;
            rectPage.Top = (int)(e.PageBounds.Top * anInch);
            rectPage.Bottom = (int)(e.PageBounds.Bottom * anInch);
            rectPage.Left = (int)(e.PageBounds.Left * anInch);
            rectPage.Right = (int)(e.PageBounds.Right * anInch);

            IntPtr hdc = e.Graphics.GetHdc();

            FORMATRANGE fmtRange;
            fmtRange.chrg.cpMax = charTo;				//Indicate character from to character to 
            fmtRange.chrg.cpMin = charFrom;
            fmtRange.hdc = hdc;                    //Use the same DC for measuring and rendering
            fmtRange.hdcTarget = hdc;              //Point at printer hDC
            fmtRange.rc = rectToPrint;             //Indicate the area on page to print
            fmtRange.rcPage = rectPage;            //Indicate size of page

            IntPtr res = IntPtr.Zero;

            IntPtr wparam = IntPtr.Zero;
            wparam = new IntPtr(1);

            //Get the pointer to the FORMATRANGE structure in memory
            IntPtr lparam = IntPtr.Zero;
            lparam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fmtRange));
            Marshal.StructureToPtr(fmtRange, lparam, false);

            //Send the rendered data for printing 
            res = SendMessage(Handle, EM_FORMATRANGE, wparam, lparam);

            //Free the block of memory allocated
            Marshal.FreeCoTaskMem(lparam);

            //Release the device context handle obtained by a previous call
            e.Graphics.ReleaseHdc(hdc);

            //Return last + 1 character printer
            return res.ToInt32();
        }

    }

}


Текст не мой и пинать меня не надо , лучше поправьте его если нужно , а я не c# и никогда им не буду . Просто мне пару раз помогли на форуме вот может это еще кому поможет .
...
Рейтинг: 0 / 0
rtf для чайников
    #38727437
bobsoft
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Забыл .
Печать как обычного rtf , но там где выводится страница нужно

self.ret = self.richTextBox1.print(self.ret,richTextBox1.TextLength,e)
if self.ret < self.richtextbox1.textlength
e.HasMorePages = true
else
e.HasMorePages = false
end
...
Рейтинг: 0 / 0
rtf для чайников
    #38967042
bobsoft
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Не работает как надо этот Msftedit.dll . Первое это прочерчивание бордюр в некоторых местах , второе это не правильный подсчет размера блока при выводе на печать ЕСЛИ в таблицах есть строки НЕ одинаковой высоты . Может есть решение ?
...
Рейтинг: 0 / 0
rtf для чайников
    #38967046
Фотография Cat2
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Модератор форума
bobsoft,

Мы поняли, что не работает, а что вы желаете сделать?
...
Рейтинг: 0 / 0
4 сообщений из 4, страница 1 из 1
Форумы / WinForms, .Net Framework [игнор отключен] [закрыт для гостей] / rtf для чайников
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]