Results 1 to 3 of 3

Thread: [2005] Select Panel, get Focus Rectangle

  1. #1

    Thread Starter
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    [2005] Select Panel, get Focus Rectangle

    I have a form that adds one or more custom controls to it that are inherited from the Panel class. I need the custom control to be selectable so the user can change the properties of individual controls. The Panel class is not selectable, even though it has a Public Select Method . Can anyone suggest a method for allowing the custom control to be selectable and also display a focus rectangle?
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

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

    Re: [2005] Select Panel, get Focus Rectangle

    The Panel class a a Select method because it's inherited from Control. Certain members have no effect for certain controls. I've never made an unselectable control selectable but I have done it the other way around. here's my code for a Button that cannot receive focus:
    vb.net Code:
    1. ''' <summary>
    2. ''' A button control that cannot receive focus.
    3. ''' </summary>
    4. Public Class UnselectableButton
    5.     Inherits System.Windows.Forms.Button
    6.  
    7. #Region " Constructors "
    8.  
    9.     ''' <summary>
    10.     ''' Initialises a new instance of the <see cref="UnselectableButton"/> class.
    11.     ''' </summary>
    12.     Public Sub New()
    13.         MyBase.New()
    14.  
    15.         'The button cannot receive focus.
    16.         Me.SetStyle(ControlStyles.Selectable, False)
    17.     End Sub
    18.  
    19. #End Region 'Constructors
    20.  
    21. #Region " Constants "
    22.  
    23.     ''' <summary>
    24.     ''' The message received from Windows when the form is activated by a mouse click.
    25.     ''' </summary>
    26.     Private Const WM_MOUSEACTIVATE As Integer = &H21
    27.     ''' <summary>
    28.     ''' The reply sent to Windows to indicate that the form should not be activated.
    29.     ''' </summary>
    30.     Private Const MA_NOACTIVATE As Integer = 3
    31.  
    32. #End Region 'Constants
    33.  
    34. #Region " Variables "
    35.  
    36.     ''' <summary>
    37.     ''' Corresponds to the MA_NOACTIVATE window process reply.
    38.     ''' </summary>
    39.     Private ReadOnly noActivate As New IntPtr(MA_NOACTIVATE)
    40.  
    41. #End Region 'Variables
    42.  
    43. #Region " Methods "
    44.  
    45.     ''' <summary>
    46.     ''' Processes Windows messages.
    47.     ''' </summary>
    48.     ''' <remarks>
    49.     ''' Informs Windows not to activate the window when it is clicked with the mouse.  Note that this behaviour applies to the client area of the window only.
    50.     ''' </remarks>
    51.     Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    52.         MyBase.WndProc(m)
    53.  
    54.         If m.Msg = WM_MOUSEACTIVATE Then
    55.             'Tell Windows not to activate the window on a mouse click.
    56.             m.Result = noActivate
    57.         End If
    58.     End Sub
    59.  
    60. #End Region 'Methods
    61.  
    62. End Class
    Presumably you'd have to do something similar for your control. You'd set the Selectable style to True, but I'm not sure what else. You'd probably have to take responsibility for drawing the focus rectangle at least.
    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
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    Re: [2005] Select Panel, get Focus Rectangle

    That's an interesting idea. I'll see what I can do. If I can't get it to work I'll just improvise. Thanks again John!
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

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