【问题标题】:Controlling the listbox inside a user control from main form and other user controls从主窗体和其他用户控件控制用户控件内的列表框
【发布时间】:2014-02-04 21:03:05
【问题描述】:

我有一个用户控件,里面有一个列表框。我想将此列表框用作我的应用程序中的留言板。所以程序中的主窗体和可能的其他用户控件将发送消息以供列表框显示。

我想知道实现这一点的最佳方法是什么。

【问题讨论】:

    标签: c# winforms user-controls


    【解决方案1】:

    您可以创建向您的MessageBoardControl 添加消息的方法:

    public void AddMessage(string message)
    {
        messagesListBox.Items.Add(message);
    }
    

    然后你可以从你的表单中使用所有这些方法:

    messageBoardControl1.AddMessage("Hello World");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-19
      • 1970-01-01
      • 2017-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-31
      • 1970-01-01
      相关资源
      最近更新 更多