IWindowsFormsEditorService question

  • Thread starter http://www.bit-kit.com
  • Start date
H

http://www.bit-kit.com

I have created an image selection dropdown editor for use in a
PropertyGrid. My selector form is called dropdown by a
IWindowsFormsEditorService and so far it's all sweet.

On my selector form I have placed a lot of pictures the user can select
from. I have also placed a button with "From File..." that opens an
OpenFileDialog (Remember that this is still in the dropdown dialog form
of the PropertyGrid). The problem is that when the "From File..."
button is clicked, ShowDialog() is called, the OpenFileDialog opens and
gets focus, and the selector form DISAPPEARS. As a second effect, the
OpenFileDialog stays topmost, yet the application can be used
underneath.

How can I keep the dropdown UITypeEditor visible after the
OpenFileDialog.ShowDialog() call, and yet make both controls disappear
if the user clicks somewhere else on the screen or presses esc?

Thanks!


- Peder -

http://www.bit-kit.com
 
N

Nicholas Paldino [.NET/C# MVP]

Peder,

I don't think you can. I think the designer gets the impression that
the focus has left the drop down and therefore, closes it.

Instead of using a drop down, why not use a form (return
UITypeEditorEditStyle.Modal from your override of GetEditStyle) and display
your pictures? You could then have a button on the form which you could use
to open the dialog, and you wouldn't have the issues you have now.

Hope this helps.
 
H

http://www.bit-kit.com

Hi Nicholas, and thanks for answering.

Well, I have considered switching to modal view. Keep in mind, however,
that this is not meant for designer use, but for a propertygrid in an
application. Furthermore, the way I understand it, it's the
IWindowsFormsEditorService that handles the focus/dropdown events for
the popup form. It seems to override or remove all common form events
on the popup form so that Deactivate doesn't work. Neither does
Dispose, Closing and all the rest.

My biggest issue is this:
If a user clicks the Image property in the PropertyGrid, the image
selector form appears dropdown. Then he/she clicks "From File..." and
the OpenFileDialog appears (and the image selector form in the
propertygrid disappears). Now, this is where Windows gets confused
because IWindowsFormsEditorService probably does some intricate message
handling. The OpenFileDialog stays topmost since it was opened modally.
Yet, since its owner form has disappeared, the user can continue to
work underneath the OpenFileFialog, and that looks plain weird. The
user should at the very least be denied to work with the application
underneath until either Ok or Cancel is clicked on the OpenFileDialog.
If I can just get this handled, I guess I can consider myself
adequately there.


- Peder -
 
N

Nicholas Paldino [.NET/C# MVP]

Peder,

I don't think you understand my initial response. The reason I
suggested that you use a modal view is because you aren't going to get the
behavior you want with a drop down, the property grid doesn't supply that
functionality.

You can still use a modal form for the property grid even though you are
not using this for a designer, but in an app.
 
H

http://www.bit-kit.com

Hi Nicholas, and thanks for your answer.

Yup, I understood your response perfectly. I was basically hoping for
some info about the obscure IWindowsFormsEditorService, which is not
well documented. Since it seems to override every Event in the form it
services, I figured it was possible to reoverride these things again.

However, I did more or less accomplish what I wanted, yet in a crude
way. I took a look at Word, and it too hides dropdown forms after the
opening of the next modal form (ref their color dialog). The problem
was the OpenFileDialog owner, since the UITypeEditor has no clue about
forms, and who owns what, and such. My dropdown form has, as mentioned,
a "From File..." button. This dropdown form is owned by itself. Again,
I guess this is because of the IWindowsFormsEditorService.

My program is rather large (around 100.000 lines so far), and it's my
thesis project. I keep a very exclusive class around with a few static
variables for common use. Upon the main form creation, I pass this
class a static reference to the main form, and retrieve it when I
create the OpenFileDialog. Thus, the owner of the OpenFileDialog
becomes the main form, and the application is locked until the user
either clicks Ok or Cancel. It might not be the most elegant solution,
but it works. Not to mention without interop, pinvoke, messaging and
all the other arcanities.


- Peder -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top