Same ContextMenu on different Controls

Discussion in 'Code Samples & Tips' started by klaus, Jan 22, 2009.

  1. klaus

    klaus Expert Licensed User

    This is a small example, using the Door library, to manage a same ContextMenu on different Controls.

    The request comes from the German forum on how to get the Control name from where the ContextMenu was triggered.

    I think this could be usefull for others.

    Best regards.
     

    Attached Files:

  2. PatrikL

    PatrikL Member Licensed User

    Hi klaus,

    thanx for this sample program. I try it, but doesnt work on realtime designed componets. For designer placed object works fine. Can me explain why?
     
  3. klaus

    klaus Expert Licensed User

    What's the problem ?
    See the attached program, works OK with controls added at runtime.

    Best regards.
     

    Attached Files:

  4. PatrikL

    PatrikL Member Licensed User

    Hi Klaus,

    thanks for reply. Your demo works fine. I attach part of my prog, which dont work. Please check it (if You want) and say me why.

    Thanks.
     

    Attached Files:

  5. klaus

    klaus Expert Licensed User

    I tried your program, works fine on my desktop (IDE and compiled) and on my devices (autoscale compiled) (Qtek9090 WM2003, htc HD WM6.1.
    So, could you explain what doesn't work.

    - do you get an error ?
    - are the context menus not displayed ?
    - are the context menus not working ?
    - etc

    Best regards.
     
  6. PatrikL

    PatrikL Member Licensed User

    I run program in IDE for now.

    After start shows only panel with scrollbar. Then You must call context menu and select Add Text. On newly created textbox again You must call context menu and select first item. Then program shows messagebox. In this messagebox should be name of textbox which is owner of context menu. But doesnt show nothing.
     
  7. agraham

    agraham Expert Licensed User

    It is doing exactly what you have programmed it to to - displaying any text that has been typed into the textbox :confused:
     
  8. PatrikL

    PatrikL Member Licensed User

    In contextmenu click sub is code for giving name of textboxt which call context menu.

    Sub cmtext_Click
    'Dim Source
    cmtextobj2.Value=cmtext.Value
    cmtextobj1.Value=cmtextobj2.GetProperty("SourceControl")
    Source=cmtextobj1.GetProperty("Text")
    Msgbox(Source)
    End Sub

    According klaus demo program, this code show owner of context menu. In klaus demo program works fine. But not in my program. I cant understand why my code dont work (its same code as klaus code).
     
  9. agraham

    agraham Expert Licensed User

    Klaus' program is returning the text property of the owner control which just happens to be the name of the control in his demo. If you type into your textbox then use the context menu you will see the text you have typed.

    To get the name try

    Source=cmtextobj1.GetProperty("propName")

    This will only work on Basic4ppc intrinsic controls, not those added from a library.
     
  10. PatrikL

    PatrikL Member Licensed User

    Last edited: Sep 13, 2010
  11. agraham

    agraham Expert Licensed User

    Because they belong to the Textbox which is the source control, not the ContextMenu.

    For using the Door library you've found it - MSDN!

    Sorry but I won't be doing that.
     
  12. klaus

    klaus Expert Licensed User

    Sorry for answering that late, I was not at home this afternoon.

    I checked both, my example and your program.
    In fact it was not a good idea to use the Text property.

    The Name property doesn't work because it returns Door.object.

    I modyfied both programs using the Tag property,
    - I set the Tag property to control's name
    - Reading the Tag property gets it back.

    Best regards.
     

    Attached Files:

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice