I am trying to use C# after using VB for a while. The problem that i am facing right now, is resizing things.
In VB i would use the following:

Private Sub TextBox_Resize() handles mybase.sizechanged 'change the size of the text box when the size of the main control changes'

textbox1.width = width - 40 'the size of the textbox is 40 off the size of the control, to keep it 20 away from each wall'

end sub

How would i use the handles feature in C#
thanks
~Matt

Dani AI

Generated

Brief summary referencing the replies: asked how to translate VB's Handles behavior to C#. pointed toward reacting to container resize, and suggested using designer layout features. Both are valid starting points; the follow-up below focuses on making the behavior robust and maintainable without hardcoded numbers.

Prefer a single, centralized layout routine rather than sprinkling size math across the codebase. For custom controls consider overriding OnResize or handling the framework layout events so all changes flow through one place (see the Control SizeChanged and Resize docs for differences: SizeChanged and Resize). Avoid one-off magic offsets: compute available space from the container ClientSize and respect Margin/Padding so spacing stays correct across themes and DPI (Form.ClientSize, Control.Margin, Control.Padding).

For maintainability and automatic behavior use container controls (TableLayoutPanel / FlowLayoutPanel) or the designer layout options rather than manual math; these handle distribution and resizing more predictably across locales and DPI (TableLayoutPanel). When changing several controls at once, wrap updates with layout suspension to avoid flicker and extra layouts (Control.SuspendLayout). Also set sensible MinimumSize/MaximumSize, and defer expensive work to ResizeEnd if continuous resize causes performance issues.

Tie this back to the thread: use the event wiring or designer as expects, but implement the layout logic using the guidance above so the UI scales cleanly and stays maintainable long-term.

Recommended Answers

All 2 Replies

You have to check in form resize event as per my understanding,

private void Form1_Resize(object sender, EventArgs e)
        {
            txtresize.Width = this.Width - 40;
        }

alternatively, take a look at the dock and anchor properties in the designer. They control the size and location of a control relative to its container.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.