Solved

How to set a UserControl's ZOrder in design mode

Posted on 2004-09-23
12
2,036 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
  • 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 85

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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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 85

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 85

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

813 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now