Print Page | Close Window

UserControls and CommandBars

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=1177
Printed Date: 12 December 2024 at 2:36am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: UserControls and CommandBars
Posted By: Geraint P
Subject: UserControls and CommandBars
Date Posted: 15 September 2004 at 8:29am

This is a similar issue to that raised below ("Problem With ActiveX"). I've taken account of the advice there and the MoveAlignedControl method certain helped me with a lot of my problems! A further issue I have is this though.

Our control implements a splitter bar to allow the control to be resized (basically it's a simple MDIpane control). To draw the splitter bar it needs to calculate the X and Y offset. We use the UserControl.Extender.Left & UserControl.Extender.Top properties to obtain the offset and call ClientToScreen (with the parent hWnd) to convert these pixel coordinates into screen coords.

Trouble is this doesn't work with a CommandBar present - it doesn't seem to take into account any toolbars that happen to exist above or to the left of our control. Do you have a recommended method of calculating the appropriate coordinates within a usercontrol in these circumstances?

I hope that makes sense.

 

 




Replies:
Posted By: SuperMario
Date Posted: 15 September 2004 at 8:43am
GetClientRect will return the top, left, bottom, and right coordinates of the client area.  


Posted By: Geraint P
Date Posted: 15 September 2004 at 9:32am

In typical fashion I managed to find a workaround after posting this, with a combination of ClientToScreen and ScreenToClient. Because our control won't necessarily be working with  CommandBars present it had to be able to work out the coords without using a call to CommandBars itself.

Really I only seem to have one further problem; the user control can't seem to resize itself. The line UserControl.Width = <new width> within our user control doesn't seem to have any effect at all with a CommandBars present. Any ideas? This seems to have something to do with it's interaction with the MoveAlignedControl method.



Posted By: Geraint P
Date Posted: 15 September 2004 at 10:21am

After looking at this a bit further I can probably simplify what I'm asking now.

If I have a picturebox aligned to the left of a MDIForm with a width of say, 2000 twips. I use MoveAlignedControls within the CommandBars_RepositionAlignedControls event. If I have a button which increases the width of the picturebox to 4000 twips, then nothing happens - the width stays the same. Is this expected behaviour?



Posted By: SuperMario
Date Posted: 15 September 2004 at 10:43am
change the width of the picturebox in the movealignedcontrol method just before it is moved.  Also make sure that the commanbars is using the same scale (twips\pixels) as your MDIform.


Posted By: Geraint P
Date Posted: 15 September 2004 at 10:59am

Sorry, but I'm not sure I understand exactly where I should be changing the width. Currently I use MoveAlignedControl as you've suggested in other threads. i.e.

Private Sub CommandBars_RepositionAlignedControls(Left As Long, Top As Long, Right As Long, Bottom As Long)
    CommandBars.MoveAlignedControl Picture1, Left, Top, Right, Bottom
End Sub

At the moment, no matter where picture1.width is changed, it doesn't seem to affect the control. Am I missing something obvious?

 



Posted By: SuperMario
Date Posted: 15 September 2004 at 11:28am
Try something like this assuming your picturebox is on the right side of the MDIForm:

    Dim NewWidth as Long  
    NewWidth = Right - SliderValue
    CommandBars1.MoveAlignedControl Picture1, NewWidth, Top, Right, Bottom


Posted By: Geraint P
Date Posted: 16 September 2004 at 5:06am

Nope - no luck at all. I'm finding the MoveAlignedControl method very confusing to be honest. For example, the Right property is described as "The space between the right side of the control and the right side of the container of the control.". Assuming I have a picturebox aligned to the right of the MDIForm, then you'd assume that this should be zero, which it patently isn't in the example above (in RepositionAlignedControls).

MoveAlignedControl seems to be doing this - send me the current client area and I'll reposition your aligned control with that and return you the new client area. It moves the control, but can't seem to resize it. Which is fair enough, except of course I can't resize the control any other way either.

I'll be uploading a simple example of this a bit later. I'd be grateful if you could take a quick look and see if there's a definite solution. Ta.



Posted By: Geraint P
Date Posted: 16 September 2004 at 5:50am

Here's the uploaded project. VERY simple as you'll see. I'll keep plugging away...

https://forum.codejock.com/uploads/GeraintP/2004-09-16_055029_Project1.zip - 2004-09-16_055029_Project1.zip



Posted By: SuperMario
Date Posted: 16 September 2004 at 8:29am
Take a look at this:

uploads/SuperMario/2004-09-16_082934_Project1.zip - 2004-09-16_082934_Project1.zip


Posted By: Geraint P
Date Posted: 16 September 2004 at 9:13am

That's looking better. Added some similar code to our real app now and the usercontrol can indeed resize itself now (as long as we call RecalcLayout afterwards and then use the usercontrol width to adjust the left/right properties of MoveAlignedControl).

Thank for all the help so far. Although you may not have seen the last of me.




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net