Time editing

I created a listview user control. I set it to add a new button every time I add a new column.
When I run a program that contains my user control, the column buttons are placed correctly. However, during development, when I add or remove columns, the control does not update the added buttons.

They are fine at runtime, but at design time I need to close the form and reopen it (force redo) to refresh the column buttons.
How can I programmatically force a redraw of my User Control?
The Column property is as follows:

  <MergableProperty(False)> _ <Editor("System.Windows.Forms.Design.ColumnHeaderCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", GetType(UITypeEditor))> _ <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _ <Localizable(True)> _ Public ReadOnly Property Columns() As ListView.ColumnHeaderCollection Get Return ListView1.Columns End Get End Property 

And I tried to redraw the control as follows:

  Me.Invalidate() Dim x As New Rectangle With {.X = Me.Location.X, .Y = Me.Location.Y, .Size = Me.Size} Me.NotifyInvalidate(x) 

But for some reason its not working. During design, each time Ii adds a column, the corresponding button is not added.

+4
source share
1 answer

Just a quick idea may not be the best solution, but it doesn't bother me to try, and I assume that it will work, even if, as I said, this is not the best way to do it.

In the Sub that you use to add / remove columns, add the following:

 Dim Graphics As Graphics = [yourform].CreateGraphics Dim ParamArg As New PaintEventArgs(Graphics, [yourform].ClientRectangle) InvokePaint(Me, ParamArgs) 

This should cause the nasty thing to be drawn every time you add / remove.

+1
source

Source: https://habr.com/ru/post/1481255/


All Articles