470,602 Members | 1,728 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,602 developers. It's quick & easy.

showdialog not working as expected

WvH
Hi,

When I create a new application, with just one button, then this code works
as expected:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim f As New ColorDialog
f.ShowDialog()
End Sub

As soon as I add some controls (a PictureBox, some NumericUpDown controls,
....) the ShowDialog does not work anymore: when I press the button, the
dialog is invisible. When I switch to another application and then back to
my app, the dialog box instantly becomes visible.

I can also press the <Alt> key to make the dialog visible. The same
behaviour goes for FontDialog, OpenFileDialog, ...

Thanks,

WvH
Nov 21 '05 #1
8 4884
Pass a reference to the dialog's owner through the constructor in this case
Me.

Regards,
--
Angel J. Hernández M.
MCP - MCAD - MCSD - MCDBA
http://groups.msn.com/desarrolladoresmiranda
http://www.consein.com

"WvH" <Wv*@nospam.msn.com> escribió en el mensaje
news:42***********************@news.skynet.be...
Hi,

When I create a new application, with just one button, then this code
works as expected:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim f As New ColorDialog
f.ShowDialog()
End Sub

As soon as I add some controls (a PictureBox, some NumericUpDown controls,
...) the ShowDialog does not work anymore: when I press the button, the
dialog is invisible. When I switch to another application and then back to
my app, the dialog box instantly becomes visible.

I can also press the <Alt> key to make the dialog visible. The same
behaviour goes for FontDialog, OpenFileDialog, ...

Thanks,

WvH

Nov 21 '05 #2
WvH,

Did you only drag those buttons or add as well something as topmost?

Cor
Nov 21 '05 #3
WvH,
As Angle suggests pass the "owner" to the ShowDialog.

Something like:

| Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
| System.EventArgs) Handles Button1.Click
| Dim f As New ColorDialog
| f.ShowDialog(Me)
| End Sub

Note it goes on the call to ShowDialog, not the constructor.

Hope this helps
Jay

"WvH" <Wv*@nospam.msn.com> wrote in message
news:42***********************@news.skynet.be...
| Hi,
|
| When I create a new application, with just one button, then this code
works
| as expected:
|
| Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
| System.EventArgs) Handles Button1.Click
| Dim f As New ColorDialog
| f.ShowDialog()
| End Sub
|
| As soon as I add some controls (a PictureBox, some NumericUpDown controls,
| ...) the ShowDialog does not work anymore: when I press the button, the
| dialog is invisible. When I switch to another application and then back to
| my app, the dialog box instantly becomes visible.
|
| I can also press the <Alt> key to make the dialog visible. The same
| behaviour goes for FontDialog, OpenFileDialog, ...
|
| Thanks,
|
| WvH
|
|
Nov 21 '05 #4
WvH
Jay and Angle,

Thanks for the suggestion, but unfortunately no difference.

I'm getting closer to the cause of the problem though: there is 1 PictureBox
on the form, which has only got this code:

Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint

Dim bit As Bitmap = New Bitmap(20, 20)
PictureBox1.Image = bit

End Sub

If I leave out the PictureBox1.Image = bit , the ColorDialog appears
correctly.

I'm obviously missing something...

Thanks,
WvH
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> schreef in bericht
news:uf**************@TK2MSFTNGP14.phx.gbl...
WvH,
As Angle suggests pass the "owner" to the ShowDialog.

Something like:

| Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
| System.EventArgs) Handles Button1.Click
| Dim f As New ColorDialog
| f.ShowDialog(Me)
| End Sub

Note it goes on the call to ShowDialog, not the constructor.

Hope this helps
Jay

"WvH" <Wv*@nospam.msn.com> wrote in message
news:42***********************@news.skynet.be...
| Hi,
|
| When I create a new application, with just one button, then this code
works
| as expected:
|
| Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
| System.EventArgs) Handles Button1.Click
| Dim f As New ColorDialog
| f.ShowDialog()
| End Sub
|
| As soon as I add some controls (a PictureBox, some NumericUpDown
controls,
| ...) the ShowDialog does not work anymore: when I press the button, the
| dialog is invisible. When I switch to another application and then back
to
| my app, the dialog box instantly becomes visible.
|
| I can also press the <Alt> key to make the dialog visible. The same
| behaviour goes for FontDialog, OpenFileDialog, ...
|
| Thanks,
|
| WvH
|
|

Nov 21 '05 #5
WvH
Cor,

I just did some basic stuff:

New project, with 1 form, 1 button, 1 colordialog, 1 picturebox. There is
very little code until now (2 subs):

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

ColorDialog1.ShowDialog(Me)

End Sub

Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint

Dim bit As Bitmap = New Bitmap(20, 20)
PictureBox1.Image = bit

End Sub

If I leave out PictureBox1.Image = bit, clicking the button does correctly
show the colordialog.

Thanks,
WvH
"Cor Ligthert [MVP]" <no************@planet.nl> schreef in bericht
news:um**************@tk2msftngp13.phx.gbl...
WvH,

Did you only drag those buttons or add as well something as topmost?

Cor

Nov 21 '05 #6
WvH,

Your program is terrible looping in the routine where it is painting the
picturebox

Maybe you can set that picturebox.Image in another place than where it tells
that it is painting it after that it is set.

I hope this helps,

Cor
Nov 21 '05 #7
WvH,
As Cor states:

You are setting the PictureBox1.Image which is causing the PictureBox1.Paint
event to be raised which sets the PictureBox1.Image property, which is
causing the PictureBox1.Paint event to be raised which sets the
PictureBox1.Image property, which is causing the PictureBox1.Paint event to
be raised, which continues until you terminate your app.

For a demonstration of what is happening, try the following code:

Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
Debug.WriteLine("Begin PictureBox1_Paint")

Debug.Indent()
Debug.WriteLine("Begin set image")
Dim bit As Bitmap = New Bitmap(20, 20)
PictureBox1.Image = bit
Debug.WriteLine("End set image")
Debug.Unindent()

Debug.WriteLine("End PictureBox1_Paint")
End Sub

Private Sub PictureBox1_Invalidated(ByVal sender As Object, ByVal e As
System.Windows.Forms.InvalidateEventArgs) Handles PictureBox1.Invalidated
Debug.WriteLine("PictureBox1_Invalidated")
End Sub

As Cor suggests you need to remove setting the PictureBox1.Image in the
PictureBox1.Paint event handler.

Hope this helps
Jay

"WvH" <Wv*@nospam.msn.com> wrote in message
news:42***********************@news.skynet.be...
| Jay and Angle,
|
| Thanks for the suggestion, but unfortunately no difference.
|
| I'm getting closer to the cause of the problem though: there is 1
PictureBox
| on the form, which has only got this code:
|
| Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As
| System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
|
| Dim bit As Bitmap = New Bitmap(20, 20)
| PictureBox1.Image = bit
|
| End Sub
|
| If I leave out the PictureBox1.Image = bit , the ColorDialog appears
| correctly.
|
| I'm obviously missing something...
|
| Thanks,
| WvH
|
|
| "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> schreef in
bericht
| news:uf**************@TK2MSFTNGP14.phx.gbl...
| > WvH,
| > As Angle suggests pass the "owner" to the ShowDialog.
| >
| > Something like:
| >
| > | Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
| > | System.EventArgs) Handles Button1.Click
| > | Dim f As New ColorDialog
| > | f.ShowDialog(Me)
| > | End Sub
| >
| > Note it goes on the call to ShowDialog, not the constructor.
| >
| > Hope this helps
| > Jay
| >
| > "WvH" <Wv*@nospam.msn.com> wrote in message
| > news:42***********************@news.skynet.be...
| > | Hi,
| > |
| > | When I create a new application, with just one button, then this code
| > works
| > | as expected:
| > |
| > | Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
| > | System.EventArgs) Handles Button1.Click
| > | Dim f As New ColorDialog
| > | f.ShowDialog()
| > | End Sub
| > |
| > | As soon as I add some controls (a PictureBox, some NumericUpDown
| > controls,
| > | ...) the ShowDialog does not work anymore: when I press the button,
the
| > | dialog is invisible. When I switch to another application and then
back
| > to
| > | my app, the dialog box instantly becomes visible.
| > |
| > | I can also press the <Alt> key to make the dialog visible. The same
| > | behaviour goes for FontDialog, OpenFileDialog, ...
| > |
| > | Thanks,
| > |
| > | WvH
| > |
| > |
| >
| >
|
|
Nov 21 '05 #8
WvH
Jay & Cor,

After creating a seperate subroutine for assigning the image, everything is
working as expected.

Thanks for explaining and for my first debugging lesson ;-)

WvH

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> schreef in bericht
news:%2****************@tk2msftngp13.phx.gbl...
WvH,
As Cor states:

You are setting the PictureBox1.Image which is causing the
PictureBox1.Paint
event to be raised which sets the PictureBox1.Image property, which is
causing the PictureBox1.Paint event to be raised which sets the
PictureBox1.Image property, which is causing the PictureBox1.Paint event
to
be raised, which continues until you terminate your app.

For a demonstration of what is happening, try the following code:

Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
Debug.WriteLine("Begin PictureBox1_Paint")

Debug.Indent()
Debug.WriteLine("Begin set image")
Dim bit As Bitmap = New Bitmap(20, 20)
PictureBox1.Image = bit
Debug.WriteLine("End set image")
Debug.Unindent()

Debug.WriteLine("End PictureBox1_Paint")
End Sub

Private Sub PictureBox1_Invalidated(ByVal sender As Object, ByVal e As
System.Windows.Forms.InvalidateEventArgs) Handles PictureBox1.Invalidated
Debug.WriteLine("PictureBox1_Invalidated")
End Sub

As Cor suggests you need to remove setting the PictureBox1.Image in the
PictureBox1.Paint event handler.

Hope this helps
Jay

"WvH" <Wv*@nospam.msn.com> wrote in message
news:42***********************@news.skynet.be...
| Jay and Angle,
|
| Thanks for the suggestion, but unfortunately no difference.
|
| I'm getting closer to the cause of the problem though: there is 1
PictureBox
| on the form, which has only got this code:
|
| Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As
| System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
|
| Dim bit As Bitmap = New Bitmap(20, 20)
| PictureBox1.Image = bit
|
| End Sub
|
| If I leave out the PictureBox1.Image = bit , the ColorDialog appears
| correctly.
|
| I'm obviously missing something...
|
| Thanks,
| WvH
|
|
| "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> schreef in
bericht
| news:uf**************@TK2MSFTNGP14.phx.gbl...
| > WvH,
| > As Angle suggests pass the "owner" to the ShowDialog.
| >
| > Something like:
| >
| > | Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
| > | System.EventArgs) Handles Button1.Click
| > | Dim f As New ColorDialog
| > | f.ShowDialog(Me)
| > | End Sub
| >
| > Note it goes on the call to ShowDialog, not the constructor.
| >
| > Hope this helps
| > Jay
| >
| > "WvH" <Wv*@nospam.msn.com> wrote in message
| > news:42***********************@news.skynet.be...
| > | Hi,
| > |
| > | When I create a new application, with just one button, then this
code
| > works
| > | as expected:
| > |
| > | Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
| > | System.EventArgs) Handles Button1.Click
| > | Dim f As New ColorDialog
| > | f.ShowDialog()
| > | End Sub
| > |
| > | As soon as I add some controls (a PictureBox, some NumericUpDown
| > controls,
| > | ...) the ShowDialog does not work anymore: when I press the button,
the
| > | dialog is invisible. When I switch to another application and then
back
| > to
| > | my app, the dialog box instantly becomes visible.
| > |
| > | I can also press the <Alt> key to make the dialog visible. The same
| > | behaviour goes for FontDialog, OpenFileDialog, ...
| > |
| > | Thanks,
| > |
| > | WvH
| > |
| > |
| >
| >
|
|

Nov 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Richard L Rosenheim | last post: by
1 post views Thread by Miguel Arenas | last post: by
reply views Thread by Homa | last post: by
3 posts views Thread by Dom | last post: by
2 posts views Thread by =?Utf-8?B?a2VubmV0aG1Abm9zcGFtLm5vc3BhbQ==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.