.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Modeless window always on top

20 REPLIES 20
Reply
Message 1 of 21
Anonymous
2280 Views, 20 Replies

Modeless window always on top

Hi,

I have a problem with modeless window. It stays on top even when it loses focus.

 

This is how I show the form:

 

            Dim myForm As New myFormClass
            Autodesk.AutoCAD.ApplicationServices.Application.ShowModelessDialog(formOwner, myForm)

 

Any ideas? TopMost property is set to False.

20 REPLIES 20
Message 2 of 21
cincir
in reply to: Anonymous

I think that is because you are using the ShowModelessDialog function and autocad threats your form as it is a paletteset. because you know palettesets are modeless windows but they are always on top. i advise you to use Form instances Hide method in forms lost focus event.

Message 3 of 21
Anonymous
in reply to: cincir

but that's not the behavior i want, the modeless window is the Help window and i want the user to be able to have the help shown and work with the program, be able to swithch to help and back.

the minimize works, but it's not that comfortable

Message 4 of 21
cincir
in reply to: Anonymous

Does making help window autohide solve your problem? You can create a paletteset instead of a form and make the paletteset autohide.

 

if not try Form.Show() instead of Application.ShowModelessDialog().

Message 5 of 21
Anonymous
in reply to: cincir

i tried Form.Show with the same result, i guess I'm doing something fundamentally wrong, or it's AutoCAD that's causing the problem

but I'm more inclined to blame AutoCAD, because when I make a winform application, it works fine

Message 6 of 21
cincir
in reply to: Anonymous

Which autocad are you using? I tested Form.Show in Autocad2012 and it works.

Message 7 of 21
Anonymous
in reply to: cincir

i'm using Civil 2012, but i run it as clean AutoCAD

 

did you use AcApp.ShowModalDialog for the main window, or did you use Form.ShowDialog ?

Message 8 of 21
cincir
in reply to: Anonymous

I used Form.Show() not Form.ShowDialog() . i thought that you want a modeless form.

Message 9 of 21
Anonymous
in reply to: cincir

I am opening the modeless form from a modal form

 

form1 has a button (or responds to keypress event)  that opens form2, form1 is modal, form2 is modeless

Message 10 of 21
kelidesign
in reply to: Anonymous

I'm just the opposite. No matter whether I apply TopMost or not, I can't switch to display it. I can only see this Form in the taskbar.

Message 11 of 21
kelidesign
in reply to: Anonymous

kelidesign_0-1714135580805.png

I have the most confusing problem, I have written two Forms, Form1 and Form2. Form2 can be displayed on top regardless of whether TopMost is set, but Form1 cannot be displayed anyway, and the Form can only be seen on the taskbar. Very infuriating, no distinction or difference to be found at all.

Message 12 of 21
daniel_cadext
in reply to: Anonymous

In ARX, you can handle WM_ACAD_KEEPFOCUS

https://help.autodesk.com/view/OARX/2024/ENU/?guid=GUID-90046447-0787-4FF8-8E91-870F085931A0

 

Not sure how to handle this on .NET.  I’m sure there’s a hook

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
Message 13 of 21
kelidesign
in reply to: Anonymous

Message 14 of 21
kelidesign
in reply to: Anonymous

Anyway, I don't know what the difference is between Form1 and Form2, and why are they treated differently? I probably know that it is related to window focus, but I want to know why these two are treated differently? One is normal and the other is always abnormal.

 

Of course, I will also try the method you mentioned to ensure that it is directly relevant. However, finding the patterns and characteristics of the problems I am currently facing is meaningful.

Message 15 of 21
norman.yuan
in reply to: kelidesign


@kelidesign wrote:

Anyway, I don't know what the difference is between Form1 and Form2, and why are they treated differently? I probably know that it is related to window focus, but I want to know why these two are treated differently? One is normal and the other is always abnormal.

patterns and characteristics of the problems I am currently facing is meaningful.


What does "I don't know what the difference..." mean? Your code creates/shows the forms, doe it not?

 

You should post your code that creates the forms (or even the code in the [Form].Designer.cs) and shows the forms. The video does not help much for identify the possible issues here.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 16 of 21
kelidesign
in reply to: norman.yuan

Of course I submitted it, in the Test.zip compressed package. Submitted along with the video.

Message 17 of 21
norman.yuan
in reply to: Anonymous

You did not mention, but the video clip shows that your running the code against AutoCAD 2018 (or, pre-2025 version, for that matters). However, when I open the *.csproj file, it CLEARLY shows that you selected WRONG project template of the Visual Studio: you used project template for .NET CORE class library, instead of class library template for .NET Framework. Things get event more confusing is that how come you can managed to make this project to target .NET Framework 4.6.2?

 

This is how a .NET Framework class project's Properties window look like:

normanyuan_0-1714314201652.png

 

This is how a .NET 8 class library project Properties window look like (FOR ACAD2025!)

normanyuan_1-1714314386151.png

 

However, this is YOUR PROJECT:

normanyuan_2-1714314499023.png

 

I am quite confused that how could you managed .NET Framework as target framework into .NET Core class library project? Did you somehow MANUALLY edited the project file?

 

Since you are targeting pre-AutoCAD2025 versions of AutoCAD, you MUST create the class library with .NET Framework project template. I think that is the cause of your issue.

 

 

 

 

Norman Yuan

Drive CAD With Code

EESignature

Message 18 of 21
kelidesign
in reply to: norman.yuan

Yes, the new project architecture supports this, in a simpler and more effective way, and there is no problem. I did this very early on and it has been working fine, you can try to create a traditional project, I don't think it is a core factor.

Message 19 of 21
kelidesign
in reply to: Anonymous
Message 20 of 21
norman.yuan
in reply to: Anonymous

OK. I used your project, made necessary changes: since the oldest AutoCAD version I have access to is Acad2021, so I had to change the referenced AutoCAD managed assemblies to Acad2021's, and in turn, change the .NET Framework to 4.7x, instead of your original 4.6x.

 

See the video clip: the 2 forms showed correctly (as modal dialog):

 

Here I do not believe the fact you use Acad2018/.NET Framework 4.6x is the cause of your issue: I have used Application.ShowModelessDialog() for all these years since Acad2006, and certainly in AutoCAD2018 with .NET Framework 4.6.x a few years back.

 

So, your issue is probably an strange, isolated issue to your specific computer/AutoCAD2018/.NET Framework4.6.x. Have you tried with other version of AutoCAD, in other computer? Have you made sure the "Copy Local" of the referenced AutoCAD assemblies are set to False?

 

 

Norman Yuan

Drive CAD With Code

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Autodesk Design & Make Report