Jump to content
Paul Dardeau

Vcl text box that user can move/resize at runtime?

Recommended Posts

Hi,

 

I'd like to find a way to allow the user to select a VCL edit box at runtime and move and/or resize it (similar to how Delphi does form builder at design time). I just need this capability for text boxes. This is for charts where I'd like the user to be able to edit title, add annotations, and move/resize the annotations. Does such a thing exist? Any suggestions?

 

Thank you in advance!

Share this post


Link to post
Just now, Paul Dardeau said:

I did many searches and did not find any good answers, hence my post here. Sorry if I offended your superior intellect.

As far as I can see both of the searches above returns a plethora of relevant answers to your question, which you are not exactly the first to ask.

So what's preventing you from using any of them?

Share this post


Link to post
34 minutes ago, Anders Melander said:

As far as I can see both of the searches above returns a plethora of relevant answers to your question, which you are not exactly the first to ask.

So what's preventing you from using any of them?

 

The first link that I examined is this:

https://www.thoughtco.com/how-to-move-and-resize-controls-at-run-time-4092542

 

It uses a non-standard way for the user to resize the control. The user must hold shift key to resize. The article concludes by saying that you might want to add 8 sizing handles. It gives no code or tips on how to do that.

 

I then looked at these:

https://tips.delphidabbler.com/tips/92

https://tips.delphidabbler.com/tips/93

 

There are no images to show what it looks like and very little explanation. I'm not new to programming, but I am new to Delphi and specialized Windows UI custom code.

 

I looked at this thread:

https://stackoverflow.com/questions/813693/how-to-draw-on-a-tpanel

 

I saw someone mention about using Raize Components (TRzPanel in particular). Great! I google search "Raize Components" and it appears they (Raize) no longer offer those components for sale.

 

In same thread, someone mentions to use TMS TAdvPanel (part of their VCL Components). I search for documentation about TAdvPanel and I can only see basic documentation.

 

This thread and some of the others do have code, but few comments or discussion about the code.

 

Part of the reason I was drawn to Delphi is the 'Rapid' part of application development. If I have to spent a lot of time figuring out old code to do something that seems relatively common, that goes against the grain of rapid development (in my opinion).

 

One of the things I was hoping to hear from others in this forum post are things like "I've used 3rd party component X and it worked great" or "I built my own by subclassing Y and adding functionality Z".

 

I find comments like "Let me teach you a trick: <google search links>" to be condescending. I introduced myself by saying that I'm new to Delphi.

Share this post


Link to post
Just now, Paul Dardeau said:

Part of the reason I was drawn to Delphi is the 'Rapid' part of application development. If I have to spent a lot of time figuring out old code to do something that seems relatively common, that goes against the grain of rapid development (in my opinion).

It's not "relatively common". In my 30 years with Delphi I think I've only had a need to do it (resize a control with the mouse) once and that was for a run-time form designer.
Moving a control can be done with something like 10 lines of code. Resize is harder.

 

The Raize controls are owned by Embarcadero now and can probably be installed via GetIt.
https://blogs.embarcadero.com/konopka-signature-vcl-controls-version-7/

 

9 minutes ago, Paul Dardeau said:

That's not how I would do it but it's certainly a possibility. Why not try it instead of just giving up?

 

10 minutes ago, Paul Dardeau said:

One of the things I was hoping to hear from others in this forum post are things like "I've used 3rd party component X and it worked great" or "I built my own by subclassing Y and adding functionality Z".

Okay then: I googled the problem, read a lot of examples, tried some different solutions and then wrote some code based on the experience I just acquired. Worked great!

Better?

 

15 minutes ago, Paul Dardeau said:

I find comments like "Let me teach you a trick: <google search links>" to be condescending. I introduced myself by saying that I'm new to Delphi.

Fair enough. Sorry about that.

I guess I just don't understand that approach to problem solving.

Share this post


Link to post
38 minutes ago, Anders Melander said:

Why not try it instead of just giving up?

 

Giving up? Au contraire! I'm just getting started! 😀

 

I suspect that my initial post may have agitated you since you thought I was giving up without trying. Sorry for that (if that's the case). I did try playing with various snippets of code I had found and had the 'move' functionality done in a matter of minutes. As you say, the resizing is more involved.

 

I started with the question because I'd like to leverage best practices and not waste time going down a rabbit hole unnecessarily. I'm not opposed to doing that when required (and I do like the learning aspects of doing that).

  • Like 1

Share this post


Link to post

Thank you to everyone who provided suggestions!

 

I have a working prototype that provides the desired functionality. I created a custom control (TSizeableLabel derived from TCustomControl) that "wraps" a TLabel. The TLabel is passed as an argument to TSizeableLabel's constructor and TSizeableLabel makes itself the parent of the label. It also makes it's size just a little bit bigger than the size of the label. The extra size is to accommodate the 8 size handles that are drawn to enable resizing.

 

I'm planning to put my prototype in a public github repo soon.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×