9 Replies - 297 Views - Last Post: 10 January 2013 - 01:11 PM Rate Topic: -----

#1 bboyzeez  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 142
  • Joined: 16-December 12

Form drawstring problem

Posted 10 January 2013 - 06:35 AM

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

Is This A Good Question/Topic? 0
  • +

Replies To: Form drawstring problem

#2 MrShoes  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 312
  • View blog
  • Posts: 486
  • Joined: 13-June 12

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?
Was This Post Helpful? 0
  • +
  • -

#3 Anthonidas  Icon User is offline

  • D.I.C Head

Reputation: 30
  • View blog
  • Posts: 215
  • Joined: 25-April 11

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

Was This Post Helpful? 0
  • +
  • -

#4 bboyzeez  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 142
  • Joined: 16-December 12

Re: Form drawstring problem

Posted 10 January 2013 - 07:09 AM

View PostAnthonidas, 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 :)
Was This Post Helpful? 0
  • +
  • -

#5 Anthonidas  Icon User is offline

  • D.I.C Head

Reputation: 30
  • View blog
  • Posts: 215
  • Joined: 25-April 11

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;


Posted Image

This post has been edited by Anthonidas: 10 January 2013 - 07:23 AM

Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5316
  • View blog
  • Posts: 11,361
  • Joined: 02-June 10

Re: Form drawstring problem

Posted 10 January 2013 - 07:58 AM

If you're trying autosize the string to match the form:

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.
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3169
  • View blog
  • Posts: 9,605
  • Joined: 05-May 12

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.

This post has been edited by tlhIn`toq: 10 January 2013 - 09:29 AM
Reason for edit:: Corrected for dictation by voice? typos

Was This Post Helpful? 0
  • +
  • -

#8 bboyzeez  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 142
  • Joined: 16-December 12

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
Was This Post Helpful? 0
  • +
  • -

#9 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3169
  • View blog
  • Posts: 9,605
  • Joined: 05-May 12

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. :-)
Was This Post Helpful? 0
  • +
  • -

#10 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5316
  • View blog
  • Posts: 11,361
  • Joined: 02-June 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1