Windows Form - TopMost

Created at 19 Jun 2022, 21:47
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
M4

m4trader4

Joined 19.09.2021

Windows Form - TopMost
19 Jun 2022, 21:47


Dear Ahmad

 

i have Button.Click += Button_Click event

Button_Click opens a form with yes and no  with topmost = true. And in the form there is a a public event 

public event Action<string, string> Event_Button_Click_Yes; no.

Event_Button_Click is subscribed.

The form is getting opened with topmost to the main window of Ctrader. If i have child windows ie open a symbol chart and detach it. and run the cBot with  Button.Click += Button_Click event and subscribe to Event_Button_Click from the form. The form opens as topmost to main window not to detached window and gets hidden until re click to main window.

 

Where as in CTrader 4.1, it was working a topmost to the detached symbol window as topmost remained to detached window.

 Button.Click += args => CloseOrder("CBO");



void CloseOrder(string BName)
{

 this._f1 = new Form1(MBMsg1, MBHdr1, BName);
 this._thread = new Thread(() => _f1.ShowDialog());
 this._thread.SetApartmentState(ApartmentState.STA);
 this._thread.Start();
 this._f1.Event_Button_Click_Yes += _f1_Event_Button_Click_Yes1;


}


  public Form1(string Headline, string Msg, string BName)
        {
            InitializeComponent();
           
            this.TopLevel = true;
            this.TopMost = true;

            this.Focus();
            
            //this.TopMost() = true;
            richTextBoxMsg.Text = Msg;
            this.Text = Headline;
            richTextBoxMsg.Name = BName;
            SoundPlayer sound = new SoundPlayer(@"c:\Sound\Beep.wav");
            sound.Play();          
            

        }


 public event Action<string, string> Event_Button_Click_Yes;
        public void ButtonYes_Click(object sender, EventArgs e)  
        {


            this.Invoke((MethodInvoker)delegate
            {
                // BName = 

                Event_Button_Click_Yes("Yes", richTextBoxMsg.Name.ToString());
                Close();
            });
           

            }

 


@m4trader4
Replies

amusleh
20 Jun 2022, 10:06 ( Updated at: 20 Jun 2022, 10:07 )

Hi,

I just tested WinForms top most and it worked fine, I had several child windows and the WinForms window were over all of them.

The only issue I noticed was with file dialogs, they appear on the back of cTrader main window.

Check here: WinForms - cTrader Automate API

You can try the last WinForms sample and set it's top most to True before ShowDialog call.

And please post a full sample cBot code that can reproduce the issue.


@amusleh

m4trader4
20 Jun 2022, 17:07

RE:

Dear Ahmad

Let me rephrase

I have 2 screens 1 and 2

in Screen 1 CTrader Main window is running

In Screen 2, 5 different symbols(A,B,C,D,E) running on child windows of CTrader with cBot running with a pop up of form (Yes/No) topmost=true through a button click,  subscribed to Form's public event.

on symbol (A) i click button FORM pops up, then i click on Symbol (B), the FORM of symbol A vanishes, till i click on Main CTrader window to get it back as TOPMOST.

I suppose the FORM is running on the Main CTrader window thread not on the Symbol A or Symbol B thread.

The same was working perfectly fine in 4.1

 


@m4trader4

m4trader4
20 Jun 2022, 17:10

RE: RE:

Even on non button click on Symbol A window, form vanishes to back ground


@m4trader4

amusleh
21 Jun 2022, 09:22

Hi,

If you open a the window from a detached chart then it will appear behind the chart, if you open the window from an attached chart then it will appear over cTrader main window.

As your indicator / cBot runs from their own process it doesn't know about the cTrader windows so it's not possible for us to change this behavior.


@amusleh

m4trader4
21 Jun 2022, 10:08

RE:

But in 4.1 it was not the behaviour what changed

 


@m4trader4

m4trader4
21 Jun 2022, 10:15

RE: RE:

Let me know how this can be achieved with FORM or without FORM


@m4trader4

m4trader4
21 Jun 2022, 10:16

RE: RE: RE:

Is there a way to move a button within the child window

 


@m4trader4

amusleh
21 Jun 2022, 10:40

RE: RE:

Hi,

But in 4.1 it was not the behaviour what changed

Yes, this is a behavior change, we are not going to change it back to 4.1 behavior as it's not possible.

Let me know how this can be achieved with FORM or without FORM

We are going to add dialog and window to the API that mimics the looks of cTrader and uses current controls, then you don't have to use WinForms or WPF.

Is there a way to move a button within the child window

What do you mean?


@amusleh

m4trader4
21 Jun 2022, 10:48

RE: RE: RE:

amusleh said:

Hi,

But in 4.1 it was not the behaviour what changed

Yes, this is a behavior change, we are not going to change it back to 4.1 behavior as it's not possible.

Let me know how this can be achieved with FORM or without FORM

We are going to add dialog and window to the API that mimics the looks of cTrader and uses current controls, then you don't have to use WinForms or WPF.

What is the ETA

Is there a way to move a button within the child window

What do you mean?

Algo.api.button is created OnStart() and if the button is selected it can be moved within the child screen. and OnClick execute

 

Button.Move += move to any cordinates within the child symbol window

Button.Click += execute some trade operations

 

 


@m4trader4