473,406 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

when text is longer than its textbox

Hi,
Is there an easy way to say, on textboxHover, if the text inside the box
isn't completely visible, have a popup tool come up showing the complete
contents of the box? I'm guessing I need to know if there's a way to
determine the number of pixels that some generic text takes up. Also, is
there a way to extract the pixel length from textbox.Size (to save some time
looking values up)?
Thanks so much!!!
Mel
Dec 13 '05 #1
2 4854
You could do something like the following if you don't care about overwriting
existing tooltips:

private ToolTip tt = new ToolTip();
private Graphics g;

public MyConstructor() {
// If you use MouseHover instead of MouseEnter, it will take 2 hovers
// in order to show initially. TextChanged lets it update as you type.
// Unfortunately, ToolTip only checks to see if it should display when you
// hover over the control, so if the text is short enough to not display
initially,
// hovering and then increasing the text length won't cause the ToolTip to
// display until you move the mouse again.
this.textBox1.TextChanged += new EventHandler(TextBox_ToolTipUpdater);
this.textBox1.MouseEnter += new EventHandler(TextBox_ToolTipUpdater);
tt.InitialDelay = 0;
tt.AutoPopDelay = int.MaxValue;
g = Graphics.FromHwnd(this.Handle);
}

private void TextBox_ToolTipUpdater(object sender, EventArgs e) {
TextBox t = sender as TextBox;
if (t != null && t.Text != tt.GetToolTip(t)) {
SizeF textSize;
textSize = g.measureString(t.Text, t.Font);
if (textSize.Width > (float)t.Size.Width) {
tt.SetToolTip(t, t.Text);
} else {
tt.SetToolTip(t, string.Empty);
}
}
}

"melanieab" wrote:
Hi,
Is there an easy way to say, on textboxHover, if the text inside the box
isn't completely visible, have a popup tool come up showing the complete
contents of the box? I'm guessing I need to know if there's a way to
determine the number of pixels that some generic text takes up. Also, is
there a way to extract the pixel length from textbox.Size (to save some time
looking values up)?
Thanks so much!!!
Mel

Dec 13 '05 #2
On Tue, 13 Dec 2005 13:42:43 -0800, melanieab
<me*******@discussions.microsoft.com> wrote:
Hi,
Is there an easy way to say, on textboxHover, if the text inside the box
isn't completely visible, have a popup tool come up showing the complete
contents of the box? I'm guessing I need to know if there's a way to
determine the number of pixels that some generic text takes up. Also, is
there a way to extract the pixel length from textbox.Size (to save some time
looking values up)?
Thanks so much!!!
Mel

You don't say if you have a multiline or a single line text box. This
seems to work for a single line textBox:

private void myTextBox_MouseHover(object sender, EventArgs e) {
Point pStart = myTextBox.GetPositionFromCharIndex(0);
Point pEnd =
myTextBox.GetPositionFromCharIndex(myTextBox.Text. Length - 1);

if (pStart.X > myTextBox.Width || pEnd.X > myTextBox.Width) {
MessageBox.Show(myTextBox.Text, this.Text);
} // end if
}

When the start of the text is not showing, the return from
GetPositionFromCharIndex() for pStart.X seems to be 65394. The code
relies on the text box width being less than this value.

An alternative might be to use a ToolTip to display the text rather
than a MessageBox.
rossum

--

The ultimate truth is that there is no ultimate truth
Dec 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Luis Esteban Valencia | last post by:
Hello. I have a datagrid with one row. I have a button that adds a new row. I am trying to implement that when the user selects one product it must change the price on the quantity column. Anyway...
2
by: trebor | last post by:
If you select text in a form's textbox and then open a second form (for whatever reason), the selected text no longer looks selected; it's not hilited. When you close the second form and return to...
23
by: Paul Mars | last post by:
I need to limit multiline textbox to 3 lines of text and if there are less then 3 lines when leaving, add empty line holders. How can I do this?? Thanks, paul
10
by: Bob | last post by:
Okay, I've done this for years but now I'm going to question it just because this idea has been at the back of my head since I started using DotNet... My WinForms app queries a database every 60...
0
by: Mark Micallef | last post by:
Hi, I'm having a problem using a databound dropdownlist inside a reorderlist ajax control. Here's a snippet of the code I'm using: <InsertItemTemplate> <div class="insertArea">...
1
by: Mark Micallef | last post by:
Hi, this question relates to a control in the Ajax toolkit for asp.net 2. I'm having a problem using a databound dropdownlist inside a reorderlist ajax control. Here's a snippet of the code I'm...
16
by: mj.redfox.mj | last post by:
Can anyone help? I have a textbox which I'm programatically adding by using the following code: txtTest = New TextBox txtTest.ID = "txtLeft" + cntCount.ToString...
18
by: Academia | last post by:
I let the use modify the text of a combobox and then I replace the selected item with the new text (in Keyup event). But if he sets the Text property to an empty string ("") that sets the...
2
by: =?Utf-8?B?TE1X?= | last post by:
I am building a template which has an area for the user to type in whatever information is needed (a form, narrative, whatever). However, I have a limited amount of space on the 1st page of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.