Refresh PropertiesWindow by program at Designtime

hvsecs

New member
Joined
Feb 14, 2019
Messages
4
Programming Experience
3-5
Hi collegues.

I have spent a lot of hours to find out how I could achieve my goal, but i have not come any nearer :-(
So maybe you have another idea.
What is the situation?
I have made a form, a very easy form with nothing on it.
This is the code:

C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace haffonReporting
{
    public partial class Easy : Form
    {
        public Easy()
        {
            InitializeComponent();
        }
        [Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        [RefreshProperties(System.ComponentModel.RefreshProperties.All)]
        public int abc { get; set; }


        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case 0x0001:
                    this.BackColor = Color.LightYellow;
                    break;
                case 0x0215:
                    abc += 5;
                    break;
            }
            base.WndProc(ref m);
        }


    }
}
As you see, there is a public property named abc and WndProc.
This Proc captures a mouseclick and countup abc by 5.

I save this form and ok.

Then I add a new form, inherited from the easy one.
Since I trap also wm_create, the backcolor of the new form gets light yellow.
I can see in the PropertiesWindow the Property abc.

If I now click somewhere into the form, the abc gets counted up every time by 5.
BUT this is not reflected in the Properties Window. If I resize the form i.e., THEN the previously updated value is seen in the Properties window.

So just the change of the property by code does not show it in the properties window. Another fact: If I just click enter a few times and do nothing else, the form does not get dirty, so if I close it, the change is not saved. If I resize it before closing, then it gets saved, and also the abc is saved correctly.

Any idea, how I could let the Properties window get updated?
I have tried with trapping some message, creating some messages, notifying etc, I have tried to resize the form programatically (it resizes, but change is not visible in the Properties Window)

This is very tricky.
Maybe there is a solution?

Many many thanks!
 
Use IComponentChangeService Interface (System.ComponentModel.Design) | Microsoft Docs
In property setter you can do this:
if (DesignMode) {
    changeService.OnComponentChanged(this, TypeDescriptor.GetProperties(this)["abc"], null, value);
}
 
WTF and OMG.

It is really that easy. If I think of all the things I have read and tried - what a luck my mouse survived this :)
Many thanks four your help.


Use IComponentChangeService Interface (System.ComponentModel.Design) | Microsoft Docs
In property setter you can do this:
if (DesignMode) {
    changeService.OnComponentChanged(this, TypeDescriptor.GetProperties(this)["abc"], null, value);
}
 

Latest posts

Back
Top Bottom