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. .NET (Core and Framework)
  4. TextBox on Desktop Icons

TextBox on Desktop Icons

Scheduled Pinned Locked Moved .NET (Core and Framework)
helptutorial
7 Posts 3 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.
  • B Offline
    B Offline
    BennyMac
    wrote on last edited by
    #1

    Dear experts, Does anyone know how to get access to the text box control that is displayed underneath icons on the Windows desktop. I want to re-use this text box in my own application as it has the "growth" behaviour that I urgently need. I need a text box that will grow in height as more text is added to it. PLEASE HELP ME! Thanks in advance for your assistance. Benjamin

    P O 2 Replies Last reply
    0
    • B BennyMac

      Dear experts, Does anyone know how to get access to the text box control that is displayed underneath icons on the Windows desktop. I want to re-use this text box in my own application as it has the "growth" behaviour that I urgently need. I need a text box that will grow in height as more text is added to it. PLEASE HELP ME! Thanks in advance for your assistance. Benjamin

      P Offline
      P Offline
      Poolbeer
      wrote on last edited by
      #2

      Hi, Why don't you use the standard textbox and at every keypress check the size of the text using the MeasureText method and size the textbox appropriatly. It works for me... Greets, Poolbeer


      Speak Out! Use the Source, Luke! (Dr. GUI .NET #5)

      B 1 Reply Last reply
      0
      • P Poolbeer

        Hi, Why don't you use the standard textbox and at every keypress check the size of the text using the MeasureText method and size the textbox appropriatly. It works for me... Greets, Poolbeer


        Speak Out! Use the Source, Luke! (Dr. GUI .NET #5)

        B Offline
        B Offline
        BennyMac
        wrote on last edited by
        #3

        Hi Poolbeer (nice name :-), I've actually tried this approach. Maybe if I could go over my thinking: (1) Handle the key press event (2) Get the key value and check for special keys like delete, backspace, enter and take the appropriate action based on this (i.e. either add the normal char, delete a char etc..) (3) Modify the Text value accordingly (4) Indicate the event has been handled. (5) Get the value of Text and use Graphics.MeasureString to compare to the width of the TextBox area (available through TextBox.Size). (6) If the width of the string > width of the client area, then increment the height of the TextBox by the the FontHeight. (7) Reposition the cursor within the textbox. (8) Invalidate the control to repaint itself. Is this the kind of approach? (i'm no expert). How do settings like WordWrap and the likes work into your TextBox solution? Finally, how to you handle the ability to get and set Text into your box especially if the Text has been modified to create the desired output. Sorry for the abudance of questions but I've been working on this for a while and you are the only help I've had! :) Benjamin

        P 1 Reply Last reply
        0
        • B BennyMac

          Hi Poolbeer (nice name :-), I've actually tried this approach. Maybe if I could go over my thinking: (1) Handle the key press event (2) Get the key value and check for special keys like delete, backspace, enter and take the appropriate action based on this (i.e. either add the normal char, delete a char etc..) (3) Modify the Text value accordingly (4) Indicate the event has been handled. (5) Get the value of Text and use Graphics.MeasureString to compare to the width of the TextBox area (available through TextBox.Size). (6) If the width of the string > width of the client area, then increment the height of the TextBox by the the FontHeight. (7) Reposition the cursor within the textbox. (8) Invalidate the control to repaint itself. Is this the kind of approach? (i'm no expert). How do settings like WordWrap and the likes work into your TextBox solution? Finally, how to you handle the ability to get and set Text into your box especially if the Text has been modified to create the desired output. Sorry for the abudance of questions but I've been working on this for a while and you are the only help I've had! :) Benjamin

          P Offline
          P Offline
          Poolbeer
          wrote on last edited by
          #4

          Hi, If you use the StringFormat Class and pass that along with the other stuff into MeasureString you'll get the size of the text back. Then if you do the DrawString using the same StringFormat properties the text will be drawn exactly like you want it. (ie wrapping) Using the wordwrap property of the textbox you can get the same look as the Graphics.DrawString method using the Formatting. Just play a little with those classes and you'll see it'll work. the rectangle you pass into the MeasureString method should be the size of the textbox minus the border width (usually 2 px). Good Luck. Poolbeer


          Speak Out! Use the Source, Luke! (Dr. GUI .NET #5)

          B 2 Replies Last reply
          0
          • P Poolbeer

            Hi, If you use the StringFormat Class and pass that along with the other stuff into MeasureString you'll get the size of the text back. Then if you do the DrawString using the same StringFormat properties the text will be drawn exactly like you want it. (ie wrapping) Using the wordwrap property of the textbox you can get the same look as the Graphics.DrawString method using the Formatting. Just play a little with those classes and you'll see it'll work. the rectangle you pass into the MeasureString method should be the size of the textbox minus the border width (usually 2 px). Good Luck. Poolbeer


            Speak Out! Use the Source, Luke! (Dr. GUI .NET #5)

            B Offline
            B Offline
            BennyMac
            wrote on last edited by
            #5

            Could you elaborate a little more on the rectangle that you pass into the MeasureString method? I am trying to determine the required dimensions (ie. size) so what dimensions to I pass into the method? Appreciate your ongoing assistance. Cheers, Benjamin

            1 Reply Last reply
            0
            • P Poolbeer

              Hi, If you use the StringFormat Class and pass that along with the other stuff into MeasureString you'll get the size of the text back. Then if you do the DrawString using the same StringFormat properties the text will be drawn exactly like you want it. (ie wrapping) Using the wordwrap property of the textbox you can get the same look as the Graphics.DrawString method using the Formatting. Just play a little with those classes and you'll see it'll work. the rectangle you pass into the MeasureString method should be the size of the textbox minus the border width (usually 2 px). Good Luck. Poolbeer


              Speak Out! Use the Source, Luke! (Dr. GUI .NET #5)

              B Offline
              B Offline
              BennyMac
              wrote on last edited by
              #6

              Actually I think I've worked out what you meant about the layout rectangle. Cool. However, my main problem is actually determining the layout rectangle which is equivalent to the behaviour of the TextBox. You mentioned taking into account the textbox with minus the border etc. however I cannot seem to get a layout rectangle that ensures the behaviour of the TextBox is replicated exactly. How did you solve this problem? Is your solution resolution independent etc.. Cheers, Benjamin

              1 Reply Last reply
              0
              • B BennyMac

                Dear experts, Does anyone know how to get access to the text box control that is displayed underneath icons on the Windows desktop. I want to re-use this text box in my own application as it has the "growth" behaviour that I urgently need. I need a text box that will grow in height as more text is added to it. PLEASE HELP ME! Thanks in advance for your assistance. Benjamin

                O Offline
                O Offline
                Oleksandr Kucherenko
                wrote on last edited by
                #7

                txtDescription - is a TextBox control private const int DEF_HEIGHT = 40; using( Bitmap bmp = new Bitmap( 1, 1 ) ) { using( Graphics g = Graphics.FromImage( bmp ) ) { int iHeight = 0; // make a string a little bigger by adding "\r\nW" - this give us one line // of free space SizeF size = g.MeasureString( string.Join( "\r\n", txtDescription.Lines ) + "\r\nW", txtDescription.Font, txtDescription.Width ); iHeight += (int)( size.Height + 0.5 ); // max size if( iHeight > 200 ) { txtDescription.ScrollBars = ScrollBars.Vertical; iHeight = 200; } else { txtDescription.ScrollBars = ScrollBars.None; } // min size if( iHeight < DEF_HEIGHT ) iHeight = DEF_HEIGHT; this.Height = iHeight; } } } Good Luck Alex Kucherenko

                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