Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on windows Form Application ?

Is there any way to make a resizable controls (like textbox in microsoft Powerpoint) ?
Posted
Comments
BillWoodruff 9-Jan-15 15:11pm    
Do you mean how to enable a Control on a Form at run-time to be click-dragged re-sized by the user of the Windows Form Application ?
BibhutiAlmighty 10-Jan-15 0:30am    
yes

Why not? The are all resizeable: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.size%28v=vs.110%29.aspx[^].

As you can see, you can always change the size.

The only problem is to create a control which would resize other control(s). It could be anything, even the scroll bar or the slider :-).

It's much better not to resize controls in an arbitrary way (where are you going to resize them? In good design, this space is occupied with other controls! :-)) These two are specifically designed for resizing, in much more reasonable way:
http://msdn.microsoft.com/en-us/library/system.windows.forms.splitter%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.splitcontainer%28v=vs.110%29.aspx[^].

—SA
 
Share this answer
 
v3
Comments
BillWoodruff 11-Jan-15 11:04am    
This comment added late because comments were disabled for a few days.

My vote of +2: States the obvious fact that WinForm Controls are re-sizable at design-time as if that is something that is not obvious. Then digresses about scroll-bars and sliders.

Irrelevant to OP's concerns. Typical of answers designed just to accumulate reputation points.
Sergey Alexandrovich Kryukov 11-Jan-15 11:41am    
Aha, you are starting to go against the obvious facts... :-)
What you say is pure nonsense. Sometimes the answer should be formal. Do you understand that what OP is asking is a bad design? What you suggested in your answer is bad? Really bad. And did you pay attention that I advised a really good thing: Splitter and SplitContainer, and not a scroll bad and slider as you think (I'll add a smile, because not only you can pay that little attention)...
—SA
To re-size Controls at run-time you are going to need to implement three EventHandlers for the Control (shown here wired-up in the Form Load EventHandler):
C#
// you'll need to keep track of 'state:
private void Form1_Load(object sender, EventArgs e)
{
    YourControl.MouseDown += YourControl_MouseDown;
    YourControl.MouseUp += YourControl_MouseUp;
    YourControl.MouseMove += YourControl_MouseMove;
}

private bool IsMouseUp = true; // is the mouse up/down ?
private Point MouseDownPoint; // where the mouse was clicked
private Size ControlSize;

// EventHandlers
private void YourControl_MouseDown(object sender, MouseEventArgs e)
{       
    IsMouseUp = false;

    ControlSize = YourControl.Size;

    MouseDownPoint = e.Location;
}

private void YourControl_MouseUp(object sender, MouseEventArgs e)
{       
    IsMouseUp = true;
}

private void YourControl_MouseMove(object sender, MouseEventArgs e)
{
    if (IsMouseUp) return;

    YourControl.Width = ControlSize.Width + e.X - MouseDownPoint.X;
    YourControl.Height = ControlSize.Height + e.Y - MouseDownPoint.Y;
}
This is, of course, pretty simple re-sizing: we're keeping the left-top corner of the Control "pinned" and manipulating its width and height based on relative offsets calculated from the initial and current position of the mouse during the MouseMove Event.

And, we're not doing any checking for things like making the Control so large part of it goes off-screen. You can, of course, limit the re-sizing of the Control by setting the Minimum- / Maximum- Size Properties at design time, and I strongly suggest you do that so your users will not accidentally hide the Control !

It gets much more interesting when you want to detect the direction of re-size and actually move the Control as well as re-size it. That's ... another story.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 11-Jan-15 11:57am    
And why all that? Just to answer OP's question, who knows why? It does make a resizeable control anyway (no resize grip or borders, nothing). This is just a way to screw up the design by an unsuspecting user. :-)
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900