Disable selection of a Win Form

D

dannylin

Hi all,

I'm working on a project that needs to create two layered windows
(Forms).
I can sequentially create them to get the z-order of the forms
correct.
but when a user click on the bottom form, it activates the form and
brings it to the front.

I'm thinking if i can disable the form and let these two forms never
get activated.

can anyone help

thanks
 
P

Peter Duniho

dannylin said:
Hi all,

I'm working on a project that needs to create two layered windows
(Forms).
I can sequentially create them to get the z-order of the forms
correct.
but when a user click on the bottom form, it activates the form and
brings it to the front.

I'm thinking if i can disable the form and let these two forms never
get activated.

can anyone help

What's your question?

Disabling the first form displayed will in fact prevent it from being
activated.

If you want something else, you need to be more specific.

Pete
 
D

dannylin

What's your question?

Disabling the first form displayed will in fact prevent it from being
activated.

If you want something else, you need to be more specific.

Pete

ok

Actually I have one MainForm , in the MainForm I create two another
Forms by

MyForm formA = new MyForm();
MyForm formB = new MyForm();
formA.show();
formB.show();

Because formB is created right after formA, so formB will partially
overlaps formA.

now the question is I don't want a user to select formA , because it
will bring the formA to the front.

I like the forms not to respond to any mouse click. The forms will be
closed only when user close MainForm.

_____________
_____________ |________ ____|_________
|_____________| | |_____________|
| mainForm | | formA | formB |
| | |________| |
|_____________| |_____________|
 
J

Jeff Johnson

I like the forms not to respond to any mouse click. The forms will be
closed only when user close MainForm.

Then what's the point of formA? I have to say, from the brief description
you've given, this design sounds horrible. It does not behave like 99.999%
of Windows applications, and generally that's a bad thing. Could you explain
in more detail WHY you don't want formA to receive focus?
 
D

dannylin

Then what's the point of formA? I have to say, from the brief description
you've given, this design sounds horrible. It does not behave like 99.999%
of Windows applications, and generally that's a bad thing. Could you explain
in more detail WHY you don't want formA to receive focus?

I AGREE this looks a very weird design.
The reason why I try to open multiple forms in this way is a long
story.

my program is to play video/image/swf on a screen in the mean time.
In the original design, I encapsulate the video/image/swf into a
control.
everytime when i need to play them, I add the control into my main
form, set it's z-index, then i have all the beauty of controls can
give me.
It works really great.

But one of my customer's feedback wants us to add the transparency to
swf, then he can place transparent swf on top of an image file.
after i google it and search lots of forums, I found the .net doesn't
support "windowless control", which makes transparent swf is
impossible. I don't know why .net has this limitation because the same
requirement(transparency) can be easily achieved by vb6 and vc++.

But we don't want to change a language, so we think the alternative is
to create forms instead of controls. we then can set the window to
WS_EX_layered to get the form work like a layered controls in my old
program.

anyone has better suggestion would be very welcome
 
P

Peter Duniho

dannylin said:
[...]
But one of my customer's feedback wants us to add the transparency to
swf, then he can place transparent swf on top of an image file.
after i google it and search lots of forums, I found the .net doesn't
support "windowless control",

I'm not sure what "windowless control" is even supposed to mean. In
Windows, _all_ controls are windows, by definition. An application can,
of course, implement its own user-interface scheme in which there are
things that look to the use like controls, but they wouldn't actually be
controls in the sense that the Windows API (_all_ of it, not just .NET)
uses the word "control".
which makes transparent swf is
impossible. I don't know why .net has this limitation because the same
requirement(transparency) can be easily achieved by vb6 and vc++.

It's true that .NET Forms do not handle transparent controls very well,
if at all. The only approaches I've seen that work are basically hacks.
But I don't think that manipulating forms in this way is the right
solution. You would be much better off switching APIs than trying to
force Forms to do what you want.
But we don't want to change a language, so we think the alternative is
to create forms instead of controls. we then can set the window to
WS_EX_layered to get the form work like a layered controls in my old
program.

anyone has better suggestion would be very welcome

If I recall correctly, WPF supports transparency at the control level,
not just the top-level windows. So one option would be to use WPF
instead of Forms.

I'm curious about your claim that "the same requirement(transparency)
can be easily achieved by vb6 and vc++". As far as I know, this is not
true (they, and especially C++, should have the same limitations as
Forms, as Forms is just a thin wrapper around the unmanaged Win32 API).
But, assuming you can do it in those environments, another alternative
would be to implement the specific transparency-related functionality in
C++, and then call that from your C# code.

Pete
 
J

Jeff Johnson

I'm not sure what "windowless control" is even supposed to mean. In
Windows, _all_ controls are windows, by definition. An application can,
of course, implement its own user-interface scheme in which there are
things that look to the use like controls, but they wouldn't actually be
controls in the sense that the Windows API (_all_ of it, not just .NET)
uses the word "control".

"Windowless control" comes from the Classic VB world, and it's basically as
you describe: the application handles the drawing of the control and there
is no HWND associated with it. VB does this with labels instead of using the
STATIC control (in dialog box terminology).
 
D

dannylin

If I recall correctly, WPF supports transparency at the control level,
not just the top-level windows.  So one option would be to use WPF
instead of Forms.

I'm curious about your claim that "the same requirement(transparency)
can be easily achieved by vb6 and vc++".  As far as I know, this is not
true (they, and especially C++, should have the same limitations as
Forms, as Forms is just a thin wrapper around the unmanaged Win32 API).
  But, assuming you can do it in those environments, another alternative
would be to implement the specific transparency-related functionality in
C++, and then call that from your C# code.

Pete

I'm not familiar with WPF but I will try it later.
I don't know why C# WinForm has such bad transparent support.
 
P

Peter Duniho

dannylin said:
I'm not familiar with WPF but I will try it later.
I don't know why C# WinForm has such bad transparent support.

First, it's not "C# WinForm". It's the .NET System.Windows.Forms
namespace classes. It's the same whether you are using C# or any other
..NET language.

As for why it is the way it is, I already explained that. It's because
that's how the unmanaged controls API in Windows works. Forms provides
very little in the way of additional features beyond what's already in
the unmanaged Windows API.

Pete
 

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