Visio Guy

Visio Discussions => Programming & Code => Topic started by: perry59 on November 02, 2022, 06:49:41 PM

Title: need help from Nikolay on his addin (or someone else who is smarter than me)
Post by: perry59 on November 02, 2022, 06:49:41 PM
I  am having an issue with the anchor panel. Typically I can click a button on my ribbon to show or hide it.
Right now when I click the button the panel shows, but it's just a little sliver at the right side of the visio window which I must carefully grab with the mouse curser to pull it out to a usable size. As soon as I click outside the panel, in the main window, the panel goes back to being a small sliver. It looks like the code gives it an initial size but visio is squishing it. Is there something I can do in code to prevent this from happening or is this some visio setting I am unaware of?
Thanks
Title: Re: need help from Nikolay on his addin (or someone else who is smarter than me)
Post by: Surrogate on November 02, 2022, 07:04:14 PM
Hi, perry59!

Which addin do you mean?
Title: Re: need help from Nikolay on his addin (or someone else who is smarter than me)
Post by: Nikolay on November 02, 2022, 07:28:07 PM
Could you be more specific :)
I mean, some screenshot may and which add-in do you mean?
Title: Re: need help from Nikolay on his addin (or someone else who is smarter than me)
Post by: perry59 on November 02, 2022, 07:50:54 PM
A picture is worth a dozen words, hope this helps :)
Title: Re: need help from Nikolay on his addin (or someone else who is smarter than me)
Post by: Nikolay on November 02, 2022, 08:30:25 PM
As far as I unnerstand, you are using this project template, right?
https://marketplace.visualstudio.com/items?itemName=NikolayBelyh.ExtendedVisioAddinProject2017

If so, the default panel width is set in the "PanelFrame" file, here:

        public Window CreateWindow(Window visioParentWindow)
        {
            Window retVal = null;

            try
            {
                if (visioParentWindow == null)
                    return null;

                if (_form != null)
                {
                    _visioWindow = visioParentWindow.Windows.Add(
                        _form.Text,
                        (int)VisWindowStates.visWSDockedRight | (int)VisWindowStates.visWSAnchorMerged | (int)VisWindowStates.visWSVisible,
                        VisWinTypes.visAnchorBarAddon,
                        0,
                        0,
                        300, // <<<<<<<<<<<<<<< default panel width
                        300,
                        AddonWindowMergeId,
                        string.Empty,
                        0);


Title: Re: need help from Nikolay on his addin (or someone else who is smarter than me)
Post by: perry59 on November 02, 2022, 09:14:07 PM
yes, that's it, only difference is I'm using the VB version, but it still has 300.
although the panel is still squished to the smallest possible width until I manually stretch it out
Title: Re: need help from Nikolay on his addin (or someone else who is smarter than me)
Post by: perry59 on November 02, 2022, 09:15:29 PM
Oh, and to answer questions, it is my own addin using Nikolay's addin template (vb version)
Title: Re: need help from Nikolay on his addin (or someone else who is smarter than me)
Post by: Nikolay on November 03, 2022, 07:47:43 AM
So did changing this "300" to something else work?
It should be the same in VB version:

    Public Function CreateWindow(visioParentWindow As Window) As Window
        Dim retVal As Window = Nothing
        Try
            If visioParentWindow Is Nothing Then
                Return Nothing
            End If
            If _form IsNot Nothing Then
                _visioWindow = visioParentWindow.Windows.Add(_form.Text,
                        CInt(VisWindowStates.visWSDockedRight) Or CInt(VisWindowStates.visWSAnchorMerged) Or CInt(VisWindowStates.visWSVisible),
                        VisWinTypes.visAnchorBarAddon,
                        0,
                        0,
                       300,
                       300,
                       AddonWindowMergeId, String.Empty, 0)
Title: Re: need help from Nikolay on his addin (or someone else who is smarter than me)
Post by: perry59 on November 03, 2022, 04:30:45 PM
I never changed it from the default "300" as that worked fine in the past. I will try and see what happens but I don't expect any change.
I don't know why that now the panel shrinks to it's smallest possible width when it opens. I'm thinking it's a visio thing and not an issue with your addin code.So I am looking for a way to "force" it open regardless of what visio wants.

EDIT:
in fact I'm sure it's a visio issue because I just ran this on my laptop and it works as expected. There is something about the visio installation on my work computer that is causing this, I just don't know what it is yet. Something in visio settings? something in the registry?
Title: Re: need help from Nikolay on his addin (or someone else who is smarter than me)
Post by: Nikolay on November 03, 2022, 04:39:54 PM
I see. Maybe some update to Visio UI rolled out by Microsoft recently.
Just tested my current one (Microsoft® Visio® Plan 2 MSO (Version 2210 Build 16.0.15726.20068) 32-bit) - for me the panel seems to be okay (i.e. width "300" is respected)

If you could share Visio version (or maybe the project itself) I could try to reproduce the issue.
Title: Re: need help from Nikolay on his addin (or someone else who is smarter than me)
Post by: perry59 on November 03, 2022, 04:47:48 PM
when I get back to my desk I'll get the version and build number. All I can say now is that we are on visio 2016, I also have that on my laptop. I am unaware of any updates to visio lately
Title: Re: need help from Nikolay on his addin (or someone else who is smarter than me)
Post by: perry59 on November 04, 2022, 09:35:09 PM
the build info for my visio at work (the problematic one) is:
Microsoft® Visio® 2016 MSO (Version 2209 Build 16.0.15629.20196) 32-bit

the build info for my personal copy (that works) is:
Microsoft® Visio® 2016 MSO (Version 2210 Build 16.0.15726.20070) 64-bit

again, I don't think it's a problem with the addin code, just something weird with the visio installation on my work computer
Title: Re: need help from Nikolay on his addin (or someone else who is smarter than me)
Post by: Nikolay on November 05, 2022, 10:45:52 AM
Last time I have seen an issue with child window positioned oddly was when there was some optimization introduced for the hardware acceleration in Visio (the "panel" started appearing in the top-left corner of the screen instead of docked-right).
Then it somehow fixed itself with the next Visio update. I'll try to install that version exactly to try the next days.
Title: Re: need help from Nikolay on his addin (or someone else who is smarter than me)
Post by: perry59 on November 06, 2022, 04:59:29 PM
Thanks for your help Nikolay, so glad you're still here!
Title: Re: need help from Nikolay on his addin (or someone else who is smarter than me)
Post by: perry59 on November 09, 2022, 10:50:38 PM
Still haven't been able to figure out what's going on, google has not helped much. It only happens on my work computer which is weird, on my laptop with the same version of visio it works fine. Another strange symptom, if the drawing window is maximized and you hit alt-f7 which shrinks the drawing window just a bit the panel peeks out a little more, making it more obvious that something is supposed to be there.
Title: Re: need help from Nikolay on his addin (or someone else who is smarter than me)
Post by: Nikolay on November 10, 2022, 08:35:11 AM
Just as an idea - maybe there is some OTHER panel opened, and this one (the one from the add-in) is docked on the top of that one?
And the second one forces the width of the whole sidebar somehow. Could you try to dock the add-in panel to the left side instead (i.e. drag it by the header and just dock to the left)?
Title: Re: need help from Nikolay on his addin (or someone else who is smarter than me)
Post by: perry59 on November 10, 2022, 04:27:30 PM
I tried that too. My shapes panel is usually docked on the left, so I "floated" it out into drawing area and drug the addin panel over to the left and docked it there. But, when I use the toggle-panel button to close and then re-open it, it goes back to the right hand side where it is made too small to see. That part is hard coded in the addin. My other forms though remember their size and position because I record that info in "My.Settings". I think I'll try to put the addin panels position there too so it will start from it's last position as well.
I'd still like to know what the heck is going on though and why it's only this computer (so far), I don't want my potential users to get befuddled with this.
Thanks for your help Nikolay!!

by the way, here is the code in my typical form load to position the form:
(maybe put into the "createwindow" function)

If (ModifierKeys And Keys.Shift) = 0 Then
            Dim initLocation As String = My.Settings.[Default].AddWires //<-"addwires" is form name
            Dim il As New Point(0, 0)
            Dim sz As Size = Size
            If Not String.IsNullOrWhiteSpace(initLocation) Then
                Dim parts As String() = initLocation.Split(","c)
                If parts.Length >= 2 Then
                    il = New Point(Integer.Parse(parts(0)), Integer.Parse(parts(1)))
                End If
                If parts.Length >= 4 Then
                    sz = New Size(Integer.Parse(parts(2)), Integer.Parse(parts(3)))
                End If
            End If
            Size = sz
            Me.Location = il
        End If


and here is the code in my typical form close which records the last size/position:
(maybe put into the "destroywindow" function)

If (ModifierKeys And Keys.Shift) = 0 Then
            Dim location__1 As Point = Location
            Dim size__2 As Size = Size
            If WindowState <> FormWindowState.Normal Then
                location__1 = RestoreBounds.Location
                size__2 = RestoreBounds.Size
            End If
            Dim initLocation As String = String.Join(",", location__1.X, location__1.Y, size__2.Width, size__2.Height)
            My.Settings.[Default].AddWires = initLocation  //<-"addwires" is form name
            My.Settings.[Default].Save()
        End If
Title: Re: need help from Nikolay on his addin (or someone else who is smarter than me)
Post by: perry59 on November 11, 2022, 06:12:04 PM
I believe I found the main culprit.
I have a dual monitor system at work. The visio application was opening on the secondary monitor. When I moved it to the primary monitor then the panel worked as expected. Still weird, it should not matter what monitor it is displayed on.
As a side note, I tried modifying the panelFrame functions in the addin so that the panel frame could be moved around and remember it's position. Only partially successful, the necessary code is a bit past my skill level right now.
Thanks for all your help Nikolay!