|
-
Jul 29th, 2004, 02:58 PM
#1
Thread Starter
Fanatic Member
FontDialog
Hey,
I have this code:
VB Code:
FontDialog1.ShowDialog()
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!
-
Jul 29th, 2004, 03:10 PM
#2
Frenzied Member
I think it's a problem with If DialogResult - something like this seems to work:
VB Code:
If FontDialog1.ShowDialog() = DialogResult.OK Then
txtText.Font = FontDialog1.Font
End If
-
Jul 29th, 2004, 03:21 PM
#3
Thread Starter
Fanatic Member
thanks worked fine
-
Jul 29th, 2004, 03:24 PM
#4
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?
-
Jul 29th, 2004, 03:29 PM
#5
Thread Starter
Fanatic Member
nah, i used inline there too.
VB Code:
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
-
Jul 29th, 2004, 03:31 PM
#6
Frenzied Member
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:
If FontDialog1.ShowDialog = DialogResult.OK Then txtText.Font = FontDialog1.Font
This does not work fine:
VB Code:
FontDialog1.ShowDialog()
If DialogResult = DialogResult.OK Then txtText.Font = FontDialog1.Font
MessageBox.Show(DialogResult)
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|