User controls in winforms C#

Tommy Öman 1 Reputation point
2021-03-29T21:14:56.927+00:00

I'm building a simple graphics User Control to plot data in an application. To be able to scale as good as possible i would like the control to determine it's size after layed out on my winform. The controls formpart is used for plotting, and at designtime you can stretch the control area as you wish. Probably there is a simple solution on this , but i have googled a lot and havent found the solution yet. Is that possible, or am i trying to do something foolish?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,205 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,117 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Andrew Fraser 91 Reputation points
    2021-03-29T21:34:01.397+00:00

    Override the OnResize method to get the new size of the control.

    Andy

    1 person found this answer helpful.
    0 comments No comments

  2. Sam of Simple Samples 5,516 Reputation points
    2021-03-29T23:05:34.27+00:00

    I am not sure what you are asking but perhaps you are looking for ClientSize.Height and ClientSize.Width.

    I forget the difference between the Resize Event and the SizeChanged Event but I am nearly certain that the Resize Event fires multiple times during a resize and the SizeChanged Event fires after the resize is complete. You can redraw the user control during the resize or you can wait and resize only once.

    0 comments No comments