Click here to Skip to main content
15,890,336 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionRe: Overlapping with a Picturebox other controls having the picturebox transparent background VB .NET Pin
Richard MacCutchan19-Nov-13 4:37
mveRichard MacCutchan19-Nov-13 4:37 
AnswerRe: Overlapping with a Picturebox other controls having the picturebox transparent background VB .NET Pin
jose mandurrino19-Nov-13 5:39
jose mandurrino19-Nov-13 5:39 
AnswerRe: Overlapping with a Picturebox other controls having the picturebox transparent background VB .NET (update) Pin
Eddy Vluggen19-Nov-13 10:39
professionalEddy Vluggen19-Nov-13 10:39 
GeneralRe: Overlapping with a Picturebox other controls having the picturebox transparent background VB .NET (update) Pin
jose mandurrino19-Nov-13 13:05
jose mandurrino19-Nov-13 13:05 
GeneralRe: Overlapping with a Picturebox other controls having the picturebox transparent background VB .NET (update) Pin
Eddy Vluggen20-Nov-13 7:44
professionalEddy Vluggen20-Nov-13 7:44 
AnswerRe: Overlapping with a Picturebox other controls having the picturebox transparent background VB .NET (update) Pin
TnTinMn19-Nov-13 13:06
TnTinMn19-Nov-13 13:06 
GeneralRe: Overlapping with a Picturebox other controls having the picturebox transparent background VB .NET (update) Pin
jose mandurrino19-Nov-13 21:50
jose mandurrino19-Nov-13 21:50 
GeneralRe: Overlapping with a Picturebox other controls having the picturebox transparent background VB .NET (update) Pin
TnTinMn21-Nov-13 13:38
TnTinMn21-Nov-13 13:38 
First off, you are welcome. Nice to see that a poster actually appreciates our efforts. Smile | :)

Quote:
I discover also that with this suggestion or with just a picturebox, if it is inside a groupbox, the image/icon will not be show complete, it will be cut after the border.
Sheesh, some people want everything. Poke tongue | ;-P

Ok, I did a bit of playing around and found that if the target control is parented directly to the Form and not a sub container control, that the ErrorIcon will paint on top of everything. So with a little hacking, here is a custom ErrorProvider that will add a DummyControl directly to the form and post the error against that control instead.

Warning!, I have given this only minimal testing and did not include any fault detection/handling.
Maybe I will clean it up a bit when I have time and post it as Tip/Article. Unsure | :~

Give it a go and see how it works for you. Just add this code to your project and use it place of ErrorProvider when you declare an instance.

Public Class FloatingErrorProvider
   Inherits ErrorProvider
   ' Create a storage structure to hold the DummyControls that will
   ' be parented to the form that contains the control be error reported
   ' The ErrorProvider will display the ErrorIcon against these controls 
   ' instead of against the source control if the source control is not 
   ' directly parented to the form.
   Private AnchorControls As New Dictionary(Of Control, DummyControl)

   Private Function GetDummy(ByVal control As Control) As DummyControl
      Dim dummy As DummyControl
      If AnchorControls.ContainsKey(control) Then
         dummy = AnchorControls(control)
      Else
         dummy = New DummyControl            ' a zero sized, non-painting control
         dummy.Parent = control.FindForm     ' parent to the host form
         dummy.SendToBack()                  ' send to bottom of Z-order
         AnchorControls.Add(control, dummy)  ' store a reference to it
      End If
      Return dummy
   End Function

   ''' <summary>
   ''' sets the dummy control location
   ''' </summary>
   Private Sub SetDummyPosition(ByVal dummy As DummyControl, ByVal control As Control)
      Dim errloc As Point
      Dim left As Int32 = control.Location.X
      Dim right As Int32 = left + control.Width
      Dim top As Int32 = control.Location.Y
      Dim bottom As Int32 = top + control.Height
      Dim mid As Int32 = top + (control.Height \ 2)

      Dim align As ErrorIconAlignment = GetIconAlignment(control)
      Select Case align
         Case ErrorIconAlignment.BottomLeft
            errloc = New Point(left, bottom)
         Case ErrorIconAlignment.BottomRight
            errloc = New Point(right, bottom)

         Case ErrorIconAlignment.MiddleLeft
            errloc = New Point(left, mid)

         Case ErrorIconAlignment.MiddleRight
            errloc = New Point(right, mid)

         Case ErrorIconAlignment.TopLeft
            errloc = New Point(left, top)

         Case ErrorIconAlignment.TopRight
            errloc = New Point(right, top)

      End Select
      dummy.Location = control.FindForm.PointToClient(control.Parent.PointToScreen(errloc))
   End Sub

   Public Shadows Sub SetError(ByVal control As Control, ByVal text As String)
      Dim errcontrol As Control
      If NeedsDummy(control) Then
         errcontrol = GetDummy(control)
         SetDummyPosition(DirectCast(errcontrol, DummyControl), control)
      Else
         errcontrol = control
      End If

      MyBase.SetError(errcontrol, text)

   End Sub

   ''' <summary>
   ''' determine if control is parented directly to the form
   ''' </summary>
   Private Function NeedsDummy(ByVal control As Control) As Boolean
      Dim frm As Form = control.FindForm
      Return frm.Handle <> control.Parent.Handle
   End Function

#Region "Method Overrides"
   Public Shadows Sub SetIconAlignment(ByVal control As Control, ByVal alignment As ErrorIconAlignment)
      If NeedsDummy(control) Then
         Dim errcontrol As DummyControl = GetDummy(control)
         MyBase.SetIconAlignment(errcontrol, alignment)
         SetDummyPosition(errcontrol, control)
      Else
         MyBase.SetIconAlignment(control, alignment)
      End If
   End Sub
   Public Shadows Function GetError(ByVal Control As Control) As String
      Dim errcontrol As Control
      If NeedsDummy(Control) Then
         errcontrol = GetDummy(Control)
      Else
         errcontrol = Control
      End If
      Return MyBase.GetError(errcontrol)
   End Function

   Public Shadows Function GetIconAlignment(ByVal control As Control) As ErrorIconAlignment
      Dim errcontrol As Control
      If NeedsDummy(control) Then
         errcontrol = GetDummy(control)
      Else
         errcontrol = control
      End If
      Return MyBase.GetIconAlignment(errcontrol)
   End Function

   Public Shadows Function GetIconPadding(ByVal control As Control) As Int32
      Dim errcontrol As Control
      If NeedsDummy(control) Then
         errcontrol = GetDummy(control)
      Else
         errcontrol = control
      End If
      Return MyBase.GetIconPadding(errcontrol)
   End Function

   Public Shadows Sub SetIconPadding(ByVal control As Control, ByVal padding As Int32)
      Dim errcontrol As Control
      If NeedsDummy(control) Then
         errcontrol = GetDummy(control)
      Else
         errcontrol = control
      End If
      MyBase.SetIconPadding(errcontrol, padding)
   End Sub
#End Region

   ''' <summary>
   ''' A non-painting, zero sized control to post an Error against
   ''' </summary>
   Private Class DummyControl
      Inherits Control
      Public Sub New()
         Size = Size.Empty
         Visible = True
      End Sub
      Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
         'don't paint anything
      End Sub
   End Class
End Class

GeneralRe: Overlapping with a Picturebox other controls having the picturebox transparent background VB .NET (update) Pin
jose mandurrino24-Nov-13 8:52
jose mandurrino24-Nov-13 8:52 
Questionzoom a big image with VB Pin
99117651518-Nov-13 22:09
99117651518-Nov-13 22:09 
AnswerRe: zoom a big image with VB Pin
Eddy Vluggen19-Nov-13 10:37
professionalEddy Vluggen19-Nov-13 10:37 
QuestionRe: zoom a big image with VB Pin
99117651519-Nov-13 14:32
99117651519-Nov-13 14:32 
AnswerRe: zoom a big image with VB Pin
Eddy Vluggen20-Nov-13 7:53
professionalEddy Vluggen20-Nov-13 7:53 
AnswerRe: zoom a big image with VB Pin
Bernhard Hiller19-Nov-13 22:12
Bernhard Hiller19-Nov-13 22:12 
QuestionSystem.Null Pin
Member 1040919918-Nov-13 4:21
Member 1040919918-Nov-13 4:21 
AnswerRe: System.Null Pin
Richard Deeming18-Nov-13 4:44
mveRichard Deeming18-Nov-13 4:44 
QuestionHow can i avoid my vbscript running in temp folder when converted to exe using iexpress wizard Pin
superselector14-Nov-13 21:12
superselector14-Nov-13 21:12 
AnswerRe: How can i avoid my vbscript running in temp folder when converted to exe using iexpress wizard Pin
Mike Meinz16-Nov-13 3:09
Mike Meinz16-Nov-13 3:09 
GeneralRe: How can i avoid my vbscript running in temp folder when converted to exe using iexpress wizard Pin
Dave Kreskowiak16-Nov-13 3:18
mveDave Kreskowiak16-Nov-13 3:18 
GeneralRe: How can i avoid my vbscript running in temp folder when converted to exe using iexpress wizard Pin
Mycroft Holmes16-Nov-13 17:00
professionalMycroft Holmes16-Nov-13 17:00 
GeneralRe: How can i avoid my vbscript running in temp folder when converted to exe using iexpress wizard Pin
superselector21-Nov-13 21:09
superselector21-Nov-13 21:09 
GeneralRe: How can i avoid my vbscript running in temp folder when converted to exe using iexpress wizard Pin
Mike Meinz22-Nov-13 1:21
Mike Meinz22-Nov-13 1:21 
QuestionSorting Gridview with Data from DataTable error Pin
Commish1314-Nov-13 5:11
professionalCommish1314-Nov-13 5:11 
AnswerRe: Sorting Gridview with Data from DataTable error Pin
Richard MacCutchan14-Nov-13 6:13
mveRichard MacCutchan14-Nov-13 6:13 
GeneralRe: Sorting Gridview with Data from DataTable error Pin
Commish1314-Nov-13 7:07
professionalCommish1314-Nov-13 7:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.