Click here to Skip to main content
15,889,527 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

I am trying to create my own Message box similar to Windows message box.

I am using a panel on the MessageBox form to display the user message.

I am using MS Gothic as the Font type with size 10.Using point for the unit property of Font.

When I display the message, I found that the space between two line is very small.

I want to increase the space i.e I want to control it in the program.

Is there any property in VB.Net to achieve the above.


Appreciate any idea.


Regards,

Vijay.
Posted
Comments
Sergey Alexandrovich Kryukov 10-Sep-12 16:40pm    
Do you mean spacing between lines of the same Text property of the same control? Or between different controls like Lable or TextBox? (In last case, spacing is trivial). What are the controls containing the text?
--SA
Sergey Alexandrovich Kryukov 10-Sep-12 16:45pm    
If you mean line spacing in the same text (shown with end line characters or auto word wrapping), this is an interesting important question, I voted 4 in advance (would be 5 if more clearly formulated).
--SA
Vijay hit 10-Sep-12 20:51pm    
Thanks for the response.

Yes it is line spacing in the same text property of the same control.

To put my Q in simple way, I want to display 3 lines in a panel with proper line spacing between the lines.
If we use Windows message box, it will display 3 lines with proper spacing between lines.
I want to display in similar passion.
Sergey Alexandrovich Kryukov 10-Sep-12 21:34pm    
Well, I think I answer in full. If you have some concerns or some of further detail, you are welcome to ask your follow-up question. If you got the idea, please accept my answer formally (green button) -- thanks.
(Perhaps you mistyped "passion", which means ~strong feeling or addiction to one's activity, or suffering, in another meaning. Did you mean "fashion" or something else?)
--SA

1 solution

Please see my comments to the question: some clarification is needed.

If you want to make a spacing between texts of different controls, this is trivial: just insert some spacer Panel between them, having the same value of System.Windows.Controls.Dock property, either System.Windows.Forms.Top or System.Windows.Forms.Bottom:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.dock.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.dockstyle.aspx[^].

In principle, you can use this technique in a more complex case, see below.

So, what to do if you want to increase spacing in the rendered string shown with end line characters or auto word wrapping? This is pretty difficult, because neither System.Drawing.Canvas nor System.Drawing.Font has an appropriate property (but native GDI+ has, according to its documentation). One approach is this: you can parse the string into separate lines and render each line separately in some custom control in your OnPaint method. Such parsing is easy if the rendered line breaks are based only on end-of-line characters, but pretty difficult it the automatic word wrapping is used. In this case, you would need to measure each line's width:
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.measurestring.aspx[^],
http://msdn.microsoft.com/en-us/library/7sy6awsb.aspx[^].

The big problem here is that the width returned by these methods is not very accurate because it does not take hinting (http://en.wikipedia.org/wiki/Hinting[^]) in account.

Now, for the alternative, you can use read-only System.Windows.Forms.RichTextBox where you can set a paragraphs line spacing:
http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.aspx[^].

This would be much simpler; and the fact it's selectable is only for good: you can allow your customers to copy the text to clipboard, for example, to send an issue report. Experience shows that nearly all customers are physically unable to write what they could see on screen in an issue report.

—SA
 
Share this answer
 
Comments
Vijay hit 11-Sep-12 1:50am    
Hi Kryukov,

Thanks for the detail explanation.

However, I wanted to know is there any easy way or methods to implement my task.

Your first two idea seems lot of work is needed to implement.

So, I planned to go with read only mode Richtext box idea and it is working fine.

I am going to use it.

Thanks a lot.

Also, thank for reminding me not to make mistake while writing in hurry. Yes it is fashion.
In the same Fashion.

Vijay
Sergey Alexandrovich Kryukov 11-Sep-12 13:06pm    
You are very welcome.
Good luck, call again.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900