Solved

How to set a UserControl's ZOrder in design mode

Posted on 2004-09-23
12
2,043 Views
Last Modified: 2013-12-26
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
Comment
Question by:const71
[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
  • 3
  • 3
  • 2
  • +3
12 Comments
 
LVL 5

Expert Comment

by:JMoon5FTM
ID: 12155038
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
 
LVL 7

Expert Comment

by:DrewK
ID: 12159896
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12160962
>> 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 7

Expert Comment

by:DrewK
ID: 12160991
I stand corrected.

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

Sorry for the confusion!

~DrewK
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12161057
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
 
LVL 7

Expert Comment

by:DrewK
ID: 12161476
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12161649
>> 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
 

Author Comment

by:const71
ID: 12166276
unfortunately, that doesnt work
0
 

Author Comment

by:const71
ID: 12166283
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
 
LVL 2

Accepted Solution

by:
jtbalogh earned 500 total points
ID: 12219154
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
 
LVL 1

Expert Comment

by:Allpax
ID: 12468457
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
 
LVL 2

Expert Comment

by:jtbalogh
ID: 12468560
>> (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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month9 days, 9 hours left to enroll

624 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