Results 1 to 7 of 7

Thread: [RESOLVED] [3.0/LINQ] Allow inherited control to be selectable and have focus

  1. #1

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Resolved [RESOLVED] [3.0/LINQ] Allow inherited control to be selectable and have focus

    I have a control that inherits from UserControl and i want it to be selectable and to receive input focus. (I need to be able to give it focus and make it selectable through code).

    I've tried setting the controlstyle to selectable, hiding the inherited CanSelect/CanFocus properties (using new bool ....) but even that doesn't give the control focus when i do MyControl.Focus() and ParentForm.ActiveControl = this.

    Any ideas?
    Last edited by SLH; Nov 23rd, 2008 at 06:43 AM.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [3.0/LINQ] Allow inherited control to be selectable and have focus

    What you're doing is wrong. A UserControl is supposed to be a container for multiple child controls. That's what the UserControl class exists for. If you want to make a control that can receive focus then you should be inheriting the Control class, not the UserControl class.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: [3.0/LINQ] Allow inherited control to be selectable and have focus

    Ahhh that explains it! Thanks for the tip. (I love being able to write a question before i go to bed and get an answer when i wake up!!).

    Rating++

    EDIT: Looks like you help me too often, can't give you rep until i've given it to others.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  4. #4

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: [3.0/LINQ] Allow inherited control to be selectable and have focus

    Hmm, i now have my class inheriting from Control, rather than UserControl and it still has CanFocus and CanSelect returning false even with me hiding the inherited versions and setting the selectable style for my control.

    Any ideas, do i need to inherit some other control that allows focus?
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [3.0/LINQ] Allow inherited control to be selectable and have focus

    I've never actually developed a custom control myself so I'm not sure of all the details. I think at least you have to call SetStyle in the constructor and set the Selectable style. I'd go to MSDN and do some reading on authoring custom controls.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: [3.0/LINQ] Allow inherited control to be selectable and have focus

    I did have a search around before posting, but i'll have another go if no-one else has any ideas.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  7. #7

    Thread Starter
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051

    Re: [3.0/LINQ] Allow inherited control to be selectable and have focus

    I used a .net reflector to see what CanFocus and CanSelect did internally.
    Seems that they actually do some low-level looking at window handles.
    Because of what i'm doing with the control and form (rendering it via XNA) the functions always return false. Soooo.... i've just created several methods that hide all the selection and focusing related functions.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


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