Question Font dialog Help Needed

inkedgfx

Well-known member
Joined
Sep 29, 2012
Messages
139
Location
USA
Programming Experience
Beginner
I am trying to add a font dialog to my program...but whenever the code is fired the font dialog appears twice...when I run the program and click the buttom the font dialog appears..when I choose the font and size then click ok the dialog dissappears then reappears again..below is the code:

dim fontdlg as new fontdialog
dim colordlg as new colordialog

fontdlg.showdialog()


try

if (fontdlg.showdialog) = windows.forms.dialogresult.ok) then
fontdlg.showcolor = true
fontdlg.showapply = false
fontdlg.showeffects = false
fontdlg.maxsize = 72

myFont = fontdlg.font

colordlg.showdialog()

myWaterMarkColor = colordlg.color

end if



this results in the fontdialog showing twice in a row. also I added the color dialog because i couldnt get the fontdialog to show the color "fontdlg.showcolor" didnt add the color to the dialog.

any help is appreciated

thank you
InkedGFX







 





 
It's ShowDialog that displays the dialogue and you're calling ShowDialog twice so it displays twice. Get rid of that first call. Also, there's no point setting properties of the dialogue after it's closed. Create, configure it, display it.
 
ok....I didnt think the if statement would show the already shown dialog...thanks for your help.

InkedGFX
 
The If statement wouldn't show the dialogue again if you were to test the result of the first ShowDialog call but you are making a second ShowDialog call and testing the result of that. If you call a method twice then it will execute twice. If you want to test the result of function later then you must assign that result to a variable and then test the variable, e.g.
VB.NET:
Dim result = fontdlg.showdialog()

try

if result = windows.forms.dialogresult.ok then
 
Back
Top