|
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,
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
|
|
|
|
|
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
|
|
|
|
|
txtDescription - is a TextBox control
<br />
private const int DEF_HEIGHT = 40;<br />
<br />
<br />
<br />
using( Bitmap bmp = new Bitmap( 1, 1 ) )<br />
{<br />
using( Graphics g = Graphics.FromImage( bmp ) )<br />
{<br />
int iHeight = 0;<br />
<br />
SizeF size = g.MeasureString( <br />
string.Join( "\r\n", txtDescription.Lines ) + "\r\nW", <br />
txtDescription.Font, <br />
txtDescription.Width );<br />
<br />
iHeight += (int)( size.Height + 0.5 );<br />
<br />
if( iHeight > 200 )<br />
{<br />
txtDescription.ScrollBars = ScrollBars.Vertical;<br />
iHeight = 200;<br />
}<br />
else<br />
{<br />
txtDescription.ScrollBars = ScrollBars.None;<br />
}<br />
<br />
if( iHeight < DEF_HEIGHT ) iHeight = DEF_HEIGHT;<br />
<br />
this.Height = iHeight;<br />
}<br />
}<br />
}<br />
<br />
Good Luck
Alex Kucherenko
|
|
|
|
|
Hi,
I have readen that the compact framework does not support GDI+, ... then to load a JPG I need to use strange, fancy activeX controls from third parties ?
Thanks, greetings
Braulio
|
|
|
|
|
Hi,
I need to register a pluggable protocol for Internet Explorer like
res://C:/windows/googletoolbar.dll#options
My problem or requirement is as follows:
(*)Can I ask my user to install a DLL and call its method like the one above? (Will POST or GET to that would work?)
(*)If I want to register a new protocol like res:// how is that possible? If the solution would be using .NET framework Classes, it would be great.
Deepak Kumar Vasudevan
http://deepak.portland.co.uk/
|
|
|
|
|
A protocol handler can be temporarily made available. Watch out for the IInternetSession() and CoInternetGetSession API methods in MSDN.
Other than temporary registration, the only way to have a protocol handler running is to have it fully registered and, at this point, there is no way to do it through the web. Otherwise, this would be a security hole.
|
|
|
|
|
Does anybody know how to make a localized installation kit?
I apreciate any help.
Sergiu.
|
|
|
|
|
Hi,
I have a problem with DateTimePicker control. The problem is that I want to capture the Up and Down button of DateTimePicker control when its ShowUpDown property is true.
Can anyone know about the events or logic how to trace it.
Plz help me
Thanks
Sohail
|
|
|
|
|
Hi Sohail,
Are you talking about DatePicker in ASP.NET or in Windows Forms? I have tried out ASP.NET Calendar Control but since that involves server roundtrip, I went to a control from http://www.softcomplex.com/ , which provides complete clientside datetime picker along with validation for time also.
Deepak Kumar Vasudevan
http://deepak.portland.co.uk/
|
|
|
|
|
I'm trying to create an interface with 4 viewports(seen in most 3d modelling apps and level editors).
I'm trying to split the windows with a number of Splitter's but I just can't get it right.. It seems it is impossible to divide a window into 4 viewports using splitters? Do I need to create my own control or does someone have a class ready for this purpose?
|
|
|
|
|
Hint: Use panels
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Yeah.. I figured that out after my post.
But the problem still remains.. you can't get a pure 4 viewport interface because in order to get 4 panels
---------------
| | |
|_____|_______|
| | |
| | |
|--------------
the horizontal splitter needs to be divided.. one left of the vertical splitter and one to the right.
so i can't get a cross-arrow in the middle... bugs me out
|
|
|
|
|
Sounds like a nice time to write an article once you have figured it out
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Yeah... I'll think about it!
|
|
|
|
|
Hi,
I am working on a project involving Grid Services (http://www.globus.org).
This involves a slight modification to the WSDL describing a web service. I wish to insert XML elements in any portType element describing the service.
In ASP.NET, to obtain the WSDL description, you look at the URL
http://myservices.com/Service.asmx?WSDL
My question is, how is the WSDL produced (i.e. at what level does ASP.NET interpret the ?WSDL command?). How can I affect this and do what I want to do? What framework classes might be used?
Any ideas?
No work.
|
|
|
|
|
Is there a bug in setting the icon property of a Windows Form in .NET? I have an icon defined as an embedded resource. I have edited it, but I continute to get the original, not the edited icon in my form.
This occurs even in design view when I change the icon property to my icon, on the property page I see my edited icon but on the form I continue to see the icon in its original form. What gives?
|
|
|
|
|
I have seen this too. Best way is to remove the icon resource (not delete) then do a rebuild, then add the modified icon resource and rebuild again.
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
I'm trying to display an icon on a form as an embedded resource. I have it flagged as embedded, but when I change it, I continue to get the original icon, not the edited one. Do I need to "un-embed" it?
|
|
|
|
|
You shouldn't have to reembed an icon. I have written several apps that use embedded icons, and I've never had to reembed anything. What you could try is a full rebuild of the project, but I don't know if that will affect your icon or not.
|
|
|
|
|
Hello,
I got a program whith PrintPreviewControl, on Win-
2000/XP workstation all fine, but on Win-98 workstation
PrintPreviewControl periodically have the following error:
====================
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.NullReferenceException: Object reference not set
to an instance of an object.
at
System.Windows.Forms.PrintPreviewControl.CalculatePageInfo
()
at
System.Windows.Forms.Control.InvokeMarshaledCallbacks()
====================
This error also occurs in this MS Example:
http://msdn.microsoft.com/msdnmag/issues/03/02/PrintinginN
ET/default.aspx
Any ideas? I really need to resolve this problem.
Thanks.
|
|
|
|
|
I think I have come across a fairly common situation but I cant find any help with this.
I have a simple form with 2 controls. A text box (Employee's Name) and a combo box (Employee's Job Title). I have a DataTable that I have tied both the text box and combo box to. Changing positions using the CurrencyManager works fine and everything is good.
But now I want to populate the combo-box with a list of all available jobs. I want to be able to select a item from the list and have it update the appropriate row in my DataTable as would an edit within the text box.
I have the following code, but I get un-expected results.
<br />
DataTable jobs = new DataTable("Jobs");<br />
jobs.Columns.Add("Job", typeof(string));<br />
jobs.Rows.Add(new object[] {"Software Engineer"});<br />
jobs.Rows.Add(new object[] {"Project Manager"});<br />
jobs.Rows.Add(new object[] {"Tester"});<br />
jobs.Rows.Add(new object[] {"Documenter"});<br />
jobs.Rows.Add(new object[] {"Project Lead"});<br />
<br />
cboJob.DataSource = t;<br />
cboJob.DisplayMember = "Job";<br />
<br />
DataTable namesAndJobs = new DataTable("NamesAndJobs");<br />
namesAndJobs.Columns.Add("Name", typeof(string));<br />
namesAndJobs.Columns.Add("Job", typeof(string));<br />
<br />
namesAndJobs.Rows.Add(new object[] {"Bob", "Project Lead"});<br />
namesAndJobs.Rows.Add(new object[] {"Mark", "Documenter"});<br />
namesAndJobs.Rows.Add(new object[] {"Henry", "Project Manager"});<br />
<br />
txtName.DataBindings.Add("Text", namesAndJobs, "Name");<br />
cboJob.DataBindings.Add("Text", namesAndJobs, "Job");<br />
Can what I want to do, even be done?
|
|
|
|