Solved

VB.net when groupbox is visible, everything in the back darkens

Posted on 2012-03-14
17
629 Views
Last Modified: 2012-06-27
Hi Experts,

I have a form in VB.net

when i click the button, a hidden groupbox in the middle of the screen turns visible (with a new menu inside, sort of like a popup.


I need to dim everything in the background out and make it a few shades darker.

i was thinking I make a giant black opaque picturebox in the background

cannot find how to do this
I found some things but don't know how to put them together


Thanks in advance
0
Comment
Question by:Ess Kay
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
  • 2
  • +1
17 Comments
 
LVL 38

Expert Comment

by:Tom Beck
ID: 37721856
This is for a Windows form?
0
 
LVL 15

Author Comment

by:Ess Kay
ID: 37721880
Yes.


An example of what i want it to do is images from google search when you click one the screen is dark, cannot click behind the picture but can still see

example
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37721976
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 15

Author Comment

by:Ess Kay
ID: 37722047
I don't need the form's opacity to change

what does this have to do with anything


And no, the picture box does not have an opacity function


i need it to look something like this

dark bg no click
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37722094
That CSS at work which does not exist in winforms.
0
 
LVL 15

Author Comment

by:Ess Kay
ID: 37722117
obviously, but when there is a will, there is a way. I want something like that on my windows form.


this is close to what I am looking for but I need the actual code, and for it to be in VB.net
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_CPP/Q_21874286.html
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 37722346
The Opacity() approach can work.  First disable the real form.  Next, display a Borderless Form over the main form and set its Opacity to your liking.  Finally, display a third small Form with the GroupBox over the other two.
0
 
LVL 15

Author Comment

by:Ess Kay
ID: 37722360
Interesting concept. how would I go about layering the second and third form
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 37722612
Just position them right over each other.  You'll probably need to fiddle with each Forms ShowInTaskBar() property so they appear (or don't appear) to have entries in the TaskBar.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 37722614
*I mean explicitly set their Location() properties based off each other.  Set the FormStartPosition() to "Manual".
0
 
LVL 15

Author Comment

by:Ess Kay
ID: 37724735
But if you alt-tab you will be able to cycle through them. or if you click the form on the start menu the others will go to the back

sounds impractical
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 37724753
There are other house-keeping techniques you can do to prevent that.  Yes...it's a pain in the butt.

If you want it all in ONE form then take a screenshot of the form and use the Drawing classes to make it look "dimmed".  Now put that in image in a temp Panel control that is placed over everything on the form.  Finally, add the GroupBox to that Panel.
0
 
LVL 15

Author Comment

by:Ess Kay
ID: 37724805
the form is dynamic, options change on it
so screenshot wont work



looks like this, but ill change the (look) of it later


 frm
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 37725006
"the form is dynamic, options change on it, so screenshot wont work"

You can take a screen shot via code right before you need to dim it.
0
 
LVL 15

Author Comment

by:Ess Kay
ID: 37725069
hows that work
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 37725201
Try something like this:
Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim RC As Rectangle = Me.RectangleToScreen(Me.ClientRectangle)
        Dim bmp As New Bitmap(RC.Width, RC.Height)
        Using G As Graphics = Graphics.FromImage(bmp)
            G.CopyFromScreen(RC.Location, New Point(0, 0), RC.Size)
            Using brsh As New SolidBrush(Color.FromArgb(128, Color.Gray))
                G.FillRectangle(brsh, Me.ClientRectangle)
            End Using
        End Using

        Dim pnl As New Panel
        pnl.Size = RC.Size
        pnl.Location = New Point(0, 0)
        pnl.BackgroundImage = bmp
        Me.Controls.Add(pnl)
        pnl.BringToFront()

        Dim gb As New GroupBox
        gb.Text = "Hello World!"
        gb.Size = New Size(Me.ClientRectangle.Width / 2, Me.ClientRectangle.Height / 2)
        gb.Location = New Point(Me.ClientRectangle.Width / 4, Me.ClientRectangle.Height / 4)
        pnl.Controls.Add(gb)

        Dim btn As New Button
        btn.Text = "OK"
        btn.Tag = pnl
        btn.Location = New Point(gb.Width - btn.Width - btn.Margin.Right, gb.Height - btn.Height - btn.Margin.Bottom)
        AddHandler btn.Click, AddressOf btn_Click
        gb.Controls.Add(btn)

        Me.ControlBox = False
        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedSingle
    End Sub

    Private Sub btn_Click(sender As System.Object, e As System.EventArgs)
        Dim btn As Button = DirectCast(sender, Button)
        DirectCast(btn.Tag, Panel).Dispose()
        Me.ControlBox = True
        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
    End Sub

End Class

Open in new window

0
 
LVL 15

Author Closing Comment

by:Ess Kay
ID: 37725272
Exactly what I was looking for thanks
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question