Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devexpress PopupMenu Closing event like Windows Contextmenu Closing event

I am using Devexpress PopupMenu to show on right click. Now I want to know before closing of this popup menu, just like Windows ContextMenu Closing event.

PopupMenu has Closeup event, but that fires after closing of it. Actually my goal is to handle when to close the popup menu according to situations.

Is there anyway, I can achieve it?

like image 839
Rohit Prakash Avatar asked Nov 01 '22 13:11

Rohit Prakash


1 Answers

I found this previous issue - somebody tried to do the same thing using XtraBars.PopupMenu and had to create a subclass of BarManager and override the BarSelectionInfo.ClosePopup event (maybe you can adapt it to your scenario). The example project is attached to the issue and demonstrates selecting a date in the popup menu and the menu staying open.

EDIT:

Here's the relevant code for completeness - whenever the popup is about to close, ClosePopup fires, as per docs for BarManager :

When you place a BarManager on a form at design time, all controls publish the PopupContextMenu extender property (its caption in the Properties window looks like 'PopupContextMenu on barManager1')

You can assign the Context menu using this property and implement the override.

In the example, you return from the method based on some condition (cancel the event) - in this case the Tag of the Bar is set to False on an event in the Form and checked in the override.

      private void barEditItem1_EditValueChanged(object sender, EventArgs e) {
           popupMenu1.Manager.Bars[0].Tag = false;
      }

       using DevExpress.XtraBars;
       using DevExpress.XtraBars.ViewInfo;

        public class MyBarManager : BarManager {
            protected override BarSelectionInfo CreateSelectionInfo() {
                return new MyBarSelectionInfo(this);
            }
        }

        public class MyBarSelectionInfo : BarSelectionInfo {
            public MyBarSelectionInfo(BarManager manager)
                : base(manager) {
            }

            public override void ClosePopup(IPopup popup) {
                if (!(bool)Manager.Bars[0].Tag) {
                    Manager.Bars[0].Tag = true;
                    return;
                }

                base.ClosePopup(popup);
            }
        }
like image 180
Jaycee Avatar answered Nov 13 '22 17:11

Jaycee