Results 1 to 6 of 6

Thread: FontDialog

  1. #1

    Thread Starter
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575

    FontDialog

    Hey,
    I have this code:
    VB Code:
    1. FontDialog1.ShowDialog()
    2.         If DialogResult = DialogResult.OK Then txtText.Font = FontDialog1.Font
    Does anyone know why it doesn't change the font when you press okay? Am I doing something wrong here? I have never used DialogResults before, so I'm not sure what I'm doing. But I don't understand why that wouldn't work.

    Thanks!

  2. #2
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    I think it's a problem with If DialogResult - something like this seems to work:
    VB Code:
    1. If FontDialog1.ShowDialog() = DialogResult.OK Then
    2.             txtText.Font = FontDialog1.Font
    3.         End If

  3. #3

    Thread Starter
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    thanks worked fine

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    I read on MS site that inline If statements should NOT be used in .net

    why? im not sure... but it would appear that maybe this is one of those reasons?

  5. #5

    Thread Starter
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    nah, i used inline there too.
    VB Code:
    1. If FontDialog1.ShowDialog() = DialogResult.OK Then txtText.Font = FontDialog1.Font
    i think the problem was something to do with the DialogResult wasn't targeted at the FontDialog. Think that's a bit shoddy if you ask me, that it went without errors for the method i did.

    Anyway, i don't mind inline If statements myself. I say, if i'm only gunna do one thing, i'm not gunna bother wasting lines and include an End If at the end.

    I think Microsoft just don't like it because its a bad habit or something... like the bad habits in html where you just do
    <p>Lalala
    <p> lalala

    instead of <p>Lalala</p>
    <p>lalalal</p>

    if u get what i mean... stupid things like this, they want you to close your if statements and not just let the compiler do it. i don't care really myself. i'm just going to go over to labeling my variables

  6. #6
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    I've heard that too, that's it's a bug, so I don't use. Plus, I prefer having the if and end if - easier for me to read.

    But, that is not a problem with the original code. This works fine:
    VB Code:
    1. If FontDialog1.ShowDialog = DialogResult.OK Then txtText.Font = FontDialog1.Font

    This does not work fine:
    VB Code:
    1. FontDialog1.ShowDialog()
    2.         If DialogResult = DialogResult.OK Then txtText.Font = FontDialog1.Font
    3.         MessageBox.Show(DialogResult)
    4.         MessageBox.Show(DialogResult.OK)

    I put in the MessageBox stuff. Notice the original code says If 0 = 1, so it's never true. 0 is the default value for DialogResult.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width