Results 1 to 40 of 4199

Thread: CommonControls (Replacement of the MS common controls)

Threaded View

  1. #11
    Member
    Join Date
    Oct 2007
    Posts
    52

    Re: CommonControls (Replacement of the MS common controls)

    Hi Krool,

    Thanks! I am sorry for late response and I see you issued an update. Okay, first things first. In testing again today, I see that I made a stupid mistake when I was previously testing. I was actually feeding the sub swapped right and top values. So my assertion before that it was "wildly off" wasn't quite right - it was "wildly off" because I was stupid. lol

    However, the old code still was not correct. My replacement code above also was not correct - the .Right calculations in my code was wrong.

    Your new code is better, but I think there is still a mistake in the .Right and .Bottom. I believe you should be subtracting the PhysOffsetCX and PhysOffsetCY instead of adding them.

    In other words it should now be:

    Code:
        .Left = LeftMargin - PhysOffsetCX
        .Top = TopMargin - PhysOffsetCY
        .Right = (PhysCX - RightMargin) - PhysOffsetCX
        .Bottom = (PhysCY - BottomMargin) - PhysOffsetCY
    This is basically the way my old code that I've used for years was doing it.

    Note however that this code does not take into account either if the margins are less than the offsets or if the margins are not specified. I've seen printers that have .5 inch offsets (or a little less but you get the idea). This code would fail on that if they specified a margin say of .30 inches because it would give a negative number. That is why I did the If/Then's. It's not pretty, but it solves this problem. I also think you should not be setting the default values to 0. If margins aren't specified (they are optional in PrintDoc) then it's almost guaranteed not to be right. Taking everything together, I believe something like the following is probably best:

    Code:
        With .RC
        If (LeftMargin - PhysOffsetCX) > 0 Then 
             .Left = LeftMargin - PhysOffsetCX
        Else
             .Left = PhysOffsetCX
        End If
        If (TopMargin - PhysOffsetCY) > 0 Then 
             .Top = TopMargin - PhysOffsetCY
        Else
             .Top = PhysOffsetCY
        End If
        If (RightMargin - PhysOffsetCX) > 0 Then 
             .Right = (PhysCX - RightMargin) - PhysOffsetCX
        Else
             .Right = PhysCX - PhysOffsetCX
        End If
        If (BottomMargin - PhysOffsetCY) > 0 Then 
             .Bottom = (PhysCY - BottomMargin) - PhysOffsetCY
        Else
             .Bottom = PhysCY - PhysOffsetCY
        End If
        End With
    This only sets based on the margins if the margins that were set are greater than the offsets, otherwise or if no margins were set at all, will set a default.

    Thanks again for all your work with all of these!! I appreciate you! This stuff gets complicated and I think there was some wrong MS documentation/examples on this margin stuff too.

    [Edit: Updated to fix a silly mistake in my code where I originally was setting default values for RCPage and not RC]
    Last edited by chrislong2; Sep 6th, 2021 at 10:07 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width