Using EM_GETRECT and EM_SETRECT for RTF boxes in C#?
-
Hi, folks! I've made a sub-class of the System.Windows.Forms.RichTextBox called "MyRtfBox". Within my rtf box, I want to add a few properties which allow me to directly access some of the advanced properties of the rtf textbox, such as line count, getting the scrollbar thumb's position, etc. I'm glad to say that I've figured all of that out, EXCEPT for how to get and set the display rectangle using Windows Forms Messages! I've looked all over the web and can't find any articles anywhere in C# that show how to use these two Messages. The examples I've seen in C++ and VB don't seem to translate well to C#. Does anyone have a clue? When it's all set and done, I'd like to have a sub-classed RTF box with this public property... //Taken from the Windows constants list. private const int EM_GETRECT = 0x00b2; private const int EM_SETRECT = 0x00b3; public Rectangle DisplayRect { get { Rectangle rect = new Rectangle(); //Send a message to Windows somehow! return rect; } set { //Send a message to Windows using the given Rectangle parameter. } } Many thanks!! Anthony
-
Hi, folks! I've made a sub-class of the System.Windows.Forms.RichTextBox called "MyRtfBox". Within my rtf box, I want to add a few properties which allow me to directly access some of the advanced properties of the rtf textbox, such as line count, getting the scrollbar thumb's position, etc. I'm glad to say that I've figured all of that out, EXCEPT for how to get and set the display rectangle using Windows Forms Messages! I've looked all over the web and can't find any articles anywhere in C# that show how to use these two Messages. The examples I've seen in C++ and VB don't seem to translate well to C#. Does anyone have a clue? When it's all set and done, I'd like to have a sub-classed RTF box with this public property... //Taken from the Windows constants list. private const int EM_GETRECT = 0x00b2; private const int EM_SETRECT = 0x00b3; public Rectangle DisplayRect { get { Rectangle rect = new Rectangle(); //Send a message to Windows somehow! return rect; } set { //Send a message to Windows using the given Rectangle parameter. } } Many thanks!! Anthony
Okay, don't get hung up on the fact that I called the public property, "DisplayRect". I know there's already a public property on RTF boxes called DisplayRectangle. The point of this exercise is to understand how to use the 2 Windows constants in sending messages to Windows asking for this info, and then setting a new value. Since there doesn't seem to be any other C#-specific examples out there in the world, this would be *really* useful! Thanks! Anthony
-
Hi, folks! I've made a sub-class of the System.Windows.Forms.RichTextBox called "MyRtfBox". Within my rtf box, I want to add a few properties which allow me to directly access some of the advanced properties of the rtf textbox, such as line count, getting the scrollbar thumb's position, etc. I'm glad to say that I've figured all of that out, EXCEPT for how to get and set the display rectangle using Windows Forms Messages! I've looked all over the web and can't find any articles anywhere in C# that show how to use these two Messages. The examples I've seen in C++ and VB don't seem to translate well to C#. Does anyone have a clue? When it's all set and done, I'd like to have a sub-classed RTF box with this public property... //Taken from the Windows constants list. private const int EM_GETRECT = 0x00b2; private const int EM_SETRECT = 0x00b3; public Rectangle DisplayRect { get { Rectangle rect = new Rectangle(); //Send a message to Windows somehow! return rect; } set { //Send a message to Windows using the given Rectangle parameter. } } Many thanks!! Anthony
Hi! I'd suppose you can use EM_GETRECT and EM_SETRECT just like any other windows message sent to your RTB. The declaration of SendMessage is something like this:
[DllImport("user32.dll")]
private static extern int SendMessage(IntPtr hWnd, int msg, IntPtr wPar, IntPtr lPar);Then you can use this function to send the messages to your RTB. The last parameter (lPar) is used for the rectangle. You can use the
Marshal.StructureToPtr()
andMarshal.PtrToStructure()
methods to transfer the rectangle data to your working structures. That should do the trick...Regards, mav -- Black holes are the places where god divided by 0...