VB.NET-添加自己的控件后,看不到表单实例或关闭contextmenustrip. [英] VB.NET - Can't see instance of form or close contextmenustrip after add own control.

查看:279
本文介绍了VB.NET-添加自己的控件后,看不到表单实例或关闭contextmenustrip.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以在这里帮助我一点.问题是,当我右键单击表单时,我的contextmenustrip出现,并带有一个我添加的新控件,它接受一个值并将其通过添加处理程序传递.问题是一旦有了该值,就看不到实例化的窗体,也无法关闭上下文菜单条,因为它不可见.

Can someone help me a little bit here. The issue is when I right click on the form, my contextmenustrip appears with a new control I added and it accepts a value and passes it through an add handler. The issue is once I have that value, I can''t see the instantiated form nor can I close down the context menu strip as it is not visible.

Public Class Form1

    Public Sub New()

        '' This call is required by the Windows Form Designer.
        InitializeComponent()

        cmenuListView.Items.Add(New MyToolStripItem)

    End Sub

    Private Sub FilterBySymbolToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FilterBySymbolToolStripMenuItem.Click
        MessageBox.Show("Filter By Symbol Ver 1 worked")
    End Sub

    Public Class MyToolStripItem
        Inherits ToolStripControlHost

        Public Sub New()
            MyBase.New(New MyToolbarControl)
        End Sub

        Public ReadOnly Property MyToolbarControlProp() As MyToolbarControl
            Get
                Return CType(Control, MyToolbarControl)
            End Get
        End Property

        Protected Overrides Sub OnSubscribeControlEvents(ByVal control As Control)

            MyBase.OnSubscribeControlEvents(control)

            Dim myToolbarControlProp As MyToolbarControl = _
            CType(control, MyToolbarControl)

            AddHandler myToolbarControlProp.MyTxt.KeyDown, AddressOf HandleMarkChange

        End Sub
        Protected Overrides Sub OnUnsubscribeControlEvents(ByVal control As Control)

            MyBase.OnUnsubscribeControlEvents(control)

            Dim myToolbarControlProp As MyToolbarControl = _
            CType(control, MyToolbarControl)

            RemoveHandler myToolbarControlProp.MyTxt.KeyDown, AddressOf HandleMarkChange

        End Sub
        Public Sub HandleMarkChange(ByVal sender As Object, ByVal e As KeyEventArgs)

            If e.KeyCode = Keys.Enter Then

                Dim MyValue As String = DirectCast(sender, TextBox).Text

                MyToolbarControlProp.MyTxt.Text = String.Empty

                MsgBox(MyValue)

                ''now need to run code against another control on form but can''t see instantiated form

                ''add code

                ''now also need to close cmenuListView but can''t see .close - CAUSES ERROR
                ''cmenuListView.close()

            End If

        End Sub
    End Class

    Public Class MyToolbarControl
        Inherits ToolStripContentPanel

        Friend WithEvents MyTxt As New TextBox
        Friend WithEvents MyLbl As New Label

        Public Sub New()
            MyBase.Size = New System.Drawing.Size(175, 20)
            MyBase.BackColor = Color.Empty

            With MyLbl
                .Anchor = AnchorStyles.Bottom
                .Text = "Filter By Symbol:"
                .TextAlign = ContentAlignment.BottomLeft
                ''.Size = New Size(60, 15) '' Filter For:
                .Size = New Size(90, 15)
                .Location = New Point(0, 0)
                .Parent = Me
            End With

            With MyTxt
                .Anchor = AnchorStyles.Right
                .Location = New Point(MyLbl.Right, 0)
                .Width = Width - MyTxt.Left
                .AcceptsReturn = True
                .AcceptsTab = True
                .Enabled = True
                .ReadOnly = False
                .Parent = Me
            End With

        End Sub

    End Class

End Class

推荐答案

添加对象后,尝试重新绘制并刷新表单和contexmenu.
它对我有用.

什么是FilterBySymbolToolStripMenuItem_Click

它是工具条菜单吗?我正在尝试重新创建您的项目.

另外,请不要发布新的答案,更新或编辑您的原始问题并添加到底部.否则,Q& A对其他人来说读起来更难. :rolleyes:
Try to redraw and refresh your form and contexmenu after you''ve added the object.
it worked for me.

What is : FilterBySymbolToolStripMenuItem_Click

Is it a toolstrip menu? i''m trying to recreate your project.

Also please don''t post a new answer, update or edit you original question and add to the bottom. Otherwise the Q&A Reads harder for other people. :rolleyes:


您是否由我使用它.在构造函数中刷新?似乎对我不起作用?
did you get it to work by me.refresh in the constructor? doesn''t seem to work for me?


这篇关于VB.NET-添加自己的控件后,看不到表单实例或关闭contextmenustrip.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆