Hi all
So I have a challenge to use a getpointsize method to find the biggest size font I can use to display a string in a form.
I'm guessing as all the other challenges has been to allow the form to change size by user and everything else resizes but I don't quite know how to look at the form size say 400x400 and how to go about looking to see what size will be the largest to fit.
Is there some kind of command to check if my string fits in the form?
Thanks
Form drawstring problem
Page 1 of 19 Replies - 146 Views - Last Post: 10 January 2013 - 01:11 PM
Replies To: Form drawstring problem
#2
Re: Form drawstring problem
Posted 10 January 2013 - 06:41 AM
Not one I'm aware of. But maybe you need to create your own based on the Width and Height members of the Form?
#3
Re: Form drawstring problem
Posted 10 January 2013 - 06:49 AM
Well I am not the expert in C#, but I did something similair some time ago. In fact you could check the width of the form, get the most left and the most right points of the form and then do the same with your string. Doing that you chan check if the right point of your string is higher then your form's right point.
This post has been edited by Anthonidas: 10 January 2013 - 06:52 AM
#4
Re: Form drawstring problem
Posted 10 January 2013 - 07:09 AM
Anthonidas, on 10 January 2013 - 06:49 AM, said:
Well I am not the expert in C#, but I did something similair some time ago. In fact you could check the width of the form, get the most left and the most right points of the form and then do the same with your string. Doing that you chan check if the right point of your string is higher then your form's right point.
Ahh ok thanks both of you
Ye in the chapter I just went through it briefly spoke about g.measurestring...... I will give that a try thanks
#5
Re: Form drawstring problem
Posted 10 January 2013 - 07:21 AM
i have quickly tested what i said before, and in fact you can check the right point of your string in comparison to the form's width:
label2.Text = "Form Width: " + this.Width + " x " + this.Height; label3.Text = "String Left Point: " + label1.Left; // or label1.Bounds.Left; is the same label4.Text = "String Right Point: " + label1.Right;
This post has been edited by Anthonidas: 10 January 2013 - 07:23 AM
#6
Re: Form drawstring problem
Posted 10 January 2013 - 07:58 AM
If you're trying autosize the string to match the form:
I would however suggest, if its an option, to just leave WinForms behind. Its all equally new to you so why not just go straight to WPF where all this is handled so much better? WPF is the forward direction, WinForms is the past. Presentation is literally its middle name.
Loop
increase size
is g.measurestring bigger than the available space
if yes, drop back one size and exit loop
if no, continue loop
end loop
I would however suggest, if its an option, to just leave WinForms behind. Its all equally new to you so why not just go straight to WPF where all this is handled so much better? WPF is the forward direction, WinForms is the past. Presentation is literally its middle name.
#7
Re: Form drawstring problem
Posted 10 January 2013 - 08:25 AM
Yes, go WPF if you can.
Is you really much If you really must go WinForms, this blog post from the person in Microsoft who intimately knows the WinForms rendering engine will be infinitely helpful for what you are trying to do:
http://blogs.msdn.co.../30/403619.aspx
http://blogs.msdn.co.../07/478299.aspx
I've always found her blogs to be very helpful in understanding how WinForms works.
http://blogs.msdn.co.../30/403619.aspx
http://blogs.msdn.co.../07/478299.aspx
I've always found her blogs to be very helpful in understanding how WinForms works.
This post has been edited by tlhIn`toq: 10 January 2013 - 09:29 AM
Reason for edit:: Corrected for dictation by voice? typos
#8
Re: Form drawstring problem
Posted 10 January 2013 - 12:44 PM
Thanks all the loop worked perfect its an exercise like that which has pulled like 3 or 4 items I just learnt into place and made me understand them 
As for WPF I will admit noob and don't know what that is but basically I am following from this book now as I go on it gets more complicated and uses new things so maybe I move into that soon
Thanks again
As for WPF I will admit noob and don't know what that is but basically I am following from this book now as I go on it gets more complicated and uses new things so maybe I move into that soon
Thanks again
#9
Re: Form drawstring problem
Posted 10 January 2013 - 01:08 PM
Thanks for correcting my mangled English and typos earlier. That's what happens when you are running on just 4 hours of sleep and experiencing low blood sugar at the same time. :-)
#10
Re: Form drawstring problem
Posted 10 January 2013 - 01:11 PM
No worries mate. I figured it was just voice dictation on an iPad or iPhone since I've seen the same type of 'sounds like' typos when I use the voice dictation.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote






|