Note that there are some explanatory texts on larger screens.

plurals
  1. POHighlighting around textboxes
    text
    copied!<p>I am trying to draw a highlighted border around a custom textbox control so that I can reuse the highlighting feature for each new program I create. My approach so far has been to override the paint event in the control library (dll) after the custom property I have created is set. The code for the control is below.</p> <pre><code>Imports System.Windows.Forms Imports System.ComponentModel Imports System.Drawing Imports System.ComponentModel.Design &lt;ToolboxBitmap(GetType(Button))&gt; Public Class Textbox_Custom Inherits System.Windows.Forms.TextBox Public Event OnEnterKeyPress() Public Event MissingInfo_Change As EventHandler Dim iMissing_Info As Boolean Dim iCharacterInput As Cinput Public Property CharacterInput As Cinput '&lt;Browsable(True), DefaultValue("AllowAll")&gt; Get Return Me.iCharacterInput End Get Set(ByVal value As Cinput) Me.iCharacterInput = value End Set End Property Public Property Missing_Info As Boolean '&lt;Browsable(True), DefaultValue(True)&gt; Get Return iMissing_Info End Get Set(value As Boolean) iMissing_Info = value **MyBase.Refresh()** End Set End Property Protected Overrides Sub OnKeyPress(e As KeyPressEventArgs) MyBase.OnKeyPress(e) If Asc(e.KeyChar) = 13 Then RaiseEvent OnEnterKeyPress() End If Select Case Me.iCharacterInput Case Cinput.CharactersOnly If IsNumeric(e.KeyChar) Then e.Handled = True End If Case Cinput.NumericOnly If Not IsNumeric(e.KeyChar) And Asc(e.KeyChar) &lt;&gt; 8 Then e.Handled = True End If End Select End Sub Protected Overrides Sub OnPaint(e As PaintEventArgs) MyBase.OnPaint(e) **If iMissing_Info = True Then** Dim rect As New Rectangle(New Point(0, 0), New Size(Me.Size.Width + 2, Me.Size.Height + 2)) Dim pen As New Pen(Brushes.OrangeRed, 2) e.Graphics.DrawRectangle(pen, rect) e.Dispose() End If End Sub End Class Public Enum Cinput AllowAll NumericOnly CharactersOnly End Enum </code></pre> <p>While debugging I have set a breakpoint in the OnPaint override (lines **), but it never hits it. I then put a breakpoint in the Set section of the Missing_Info property where I am trying to invalidate the control to redraw. It does hit the MyBase.Refresh breakpoint so I don't understand what I've missed.</p> <p>I realize there have been several other posts on this topic, but from what I can tell they seem to require putting panels behind the control. I feel like I should be able to include this action in a custom control and not have to code a new highlighting section for each new project. Thanks for any help in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload