问题如何使C#的VS IDE设计器无效/刷新?

时间:2022-09-02 08:32:09

I have CustomForm inherited from Form which implements a boolean property named Prop. The forms I'll be using will inherit from CustomForm. This property will do some painting and changes (if it's enabled) to the form. However, this is not working as it should, the VS IDE designed is not being refresh to show the changes. But if I press Ctrl+Shift+B (Menu: Build » Build Solution) the VS IDE will refresh, the form designer will even disappear for a split second and will redraw itself with the new changes applied.

我有从Form继承的CustomForm,它实现了一个名为Prop的布尔属性。我将使用的表单将继承自CustomForm。此属性将对表单进行一些绘制和更改(如果已启用)。但是,这不能正常工作,设计的VS IDE不会刷新以显示更改。但是如果我按下Ctrl + Shift + B(菜单:构建»构建解决方案),VS IDE将刷新,表单设计器甚至会在一瞬间消失,并将重新绘制自己应用的新更改。

So, is there a way, by code, to force the VS IDE designer to refresh itself just like it happens when I build the solution? If so, I could add that code to the Prop set accessor and my problem was gone.

那么,有没有一种方法可以通过代码强制VS IDE设计器刷新自己,就像我构建解决方案时那样?如果是这样,我可以将该代码添加到Prop set访问器,我的问题就消失了。

Note that I've tried to call Invalidate(), Refresh() and Update. But none of them seemed to fix the problem...

请注意,我尝试调用Invalidate(),Refresh()和Update。但他们似乎没有解决问题......


Here's a little insight on my real problem. My code goes something like this:

这里有一些关于我真实问题的见解。我的代码是这样的:

internal class MyForm : Form {
    private FormBorderStyle formBorderStyle;
    private bool enableSkin;

    [DefaultValue(false)]
    public bool EnableSkin {
        get {
                return enableSkin;
        } set {
                enableSkin = value;

                if(enableSkin) {
                        BackColor = Color.Lime;
                        MaximizedBounds = Screen.GetWorkingArea(this);
                        TransparencyKey = Color.Lime;

                        base.FormBorderStyle = FormBorderStyle.None;
                } else {
                        BackColor = SystemColors.Control;
                        MaximizedBounds = Rectangle.Empty;
                        TransparencyKey = Color.Empty;

                        base.FormBorderStyle = FormBorderStyle;
                }
        }
    }

    [DefaultValue(FormBorderStyle.Sizable)]
    public new FormBorderStyle FormBorderStyle {
        get {
                return formBorderStyle;
        } set {
                formBorderStyle = value;

                if(EnableSkin) {
                        base.FormBorderStyle = FormBorderStyle.None;
                } else {
                        base.FormBorderStyle = formBorderStyle;
                }

        }
    }

    internal MyForm() {
        EnableSkin = false;
        FormBorderStyle = FormBorderStyle.Sizable;
    }
}

And the problem I'm having is something like this: http://blogs.msdn.com/calvin_hsia/archive/2007/05/01/windows-vista-aero-borderstyle-paint-problem-as-non-administrator.aspx

我遇到的问题是这样的:http://blogs.msdn.com/calvin_hsia/archive/2007/05/01/windows-vista-aero-borderstyle-paint-problem-as-non-administrator。 ASPX

In my case, that happens when you set the EnableSkin to True, change it back to False and then, changing the FormBorderStyle will cause the issue you can see on the link above. As stated in the article, the problem doesn't happen when running VS as administrator.

在我的情况下,当您将EnableSkin设置为True,将其更改回False然后,更改FormBorderStyle将导致您可以在上面的链接上看到的问题。如本文所述,以管理员身份运行VS时不会发生此问题。

That's why I'm looking for a way to refresh the VS IDE designer. In other words, now that I've found that article, I need to recreate the window just like it happens when the solution is rebuilt.

这就是为什么我正在寻找一种刷新VS IDE设计器的方法。换句话说,现在我已经找到了这篇文章,我需要像重建解决方案时那样重新创建窗口。


How do I declare a property in the base form?

如何在基本表单中声明属性?

I currently have:

我目前有:

public class MyForm : Form { }

And I can only declare properties inside that class, not inside the Form one... I also have used Invalidate() as I said in the first post, but it doesn't fix my problem.

我只能在该类中声明属性,而不是在Form 1中声明...我也使用了Invalidate(),正如我在第一篇文章中所说,但它并没有解决我的问题。

3 个解决方案

#1


4  

Someone else helped me out and to fix the problem. I just call ReCreateHandle() when the user sets EnableSkin to false. Problem solved :)

其他人帮我解决了问题。当用户将EnableSkin设置为false时,我只调用ReCreateHandle()。问题解决了 :)

Thanks everyone though :)

谢谢大家:)

#2


2  

All you need to do is add this Attribute to your property:

您需要做的就是将此属性添加到您的属性:

 [Description("Description of your property."), NotifyParentProperty(true),
 RefreshProperties(RefreshProperties.Repaint)]

That will cause the IDE to repaint when the value is changed.

这将导致IDE在值更改时重新绘制。

#3


0  

As far as I know the painting routines doesn't reflect in the IDE if you are showing the object that do the painting. For instance, if your base form do some painting, the inherited shows that... but if you open the base form it doesn't show the painting result.

据我所知,如果您正在显示绘画的对象,绘画例程不会反映在IDE中。例如,如果您的基础表单执行一些绘制,则继承显示...但是如果您打开基本表单,则它不会显示绘制结果。

I think that if you need to view the result of changing the property on your child forms, the property should be declared in base form, and do the painting in that form.

我认为如果您需要查看更改子表单上的属性的结果,则应该以基本形式声明属性,并以该表单进行绘制。

By the way... in the property body you should call this.Invalidate() in order to refresh the painting.

顺便说一下......在属性体中你应该调用this.Invalidate()来刷新绘画。

Hope that helps!

希望有所帮助!

#1


4  

Someone else helped me out and to fix the problem. I just call ReCreateHandle() when the user sets EnableSkin to false. Problem solved :)

其他人帮我解决了问题。当用户将EnableSkin设置为false时,我只调用ReCreateHandle()。问题解决了 :)

Thanks everyone though :)

谢谢大家:)

#2


2  

All you need to do is add this Attribute to your property:

您需要做的就是将此属性添加到您的属性:

 [Description("Description of your property."), NotifyParentProperty(true),
 RefreshProperties(RefreshProperties.Repaint)]

That will cause the IDE to repaint when the value is changed.

这将导致IDE在值更改时重新绘制。

#3


0  

As far as I know the painting routines doesn't reflect in the IDE if you are showing the object that do the painting. For instance, if your base form do some painting, the inherited shows that... but if you open the base form it doesn't show the painting result.

据我所知,如果您正在显示绘画的对象,绘画例程不会反映在IDE中。例如,如果您的基础表单执行一些绘制,则继承显示...但是如果您打开基本表单,则它不会显示绘制结果。

I think that if you need to view the result of changing the property on your child forms, the property should be declared in base form, and do the painting in that form.

我认为如果您需要查看更改子表单上的属性的结果,则应该以基本形式声明属性,并以该表单进行绘制。

By the way... in the property body you should call this.Invalidate() in order to refresh the painting.

顺便说一下......在属性体中你应该调用this.Invalidate()来刷新绘画。

Hope that helps!

希望有所帮助!