TextBox on Desktop Icons
-
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
-
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
-
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)
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
-
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
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)
-
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)
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
-
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)
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
-
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
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