Results 1 to 7 of 7

Thread: How to know when a control is selected at designtime

  1. #1

    Thread Starter
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339

    How to know when a control is selected at designtime

    Ok this is kind of a wierd one, I have a control i made which inherits from ComboBox but creates a label to show over top of itself. Everything works fine EXCEPT that you can't click on the control at designtime to select it, you have to drag over it to select it. I think this is happening because you are actually selecting the label in front of it which doesn't actually belong to the form or have a site. I tried to catch any events in either the label or the combo itself at designtime to just have the label forward the selection to the combo, but I don't know the right event. I can't get the enter, gotfocus, click, mousedown, mousemove events to fire on either control at designtime. About the only event that I can get to work is ChangeUI but that doesn't do what I need or fire when i need. So now that I have bored you, anyone know how to catch an event or know when a control is selected at designtime?
    Last edited by Edneeis; Jul 17th, 2003 at 10:16 AM.

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    you could try casting each control ( DirectCast ) then adding a handler to a universal Click sub , all control's click events ( or not all if you choose to ) will be handled and captured , here's a quick example i knocked up :
    VB Code:
    1. Private WithEvents ctl As Control '/// this will handle all click events ( or other events if chosen.
    2.  
    3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.  
    5.         Dim objctl(Me.Controls.Count) As Control
    6.         Dim x As Integer
    7.         For x = 0 To Me.Controls.Count - 1
    8.             objctl(x) = DirectCast(Me.Controls(x), Control)
    9.             AddHandler objctl(x).Click, AddressOf ctl_Click
    10.         Next
    11.  
    12.     End Sub
    13.  
    14.     Private Sub ctl_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ctl.Click
    15.         MessageBox.Show("clicked by :" & sender.Name)
    16.     End Sub
    hope it helps
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3

    Thread Starter
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Except that this needs to be done from within a control (so there is no form) and at designtime. I tried catching the click event but it doesn't fire at designtime apparently. Thanks though.

  4. #4
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840

    Had the same problem...

    Hi.

    I had the same problem, when I had multiple controls in my usercontrol.
    I used as listview with some other controls on top.
    I found that, on my UserControl_Load event, I could check the DesignMode property of my usercontrol.
    If that property was TRUE then all my other child-controls should have their Enabled = FALSE.

    This means that my controls will have a boring grey backcolor, but
    at least I'm able to select my control.

    I hope you can use this.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  5. #5

    Thread Starter
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Damn I thought that would work but I'm inheriting from a combobox so there is no UserControl_Load event.

    I overrode the OnCreateControl method and that seems to work, now if there is only a way to make it show enabled still. Thanks.
    Last edited by Edneeis; Aug 4th, 2003 at 02:28 PM.

  6. #6

    Thread Starter
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Or does anyone know how to select a control at designtime? I tried the Select and Focus methods but they didn't do anything at designtime. I also tried calling the OnChangeUIClues method of the base type but that didn't work either.

  7. #7
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840

    How about a designer.

    Hi Edneeis.

    I'm not really sure, since I haven't tried this before, but what
    about making a designer, just like the helpprovider, or the tooltip
    controls. They have a class that implements IDesigner
    (or something like that) that allows them to execute code at
    designtime. There should be some way to access the focus event or something like that, and also
    access the IDE like a macro to select the control.


    I think there is a sample included in VS .Net. that uses a designer.
    Something with a helplabel, if I'm not mistaken.

    I don't know if this helps at all, but maybe it's worth looking into.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width