Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Using EM_GETRECT and EM_SETRECT for RTF boxes in C#?

Using EM_GETRECT and EM_SETRECT for RTF boxes in C#?

Scheduled Pinned Locked Moved C#
csharpc++winformstutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    handa29
    wrote on last edited by
    #1

    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

    H M 2 Replies Last reply
    0
    • H handa29

      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

      H Offline
      H Offline
      handa29
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • H handa29

        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

        M Offline
        M Offline
        mav northwind
        wrote on last edited by
        #3

        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() and Marshal.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...

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups