Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2071
  • Last Modified:

How to set a UserControl's ZOrder in design mode

Hi, this code works fine during runtime of my UserObject ...

Private Sub UserControl_EnterFocus()
    Call UserControl.Extender.ZOrder(vbBringToFront)
    TitleColor = vbActiveTitleBar
End Sub

however during design-time it has no efect. The ZOrder doesnt seem to do anything.
Is there a way to fix this?
0
const71
Asked:
const71
  • 3
  • 3
  • 2
  • +3
1 Solution
 
JMoon5FTMCommented:
Is your control windowless?  If yes...dunno.  If not, try this:

Private Declare Function SetWindowPos lib "user32" (byval hWnd as Long, byval ZPos as Long, byval X as Long, byval Y as Long, byval Width as Long, byval Height as Long, byval Flags as Long) as Long
Private Const HWND_TOP = 0
Private Const SWP_NOSIZE = 1
Private Const SWP_NOMOVE = 2

Private Sub UserControl_EnterFocus
    Call SetWindowPos(UserControl.hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE)
    TitleColor = vbActiveTitleBar
End Sub
0
 
DrewKCommented:
I'm not sure I understand.

Code is not run at "design-time".

Therefore, you don't have any events occur until you enter "run-time"

Does that help?

0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
>> Code is not run at "design-time".

Actually, for a UserControl it is.  Since a UserControl has a visual component during design-time (when you place the control on a form for instance), it will receive events such as Resize and Paint while in the IDE so it will properly display in the IDE.  Below is simple example of a control that draws an ellipse inside itself.  The ellipse will update IN THE IDE as the control is resized.

    Public Class UserControl1
        Inherits System.Windows.Forms.UserControl

        Private Sub UserControl1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
            Me.Invalidate()
        End Sub

        Private Sub UserControl1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
            Dim g As Graphics = e.Graphics
            g.DrawEllipse(Pens.Red, New Rectangle(New Point(0, 0), Me.Size))
        End Sub

    End Class
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
DrewKCommented:
I stand corrected.

This must be a .NET thing (I'm not as familiar with .NET)

Sorry for the confusion!

~DrewK
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Well, the example I gave was in .Net, but the same is true for VB6 controls:

    Private Sub UserControl_Paint()
        UserControl.Circle (UserControl.Width / 2, UserControl.Height / 2), UserControl.Width / 2, vbRed
    End Sub

~IM
0
 
DrewKCommented:
IM~

So you're saying that the UserControl_Paint sub ()that you provide above) will run in the IDE in VB 6.0?

What event triggers it?

Thanks,

DrewK
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
>> So you're saying that the UserControl_Paint sub ()that you provide above) will run in the IDE in VB 6.0?

Exactly.

>> What event triggers it?

The IDE uses the Paint() event to paint the control in the IDE.

Try this out...

Create a New "ActiveX Control" project and paste the UserControl_Paint() sub into it.
Compile the OCX using File --> Make Project1.ocx.

Create a New "Standard EXE" project.
Click on Project --> Components, then the "Browse" button and select your OCX.
Click "OK".
Your control will now be in the Toolbox.
Select it and make one of your controls on the form.
Now resize the control.

~IM
0
 
const71Author Commented:
unfortunately, that doesnt work
0
 
const71Author Commented:
I just noticed theres a "bring to front" option when you right click on the user object.  Perhaps this means that doing this in any other way is impossible?
0
 
jtbaloghCommented:
ZOrder() and SetWindowPos() work for controls at runtime and are ignored by controls at design time. If the form is still in design mode and not running, then no objects on the form will respond to zorder programmatically. Has nothing to do with the usercontrol running or not. Alternatively, the zorder works for controls inside the usercontrol since the usercontrol is at runtime regardless if the form is in design mode or running. Hope that helps.
0
 
AllpaxCommented:
jtbalogh is wrong.  I have an activex control, and I can set all ZOrder properties at design-time.  All changes to the ZOrder made at design time show up at design time on my activex control.  The problem is if you want these changes to show up at runtime, then you have to save and load the property in the propertybags.
0
 
jtbaloghCommented:
>> (Allpax)
>> ... I can set all ZOrder properties at design-time ... on my activex control

Hi. Initially we were talking about one ZOrder property of the usercontrol itself on the parent form. I am not sure what you mean by all ZOrder properties. Do you mean ZOrder for all controls inside an activex control?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now