|
-
Jan 26th, 2010, 05:47 PM
#1
Thread Starter
PowerPoster
[RESOLVED] [VB6] - catch the container scalemode value
has you know, the control can be puted in a container(form\picturebox). i have these code, but only give me the form and not the container
Code:
Public Function ContainerScaleMode() As Integer
ContainerScaleMode = UserControl.ParentControls(0).ScaleMode
End Function
can anyone help me?
thanks
-
Jan 27th, 2010, 08:28 AM
#2
Re: [VB6] - catch the container scalemode value
You might be able to loop thru the controls and compare hWnds
Code:
On Error Resume Next
For I = 0 to UserControl.ParentControls.Count-1
If UserControl.ParentControls(I).hWnd = UserControl.ContainerHwnd Then
' found it
Exit For
End If
Next
On Error Goto 0
Edited: I believe code like this has too much room for failure. What if the user changes your control's container during runtime? What if the user changes the container's ScaleMode during runtime? What if your control is in a frame, frames have no ScaleMode property. If your code must rely on the container's scalemode, force the user to supply either the container or the container's scalemode as a property. That way if it fails to work, it is because of incorrect property settings, not your control. And your control does not need to try to overcome the problem with flawed hacks.
Last but not least. Except for passing event parameters in user scalemode (use ScaleX,ScaleY with vbContainerPosition & vbContainerSize), you can simply use pixels for form-related positions/sizes. Most controls have hWnds, APIs can get & set a control's position and size very easily.
Try this experiment.
1. Create a new usercontrol. Set its backcolor to black so it is easy to see
2. Add this code in its click event:
Code:
Debug.Print "2010 = "; CLng(ScaleX(2010, vbPixels, vbContainerPosition)); " in container's scalemode"
Debug.Print "2010 = "; CLng(ScaleX(2010, vbPixels, vbContainerSize)); " in container's scalemode"
3. Add a picturebox to your form, then put usercontrol in the picturebox.
4. Set picturebox scalemode to twips & run project and click on usercontrol
5. Set picturebox scalemode to pixels & run project and click on usercontrol
Use vbContainerPosition when you are converting coordinates. Use vbContainerSize for dimensions. I have not seen a situation where using the wrong one returns the wrong values. However, since VB provided two options, best to use the right one for the job.
Last edited by LaVolpe; Jan 27th, 2010 at 01:04 PM.
-
Jan 27th, 2010, 01:50 PM
#3
Thread Starter
PowerPoster
Re: [VB6] - catch the container scalemode value
 Originally Posted by LaVolpe
You might be able to loop thru the controls and compare hWnds
Code:
On Error Resume Next
For I = 0 to UserControl.ParentControls.Count-1
If UserControl.ParentControls(I).hWnd = UserControl.ContainerHwnd Then
' found it
Exit For
End If
Next
On Error Goto 0
Edited: I believe code like this has too much room for failure. What if the user changes your control's container during runtime? What if the user changes the container's ScaleMode during runtime? What if your control is in a frame, frames have no ScaleMode property. If your code must rely on the container's scalemode, force the user to supply either the container or the container's scalemode as a property. That way if it fails to work, it is because of incorrect property settings, not your control. And your control does not need to try to overcome the problem with flawed hacks.
Last but not least. Except for passing event parameters in user scalemode (use ScaleX,ScaleY with vbContainerPosition & vbContainerSize), you can simply use pixels for form-related positions/sizes. Most controls have hWnds, APIs can get & set a control's position and size very easily.
Try this experiment.
1. Create a new usercontrol. Set its backcolor to black so it is easy to see
2. Add this code in its click event:
Code:
Debug.Print "2010 = "; CLng(ScaleX(2010, vbPixels, vbContainerPosition)); " in container's scalemode"
Debug.Print "2010 = "; CLng(ScaleX(2010, vbPixels, vbContainerSize)); " in container's scalemode"
3. Add a picturebox to your form, then put usercontrol in the picturebox.
4. Set picturebox scalemode to twips & run project and click on usercontrol
5. Set picturebox scalemode to pixels & run project and click on usercontrol
Use vbContainerPosition when you are converting coordinates. Use vbContainerSize for dimensions. I have not seen a situation where using the wrong one returns the wrong values. However, since VB provided two options, best to use the right one for the job.
i found the solution more faster and easy:
[CODE]Public Function ContainerScaleMode() As Integer
ContainerScaleMode = Extender.Container.ScaleMode
End Function[/CODE
but i need ask 2 things:
1 - after compiler the Extender object can give errors in other project?
2 - why the method "Container" isn't showed(when you write "Extender.")?
thanks
-
Jan 27th, 2010, 02:07 PM
#4
Re: [VB6] - catch the container scalemode value
 Originally Posted by joaquim
i found the solution more faster and easy:
Code:
Public Function ContainerScaleMode() As Integer
ContainerScaleMode = Extender.Container.ScaleMode
End Function
but i need ask 2 things:
1 - after compiler the Extender object can give errors in other project?
2 - why the method "Container" isn't showed(when you write "Extender.")?
thanks
Hmmm
Yes potential problems. You are assuming that all Extender objects expose a Container property and that all Container properties have ScaleModes; they may not. Again a VB Frame does not have a ScaleMode property. What if your control was inside some custom usercontrol?
Recommend doing this correctly. Use ScaleX,ScaleY with the vbContainerPosition or vbContainerSize constants. If you do, you will not get those potential errors and you will not need to know the container's scalemode. Your choice of course.
-
Jan 27th, 2010, 04:25 PM
#5
Thread Starter
PowerPoster
Re: [VB6] - catch the container scalemode value
 Originally Posted by LaVolpe
Hmmm
Yes potential problems. You are assuming that all Extender objects expose a Container property and that all Container properties have ScaleModes; they may not. Again a VB Frame does not have a ScaleMode property. What if your control was inside some custom usercontrol?
Recommend doing this correctly. Use ScaleX,ScaleY with the vbContainerPosition or vbContainerSize constants. If you do, you will not get those potential errors and you will not need to know the container's scalemode. Your choice of course.
if the extender can give me errors, then how can i change these:
Code:
lngOldPosX = Extender.Left
lngOldPosY = Extender.Top
?
then i only need convert pixels to right scalemode in container.
Code:
L1 = Extender.Left + LimColLeft
T1 = Extender.Top + LimColTop
W1 = LimColWidth
H1 = LimColHeight
i only need convert pixels to container scalemode(the limcol values).
thanks
-
Jan 27th, 2010, 04:44 PM
#6
Re: [VB6] - catch the container scalemode value
Does your usercontrol have an hWnd?
If so....
Code:
Dim uRect As RECT, tPT as POINTAPI
GetWindowRect UserControl.hWnd, uRect
tPT.X = uRect.Left: tPT.Y = uRect.Top
ScreenToClient UserControl.ContainerHwnd, tPT
' now tPT has the top/left coords of your usercontrol relative to the container
-
Jan 27th, 2010, 05:11 PM
#7
Thread Starter
PowerPoster
Re: [VB6] - catch the container scalemode value
 Originally Posted by LaVolpe
Does your usercontrol have an hWnd?
If so....
Code:
Dim uRect As RECT, tPT as POINTAPI
GetWindowRect UserControl.hWnd, uRect
tPT.X = uRect.Left: tPT.Y = uRect.Top
ScreenToClient UserControl.ContainerHwnd, tPT
' now tPT has the top/left coords of your usercontrol relative to the container
thanks
-
Jan 27th, 2010, 05:17 PM
#8
Thread Starter
PowerPoster
Re: [VB6] - catch the container scalemode value
for convert the position:
Code:
Left=CLng(ScaleX(leftvalue, vbPixels, vbContainerPosition))
top=CLng(ScaleY(topvalue, vbPixels, vbContainerPosition))
and convert the size:
Code:
width= CLng(ScaleX(widthvalue, vbPixels, vbContainerSize))
height=CLng(Scaley(heightvalue, vbPixels, vbContainerSize))
tell me if the isn't right.
thanks for help me
-
Jan 27th, 2010, 06:52 PM
#9
Re: [VB6] - catch the container scalemode value
I think you have it. But for the size of your usercontrol (for example), your widthValue & widthHeight are usercontrol.Width/Height and scalemode is always Twips.
Code:
width= CLng(ScaleX(UserControl.Width, vbTwips, vbContainerSize))
height=CLng(ScaleY(UserControl.Height, vbTwips, vbContainerSize))
Last edited by LaVolpe; Jan 27th, 2010 at 07:50 PM.
-
Jan 28th, 2010, 06:13 PM
#10
Thread Starter
PowerPoster
Re: [VB6] - catch the container scalemode value
 Originally Posted by LaVolpe
I think you have it. But for the size of your usercontrol (for example), your widthValue & widthHeight are usercontrol.Width/Height and scalemode is always Twips.
Code:
width= CLng(ScaleX(UserControl.Width, vbTwips, vbContainerSize))
height=CLng(ScaleY(UserControl.Height, vbTwips, vbContainerSize))
sorry, but in these case i use, in my UC, everything, is in pixels.
thanks for everything.
PS: sorry, but i can't rate you, because i don't have "points" for use it .
-
Jan 28th, 2010, 07:16 PM
#11
Re: [RESOLVED] [VB6] - catch the container scalemode value
You didn't understand that example.
1. UserControl's Width & Height is always in Twips as is a VB form's Width & Height
:: the uc's ScaleWidth & ScaleHeight may be in pixels but not the Width & Height
2. The 2nd parameter in ScaleX & ScaleY is the scalemode you are converting from
3. The 3rd parameter in ScaleX & ScaleY is the scalemode you are converting to
-
Jan 29th, 2010, 03:14 PM
#12
Thread Starter
PowerPoster
Re: [RESOLVED] [VB6] - catch the container scalemode value
 Originally Posted by LaVolpe
You didn't understand that example.
1. UserControl's Width & Height is always in Twips as is a VB form's Width & Height
:: the uc's ScaleWidth & ScaleHeight may be in pixels but not the Width & Height
2. The 2nd parameter in ScaleX & ScaleY is the scalemode you are converting from
3. The 3rd parameter in ScaleX & ScaleY is the scalemode you are converting to
sorry, but in these case is in pixels:
Code:
L1 = Extender.Left + LimColLeft
T1 = Extender.Top + LimColTop
W1 = LimColWidth
H1 = LimColHeight
the limcol variables are in pixels. thats why that i need convert them to scalemode values.
thanks
-
Feb 4th, 2010, 04:30 PM
#13
Thread Starter
PowerPoster
Re: [RESOLVED] [VB6] - catch the container scalemode value
for finish i forgot to ask 1 thing.
if i can't use extender.name(for do a test), then how can i see the sprite2d name?
-
Feb 11th, 2010, 10:00 PM
#14
Re: [RESOLVED] [VB6] - catch the container scalemode value
Try: Ambient.DisplayName
Double check that. I'm not on a pc with VB6 and just going from memory.
-
Feb 12th, 2010, 05:23 AM
#15
Thread Starter
PowerPoster
Re: [RESOLVED] [VB6] - catch the container scalemode value
 Originally Posted by LaVolpe
Try: Ambient.DisplayName
Double check that. I'm not on a pc with VB6 and just going from memory.
yes.. works... thanks
-
Feb 22nd, 2010, 05:51 PM
#16
Lively Member
Last edited by NeedHelp!; Feb 25th, 2010 at 07:22 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|