Results 1 to 6 of 6

Thread: ToolStripDropDown renders at position 0,0 on first click

  1. #1
    mark_dbg is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2012
    Posts
    3
    Reputation
    0

    ToolStripDropDown renders at position 0,0 on first click

    I'm trying to add a WebBrowser object into a ToolStripDropDownButton's drop-down. When I first click the button the drop-down shows at screen position 0,0. On subsequent clicks of the button the drop-down shows underneath the button like it should. Any idea on how to get the drop-down to show properly on the first click?

    Code:
            Dim browser As New WebBrowser
            browser.Url = New Uri("http://localhost/test.html")
            Dim host As New ToolStripControlHost(browser)
            Dim dropDown As New ToolStripDropDown
            dropDown.Items.Add(host)
            ToolStripDropDownButton1.DropDown = dropDown

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,197
    Reputation
    2368
    Not sure why, but this code resolved the issue:
    dropDown.Visible = True

  3. #3
    mark_dbg is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2012
    Posts
    3
    Reputation
    0
    Thanks JohnH. However, that doesn't solve what I need. That just seems to open the drop-down right off the bat.

    I probably should have been a little more explicit in my original post, but what I'm trying to do is to create a toolbar for IE. I want to have certain drop-down buttons be populated dynamically with html. I've tried opening and then closing the drop-down via code on instantiation and that works somewhat. The problem then is that the user has to click on the drop-down button twice for it to show the drop-down.

  4. #4
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,197
    Reputation
    2368
    That just seems to open the drop-down right off the bat.
    That did not happen when I tested the code. The only effect adding that code for me was that the drop-down showed at correct location when I clicked the drop-down button first time.

  5. #5
    mark_dbg is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2012
    Posts
    3
    Reputation
    0
    hmmm... You're right. In the form application it does exactly what you said. In the IE toolbar app, it just opens the drop-down and it stays there.

    I think I may have found a work-around though. If I do this:

    Code:
    dropDown.Visible = true
    dropDown.Close()
    then it seems to work just fine. It's getting the flicker of the window opening in the top left and then closing right away, but it's better than nothing.

    What I had tried before was:

    Code:
    ToolStripDropDownButton1.ShowDropDown()
    ToolStripDropDownButton1.HideDropDown()
    which caused the drop down to show in the correct spot, but you had to hit the drop down button twice for it to activate.

    Thanks for you help!

  6. #6
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,197
    Reputation
    2368
    I tested in winforms, right. The first thought was to call CreateControl method, which is part of what Visible property setter also calls for controls that has not been created and assigned window handles yet, but that didn't have any effect in winforms.

    The problem may be related to the drop-down not detecting any items, it is one of the cases where internal DropDownLocation returns Point.Empty. Again testing in winforms, if I add another empty element to the dropdown it shows at correct location first time:
    dropDown.Items.Add(String.Empty)

Bookmarks

Posting Permissions

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