Results 1 to 3 of 3

Thread: [RESOLVED] An issue on Inheritance Class UserControl vs Control

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    597

    Resolved [RESOLVED] An issue on Inheritance Class UserControl vs Control

    I have a custom control, a function works for many years. Recently, I changed the inheritance from UserControl to Control. The function fails to return my expected result. How to modify to be the same?

    Code:
    public partial class UC: UserControl
    to:
    Code:
    public partial class UC: Control
    Code:
    private bool IsUCOrChildrenFocused()
    {
            IntPtr hWnd = NativeMethods.GetFocus();            
            return (hWnd == base.Handle) || (NativeMethods.GetParent(hWnd) == base.Handle) || (NativeMethods.GetParent(NativeMethods.GetParent(hWnd)) == base.Handle);    
    }
    Edited: The custom control contains one textbox and one combobox.
    For "public partial class UC: UserControl" case, when the TextBox is visible and Focused then .Visible = False, IsUCOrChildrenFocused will return true; but for "public partial class UC: Control", IsUCOrChildrenFocused always returns false.
    Last edited by DaveDavis; Jun 10th, 2022 at 04:41 AM.

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: An issue on Inheritance Class UserControl vs Control

    Note - this question was also asked in VB ... https://www.vbforums.com/showthread....rol-vs-Control


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    597

    Re: An issue on Inheritance Class UserControl vs Control

    Quote Originally Posted by techgnome View Post
    Note - this question was also asked in VB ... https://www.vbforums.com/showthread....rol-vs-Control


    -tg
    I have two version in C# and VB.NET. All codes are the same.
    I mark resolved.
    I adjusted some codes to suit the different Inheritances.

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