VS 2015 [RESOLVED] How can I send a groupbox to back of an another control?-VBForums
Results 1 to 4 of 4

Thread: [RESOLVED] How can I send a groupbox to back of an another control?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2014
    Posts
    263

    Resolved [RESOLVED] How can I send a groupbox to back of an another control?

    How can I send a groupbox to back of an another control using if condition like below:

    Code:
    Private Sub btnMoreDetails_Click(sender As Object, e As EventArgs) Handles btnMoreDetails.Click
            If grpMoreDetails.SendToBack() Then
                grpMoreDetails.BringToFront()
            Else
                grpMoreDetails.SendToBack()
            End If
        End Sub
    I am getting the following error:
    Expression does not produce a value

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    39,581

    Re: How can I send a groupbox to back of an another control?

    .SendToBack doesn't return a value, so you can't use it in an If statement.

    I don't think there is any way to check if something is at the front or back, so the best option is likely to be using a module-level variable to remember the state, or even a Static variable instead (which is basically a module-level variable, but can only be used inside the sub), eg:
    Code:
    Private Sub btnMoreDetails_Click(sender As Object, e As EventArgs) Handles btnMoreDetails.Click
            Static isAtBack as Boolean = True
            If isAtBack Then
                grpMoreDetails.BringToFront()
            Else
                grpMoreDetails.SendToBack()
            End If
            isAtBack = Not isAtBack
        End Sub
    If the first click has no effect (but it works fine after that), simply change =True to =False

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2014
    Posts
    263

    Re: How can I send a groupbox to back of an another control?

    Thanks for your kind support.

  4. #4
    Hyperactive Member
    Join Date
    Sep 2017
    Posts
    305

    Re: [RESOLVED] How can I send a groupbox to back of an another control?

    Code:
            If Me.Controls.GetChildIndex(YourControl) = 0 Then
                Me.Controls.SetChildIndex(YourControl, 1)
            End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width