Horizontal Scrollbar Problem


I am using the GoDiagram Win 2.0. When I load my application the first time before any sizing changes occur the horizontal scrollbar is out of position.
Does anyone have any clue how to fix this problem?
I have tried using:
UpdateView, Update, LayoutScrollbars(true), UpdateScrollbars and nothing works.

Are you overriding OnSizeChanged or OnCreateControl in your GoView class?

I am not. I am just putting the nodes and links directly into the GoView.

(via email, the answer to that was no)

Are you using WinForms Docking and Anchors to control the position / size of the GoView, or are you setting the size explicitly in the startup code?

The GoView is docked (Fill) below a windows toolbar. These 2 controls make up 1 larger control which is docked (Fill) in a panel.

But if you resize the window after startup, the scrollbar snaps to the right location, do I understand correctly?

Yes, that is correct. Even if I move the splitter bar to the right the horizontal bar snaps back to the bottom.

So, you have a user control that includes a GoView and a toolbar? Does the height of the GoView in the definition of the user control happen to match the height of the spot where the scroll bar is ending up?

It might be close, but not exact. My user control is 248, 153 in the designer. I think when you look at my screenshot you will see that it is bigger than that.

Well, it ought to “just work”, but maybe something about being a control inside a user control is keeping the GoView from getting the resize event at the right time during startup. Where are you trying to do the LayoutScrollbars? Can you set a breakpoint there and see what the GoView size is?

I am calling LayoutScrollbars after I do all the populating of the GoView.

GoViewPopulator.Initialize((ICollection)MyController.ModelObject, displayHorizontal, _layerView);
ScrollToSelectedNode(); _layerView.LayoutScrollBars( true );

The code inside the GoViewPopulator.Initialize looks like this…

view.BeginUpdate(); _displayHorizontal = displayHorizontal; Initialize(collection, view); view.EndUpdate();
The Initialize adds the nodes, then adds the links then performs a layout on all the nodes to move them off of each other. Originally they are all added at 0,0

The first time I hit the LayoutScrollbars

Form W=248 H = 184
GoView W=248 H=153
Toolbar W=248 H=31
The second time
Form W=244 H=422
GoView W=244 H=391
Toolbar W=244 H=31
The VerticalScrollBar never seems to get larger than 80. This would leave it fairly short of the bottom. I noticed that even without the horizontal scrollbars the veritical one still comes up short. See image

Even trying to manually assign the height of the scrollbar does not work. Could there be some kind of reference problem? I am passing the GoView around…

Could you try removing all “artificial” adjustments and initialization code? I mean all those calls to methods that have “Update” or “Layout” in their names, both for GoView as well as standard Windows Forms controls. In as much as possible, just have the code that the Visual Studio designer created, and as little else as possible.

If there is still a problem, try putting the code to initialize your view’s document into a separate button or other command that the user invokes after the whole window is visible. If this fixes the problem, then you must be initializing the view too early. Try doing it when the Form is loaded.

If you still have a problem after this second step, I would guess that you didn’t clean up all of the initialization code correctly from the first step.

I tried your sugestion of the button to display the view. This works. However, when I look in my code I am doing InitializeComponent way before I ever try to populate the document. So the view is completely created at this point correct? Is it maybe a problem because all the parent forms or controls are not done painting?

I have to say this is a really weird issue since this code has not changed in a year for us and all of the sudden it does not work.

Question, just for my understanding because I have fixed the problem but it seems…well odd…

Original code:
public void Initialize(string layerToSelect)
{ SetUpGoViewPopulator(); SetupToolbar();

LayerToSelect = layerToSelect;
DisplayNodes(layerToSelect, GoViewPopulator.DisplayHorizontal);

New code:

public void Initialize(string layerToSelect) { SetUpGoViewPopulator(); SetupToolbar();

LayerToSelect = layerToSelect;
// This forces the Enter event to fire.
// This event will populate the Nodes in the view.

private void LayerListEditor_Enter(object sender, EventArgs e) { DisplayNodes(LayerToSelect, GoViewPopulator.DisplayHorizontal); }
The Focus() and the DisplayNodes in the original code are in the same place in the code execution path. Why does calling the Focus method and having the Enter event handler display the nodes work but just simply displaying the nodes does not work?

well, it looks like you’ve set it up so that a Windows event is the final initialization. The event gets delivered after all the startup code has run and the app has returned to the “idle loop”. So, I don’t think this is really different than the “click the button” test case.

I do not think it is any different either, other than the user does not have to click on something which is a requirement for me.

I just find it odd that the code looks like it should be executed in the same place and at the same time but obviously one works and the other does not. Maybe it does matter that it waits until the end of the idle loop even though I am not sure how we are getting back into that loop since we are drawing the form once and never again.

The Windows Program main loop isn’t as apparent in .NET applications as it was in old style Windows programming. The _Enter event isn’t delivered when you call this.Focus. It gets queued up until “new Form()” code is done executing.

Read the MSDN docs for Application.Run and DoEvents methods... it may make more sense to you.

Thanks. It does make sense to me. The confusing part is the new Form() code has been called and executed minutes before I try to display the nodes. I am just confused on how I could be getting stuck in there. I do realize that is not your concern.