473,765 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic Label height based on Content

Samishii23
246 New Member
So I have a custom tool tip in my program. Its a Panel control that has a few Label controls. I have set my Panel to AutoSize based on content.

I tried to use the AutoSize property on one of the Labels, as this one holds the largest content, but that just extends its width. I would like to have it just expand height wise. The content I have ranges from a small sentence to a full paragraph. I haven't been able to find anything in searches. So now I ask the experts.

Should I use something like counting how many words are in the Panel, and scale it based on that? (I've tried this in the past, without good success) or is there a better way?
Mar 30 '10 #1
9 6058
GaryTexmo
1,501 Recognized Expert Top Contributor
You should be able to measure the width/height of a string on a panel using the Graphics.Measur eString method. I'm not sure if that will handle word wrapping through... but worth a try! I'm guessing you are intending for your tool tip to eventually wrap the text after a certain point?

You can use the measure string method to find the total width and then divide that by the maximum width you want. I'm not sure if that takes into account he spacing between rows though.
Mar 30 '10 #2
tlhintoq
3,525 Recognized Expert Specialist
I'm a HUGE believer in building your own stuff.
I also believe that dismantling the code of those more experienced is a great way to learn.
And... I hate to re-invent the wheel.
Perhaps this project will help you in several ways.
http://www.codeproject.com/KB/dialog...ith_Image.aspx
Mar 30 '10 #3
Samishii23
246 New Member
@Gary... I think you misunderstand. The only way I can get the text to wrap via height is to set the Height property of the Label. It wraps just fine.

@tlhintoq... Thanks for the link, I will check it out. I also agree with you about building my own stuff. Just need to learn more, and I'll be off to do so.
Mar 30 '10 #4
GaryTexmo
1,501 Recognized Expert Top Contributor
Sorry, then I don't understand what the problem is :(
Mar 30 '10 #5
Samishii23
246 New Member
Sorry, then I don't understand what the problem is... you want a fixed width and want to set the height of the form so it fits all the text?
Thats pretty much exactly it.
Mar 30 '10 #6
GaryTexmo
1,501 Recognized Expert Top Contributor
ok, well that's what I was talking about :D Use MeasureString to get the width and height of the text. Divide the fixed width by the text width, multiply the height by that number, set your label to that number?
Mar 31 '10 #7
Samishii23
246 New Member
@Gary, it seems that I can only use MeasureString with a draw event. I'm not using the ToolTip class. I'm just using a Panel that moves around based on which PictureBox the mouse is over. I don't actually use a Paint method. I only hide / show the Panel.

If you know of a way to still use it, or something else. I'd be glad to see it! :D

@tlhintoq. After reading through the source code of that nice custom tool tip project, I don't think it'll work for me. It calls for binding the ToolTip text to each button ( PictureBox for me ). That would be probably alot of over head on my program. Plus the tool tip has a couple bugs that I wouldn't know how to iron out. Lastly my Tool Tip text is dynamic, and will change alot. It looks like I would have to rebind the custom tool tip to the picture box every time I changed the text.

Thanks for the link is it is a cool project, and it'll defiantly be something i'll wanna learn from.
Apr 1 '10 #8
GaryTexmo
1,501 Recognized Expert Top Contributor
You should still be able to override the paint event on the panel and get the information you need :)

If you wanted, you could even use the DrawString method to draw your text too, but that's up to you I guess.
Apr 1 '10 #9
Samishii23
246 New Member
Ok gary, thanks for the input, I finally was able to get around to implementing that Paint event idea of yours. The results aren't the best. But it works. :) Thanks for the help both of you!
Expand|Select|Wrap|Line Numbers
  1.         public void HandlePaint_ToolTip(object X, PaintEventArgs EX) {
  2.             SizeF SSize = new SizeF();
  3.             float TTHeight;
  4.  
  5.             SSize = EX.Graphics.MeasureString(ToolTipDisc.Text, ToolTipDisc.Font);
  6.             TTHeight = SSize.Width / (float)ToolTipDisc.Width + 1.5f;
  7.             ToolTipDisc.Height = ((int)SSize.Height * (int)TTHeight);
  8.             }
May 24 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2376
by: K | last post by:
I have found a script online that I want to use (I am new to PHP). It creates dynamic images based on the text that you pass it. However, no matter how I try, I can't get anything other than a blank white image. Can one of you knowledgeable people please have a look at the code below and help please.
7
3557
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET) template. Briefly -------------------------------------------------------------------------------------------- I need to create dynamically some controls on the forms, and display these
1
7154
by: Peter | last post by:
Hi, Does anyone know of how I could dynamically resize an iframe based on the content's height (for IE) so that no scrollbar appears for the iframe? The content will be from a different domain. I have searched on the web and have seen solution like this <script> function resize() { var oframe = document.getElementById("frameID");
2
7696
by: dawg1998 | last post by:
I have a page that creates dynamic textboxes based on the number of fields a user chooses to fill out. This process worked great when the page was standalone. However, when I move to a Content/MasterPage setup, the MasterPage Form seems to be interfering with the ability of my code to retrieve the value in the dynamic control. Are there any ideas on why this is happening or how to work-around the problem? What is the syntax to find a...
1
5531
by: nsvmani | last post by:
Hi, i am trying to get the FileOpen dialogue window as soon as clicked href link I am using IE6 with ActiveX enabled. Just need to get the File Open dialogue window when i click on the HREF links.It would be great , if i know how to create the dynamic HREF links like it should be getting different document based on each userid. Here is my part of jsp code for your reference: <%@ page...
1
1353
by: Johanna | last post by:
I am a real php newbie, I am having to learn as I go along - no time for tutorials or books! Background to my problem: I am working on a Wordpress theme for my personal blog -http://www.vikingprincess.net The layout is a centre column and two sidebars. I just decided I want a fourth sidebar at the very right, floating at the right of the rest of the content.
1
2709
by: SunshineInTheRain | last post by:
The following code is dynamic create dropdownmenu which data within pulled from database However, the code work well on IE but not on Firefox. On Firefox, the whole mouseover and mouseout function din't work. what is not supported on Firefox? the javascript syntax? please help as i am not familiar with javascript. thanks in advanced. this is quite urgent.... please.. By the way hope there has somebody may help me find out why the design may...
6
8850
by: Miro | last post by:
Is there a way to / or a mathematical formula to see if a font size is 'too big' for a label. I have a label that is docked to 'fill' a form, and I want to resize that font based on the width and height of the label. So far I have something like this on the Form_Resize event: Label2.Font = New Font(Label2.Font.Name, _ Label2.Size.Height - 100, Label2.Font.Style)
0
4350
by: Czechtim | last post by:
Hello, I have problem with databinding. I created small application using structure that I need to demonstrate problem. I need to change content of label when changing content of property "Promena". I change content of property "Promena" from "Origin text" to "Changed text" using thread but content of label is still the same - databinding isn´t working according to my vision. Does somebody know, please, why content of label doesn´t change...
0
9399
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9957
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9835
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5276
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.