We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

FLabel Part VI

LeeLiam
LeeLiam asked
on
Medium Priority
353 Views
Last Modified: 2012-05-06
This time I would like to indicate some columns are inactive in the stack of usercontrols. My thought was to simply use DrawLine to draw an X over the column. However, everything I have tried draws the X under the usercontrols instead of on top.

The only way I got it to draw on top was to use ControlPaint.DrawReversibleLine, but I need thicker lines and that is not changable.

I also tried adding pictureboxes and locating them over the columns, but they also appear under the usercontrols.

How can I place an indicator on top of the usercontrols?

Thanks.
Comment
Watch Question

Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009

Commented:
...this time I recommend you use the Paint() event again instead of trying to paint "over" them...  ;)

So you'll need to store the fact that some columns are inactive and then in the Paint() event draw an "x" over those spots.

Author

Commented:
I have a subroutine that determines the inactive columns and calls another subroutine that draws the X. The usercontrols are on a panel. I've tried calling the first subroutine from the Panel_Paint and from the Form_Paint and nothing appears. If I call it from the uc_MouseMove, the X appears under the user control.

It may be a problem with the way I'm using DrawLine. My code for that is shown below. Should I modify it?

Thanks.
    Private Sub MyDrawLine(ByVal p1 As Point, ByVal p2 As Point)
        p1 = Me.PointToScreen(p1)
        p2 = Me.PointToScreen(p2)
        Dim g As Graphics = Graphics.FromHwnd(Panel.Handle)
        Dim myPen As Pen = New Pen(Color.Red, 6)
        g.DrawLine(myPen, p1, p2)
    End Sub

Open in new window

Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009

Commented:
"Graphics.FromHwnd" is a TEMPORARY graphics and will be erased whenever the control "underneath" is refreshed...an event that you have no control over.  This is why I suggested you draw the inactive columns "x"s in the Paint() event to make them persistent.

Author

Commented:
I'm assuming I do that with DrawLine. If so, I don't know how to Dim g as Graphics.

Can you help me with that?

Thanks.
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009
Commented:
You wouldn't manually "Dim" any graphics at all...

Use the Graphics supplied in the PAINT() Event via the "e" parameter:

   ' in the Paint() Event
   e.Graphics.DrawLine(...)

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
No joy.

I tried the e.Graphics.Drawline in the Panel_Paint event. It is still drawing the X's under the usercontrols. If I only had a ZOrder and could bring them to the top.

I tried forcing it to paint the usercontrols first, then the X's but they still come out underneath.

Any other ideas?

Thanks.
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009

Commented:
Right...use the Paint() Event for the USERCONTROLs to draw your X's...so each UserControl will draw its own inactive columns.

Author

Commented:
I have 16 usercontrols stacked in the panel. Each control has a series of numbers like 123 234 567 432 321, etc. Three digits seperated by spaces. So, the column is three digits wide and 16 rows (each row being a usercontrol) tall. When a column is inactive, I want something to cover the column. It could be an large elongated X or a rectangle or something to block out the column.

When I try to use drawline from the uc_Paint event, the screen flickers for a second, and nothing appears.

I have also tried ControlPaint.FillReversibleRectangle(rc, Color.DarkGray) to cover the columns. That works at first, but then they disappear at strange moments.

Any ideas?

Thanks.
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009

Commented:
Not sure...I'd have to see more of your new code to figure out where the problem is...

Author

Commented:
It hard to take a piece of code out of the larger project.

Perhaps a picture will show what I need. In the attachment, the gray filled rectangle indicates the inactive column. This is where I was trying to cover with a large X, but this rectangle will suffice.

The dark blue rectangle indicates the active column and moves with the mouse.

The dark blue rectangle is working well. The gray rectangle appears with the form opens, but at some point they disappear.

Does this make any sense?

Thanks.
column.jpg
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.