views:

1019

answers:

6

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.

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.

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


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

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.

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.

+2  A: 

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.

BFree
And from the MSDN documentation, that property doesn't do what I wanted:"Indicates that the property grid should refresh when the associated property value changes."It will refresh the property grid, not the IDE designer.
Nazgulled
A: 

It didn't work :(

The IDE didn't refresh as it happens when you build the solution and the new painting/changes were not applied...

Nazgulled
Do not post questions as answers. Extend the question, or comment.
Kent Fredric
Also, note: new answers don't have a fixed order, don't assume they're responses to the 'previous' answer as you see it.
Kent Fredric
A: 

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.

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.

Hope that helps!

Romias
A: 

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.

Nazgulled
A: 

[question as answer moved to question section]

Nazgulled
+1  A: 

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

Thanks everyone though :)

Nazgulled