views:

3427

answers:

3

See the title. This should be really easy, but i don't quite see how to actually do it.

(Update) I'm not subclassing the control. Trying to trigger the event via Control.Size = Control.Size fails, since it does not trigger then even unless the new size is actually different.

A: 

Just change the size of the control using: Control.Size = new Size(x,y);

Changing the size of the control will issue a resize event for that control and the control should resize.

Alternatively if you just want to redraw the control then do: Control.Invalidate();

Calanus
+2  A: 

If you are subclassing Control, you can call OnResize directly, or expose it on the API:

 public void OnResize() {
     this.OnResize(EventArgs.Empty);
 }

However, you can't do this for arbitrary controls. You could change the Size to-and-fro? Alternatively, you could use reflection, but that is hacky:

 typeof (Control).GetMethod("OnResize",
     BindingFlags.Instance | BindingFlags.NonPublic)
     .Invoke(myControl, new object[] {EventArgs.Empty});
Marc Gravell
Reflection would be possible, but it's probably an overkill and also feels really ugly.
mafutrct
I agree entirely...
Marc Gravell
A: 

Why do you want to do this, and in what scenario? You can call OnResize, for example, when you're in the control itself (ie. in your derived control class). (Or via Reflection, when you are outside.)

Apart from that, you'll probably have to change the control's size, since that is what the Resize event is for :)

Fabian Schmied