Excel主机用户控制问题 [英] Excel host User Control issue

查看:111
本文介绍了Excel主机用户控制问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是b $ b我创建了自己的Excel用户控件环境,使用了Visual Studio 2015 Excel 2013和2016 VSTO Workbook Project ... 这个概念是显示动画短信(比如股票市场新闻)。

我实现代码的方式很简单,在运行时添加一个新的标签控件实例给主'窗口消息',其中是用户控件表单。到目前为止一切正常。实际上动画是计时器工作的结果,
每个刻度(10毫秒)调用一个方法,将标签的左边属性递增1.添加一些消息后,GC开始集中工作,一切都是崩溃...

Hi,
I created my own User Control for Excel environment, used Visual Studio 2015 Excel 2013 and 2016 VSTO Workbook Project...  the concept is to show animated text message (like in the stock market news).
The way that I'm implemented the code is simple to add a new instance of label control at the run time to the main 'window messages' in which is the user control form. So far everything works fine. essentially the animation is a consequence of the timer work, each tick (10 msec) invoked a method that increment the left property of the label by 1. After added some more messages, the GC start to work intensively and everything was crashed…

添加消息的代码片段...

Snippet of the code that add the messages...

Public Sub AddMessage(ByVal Message As String, Optional ByVal Priority As Priority = Priority.Normal)
        If Message <> Nothing Then
            Dim RollerMsg As New Label
            NumMsg += 1
            If NumMsg <> 1 Then QueueMng.Enqueue(NumMsg)

            With RollerMsg
                If CType(Priority, Boolean) Then
                    .BackColor = Color.FromArgb(255, 192, 192)
                Else
                    .BackColor = Color.White
                End If
                .AutoSize = True
                .TextAlign = ContentAlignment.MiddleCenter
                .Text = Message
                .RightToLeft = RightToLeft.Yes
                .Name = "RollerMsg" & NumMsg
                .Font = IntFont
            End With

            Controls.Add(RollerMsg)

            Select Case IntDirection
                Case 4
                    RollerMsg.Left = Size.Width
                Case 6
                    RollerMsg.Left = -RollerMsg.Width
            End Select

            RollerMsg.Top = CType(Top + (Height - RollerMsg.Height) / 2, Integer)
            RollerMsg.BringToFront()
        End If
    End Sub







推荐答案

Hi Refael,

>>
在添加了更多消息后,GC开始集中工作,一切都崩溃了

这是什么意思?你的意思是你的Excel崩溃或任何不起作用?在我的选项中,GC将在没有引用时收集垃圾。如果您正在使用该对象,则不会自动收集该对象。

根据您的描述,我不知道如何使用您的代码重现您的问题。如果您能与我们分享您重现问题的详细步骤,将会很有帮助。

Best问候,

Edward

这篇关于Excel主机用户控制问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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