anyone can help me...
I have developed vb.net deskstop application.I want to open popup in button click event but when popuup open in second time first display blank space after that popup contain dispay.
my code is :

    Dim popup As New ToolStripDropDown()
    popup.Margin = Padding.Empty
    popup.Padding = Padding.Empty
    popup.Width = 150
    popup.Height = 150
    Dim host As New ToolStripControlHost(Panel2)
    host.Margin = Padding.Empty
    host.Padding = Padding.Empty
    'host.Width = 50
    popup.Items.Add(host)
    popup.Show(200, 200)

Let me try to clarify this a little:

You are:
1) Creating a toolstripdropdown
2) Adding a panel to the dropdown
3) Repeating this process for every time a button is clicked?

Is this true?

Hello Begginnerdev,

I have allready Write code in button click evevt
But when button one time clicked pop up dispaly.but when button next time clicked that time popup panel left some space after thae panel contain dispaly.
my code is :

Dim popup As New ToolStripDropDown()
popup.Margin = Padding.Empty
popup.Padding = Padding.Empty
popup.Width = 150
popup.Height = 150
Dim host As New ToolStripControlHost(Panel2)
host.Margin = Padding.Empty
host.Padding = Padding.Empty
'host.Width = 50
popup.Items.Add(host)
popup.Show(200, 200)

You are creating a new one every time - but are you deleting the old one?

If Not, you need to keep a reference of it. Maybe a class wide variable called "curItem" and dispose of it before creating the new one?

'Example:

Dim curItem as ToolStripControlHost()

'In Button_Click
 If IsNothing(curItem) = False Then curItem = Nothing

 'Your Code here

 host.Padding = Padding.Empty
 'host.Width = 50
 curItem = host
 popup.Items.Add(host)

hello Begginnerdev,

I write this code but it can display error that value of type toolstriptcontrolHost can not converted in single diamensional Array of system.windows.from.toolstriptcontrolHost

mycode :

     Dim curItem As ToolStripControlHost()
    popup.Padding = Padding.Empty
    popup.Width = 150
    popup.Height = 150
    Dim host As New ToolStripControlHost(Panel1)
    If IsNothing(curItem) = False Then
        popup.Dispose()
        Return
    End If
    host.Margin = Padding.Empty
    host.Padding = Padding.Empty
    'host.Width = 50
    curItem = host
    popup.Items.Add(host)
    popup.Show(100, 200)

I appologize. I was writing the code quickly - and forgot the New therefore the interpreter looks at the () as an array identifier.

Replace:

Dim curItem as ToolStripControlHost()

With

Dim curItem as New ToolStripControlHost(Panel1)

Hello Begginnerdev,

Thanks for help me. But if i write this same problem is Occure.

I found one solution : plese help me in this

If i write Dim popup As New ToolStripDropDown() in button click event then problem is sloved but in my pouup panel ther is close button to close a popup. if i declare Dim popup As New ToolStripDropDown() in button click event how can i close popup in close button

code :

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim popup As New ToolStripDropDown()
    popup.Margin = Padding.Empty
    popup.Padding = Padding.Empty
    popup.Width = 150
    popup.Height = 150
    Dim host As New ToolStripControlHost(Panel1)
    host.Margin = Padding.Empty
    host.Padding = Padding.Empty
    'host.Width = 50
    popup.Items.Add(host)
    popup.Show(200, 200)

    Private Sub Btnpopupcancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnpopupcancel.Click
    Me.popup.Close()

 if i write  Dim popup As New ToolStripDropDown() in button click event how can i close popup

 Plese Help me.

You have three options:

You can call the .Close() Sub procedure:

popup.Close()

This will close it, but the object remains in memory.

You can call the .Dispose() Sub procedure:

popup.Dispose()

This will release all resources for it, but waits for the garbage collector to grab it.

You can also set it to nothing - This will nullify the object:

popup = Nothing

Declare the popup in a class wide variable to be able to manipulate it class wide.

Hello Begginnerdev,

still the issue is not slove.can you give me example of dispay popup in button click and popup can close in close button click If you have.

Try something like this:

Public Class Main
    Dim popup As New Windows.Forms.ToolStripDropDown()
    Dim host As Windows.Forms.ToolStripControlHost

    Private Sub Open_Click(sender As System.Object, e As System.EventArgs) Handles btnOpen.Click
        Try
            With popup
                .Margin = Windows.Forms.Padding.Empty
                .Padding = Windows.Forms.Padding.Empty
                .Size = New Size(150, 150)
            End With

            host = New Windows.Forms.ToolStripControlHost(Panel1)

            With host
                .Margin = Windows.Forms.Padding.Empty
                .Padding = Windows.Forms.Padding.Empty
            End With

            popup.Items.Add(host)
            popup.Show()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub Close_Click(sender As System.Object, e As System.EventArgs) Handles btnClose.Click
        Try
            popup.Items.Clear()
            popup.Close()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
End Class

Hello Begginnerdev,

Thanks a lot for help my popup issue is sloved using your code.

No problem friend!

Please do not forget to mark the thread as solved. =)

Hello Begginnerdev,
I am new to Daniwab.Plese guide me how to mark the thread as sloved

There will be a button at the bottom of this page that reads:

"Mark this thread as solved"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.