Solved

How to set a UserControl's ZOrder in design mode

Posted on 2004-09-23
12
2,032 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

707 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

15 Experts available now in Live!

Get 1:1 Help Now