Jump to content
sjesper

How to wait in a form ?

Recommended Posts

Hello.

 

I was wondering how to wait in a form.

 

Example: I have a button called ">" that will make the form larger (ClientHeight) and i want it to loop like 10 times with a wait of 100 ms, and make the form a little larger everytime so it get's really smooth :-)

 

Do i have to make it calc some big numbers as a wait, cause i can't just use the command Wait() in a form.

Link to comment
Share on other sites

Do i have to make it calc some big numbers as a wait, cause i can't just use the command Wait() in a form.

Create a TTimer, and do your resize inside the timer's code body, then disable the timer after x times? Although I don't see why you can't call Wait inside the OnClick event for the button.

Link to comment
Share on other sites

Forms have an onResize event handler, buttons an OnClick event handler. So you could resize the form from the edges and have the controls inside the form auto resize. Or OnClick event handler you could do something like this:

 

[sCAR]

 

procedure ResizeForm(Sender: TObject);

begin

if Sender = Button then

Form.Width := Form.Width + 60;

end;

 

Button.OnClick := @ResizeForm;

[/sCAR]

Link to comment
Share on other sites

Create a TTimer, and do your resize inside the timer's code body, then disable the timer after x times? Although I don't see why you can't call Wait inside the OnClick event for the button.

 

I was thinking about using an TTimer, but i meaby though there was another way. But can you call wait() when a form is open cause i can't :o. If you want i can send you my code :-)

Link to comment
Share on other sites

I was thinking about using an TTimer, but i meaby though there was another way. But can you call wait() when a form is open cause i can't :o. If you want i can send you my code :-)

 

I have a thread in the tutorials section that has tutorials on forms. Use the event handlers you do not need a timer for this.

 

Edit: Yes you can use the wait procedure.

Link to comment
Share on other sites

I have a thread in the tutorials section that has tutorials on forms. Use the event handlers you do not need a timer for this.

 

Edit: Yes you can use the wait procedure.

 

Ahh so if i understand ur right i need to resize the form when i click the button and use the TNotifyEvent: OnResize with the form until it's the right amount :-)

 

Just gonna try that :-)

Link to comment
Share on other sites

Ahh so if i understand ur right i need to resize the form when i click the button and use the TNotifyEvent: OnResize with the form until it's the right amount :-)

 

Just gonna try that :-)

Haha, I wouldn't go that route if I were you. You have to resize each control manually in the procedure. Its hectic, I've done it before and have gotten it to work. I haven't tried this yet, but I would try/look into doing things outlined here instead (Autoresizing form controls). Good luck. Use google if you can't find out what the type is.

 

So if onResize used (made up) TOnResizeEvent. Instead of TNotifyEvent, it could be something like this.

 

[sCAR]

procedure OnResizeEvent(Sender: TObject; var Action: TOnResizeAction); // Made up

begin

Action := TonResizeFree;

end;

 

Form.OnResize := @OnResizeEvent;

[/sCAR]

 

Could be something like that instead of the default TNotifyEvent's (Sender:TObject)

 

If you are going to just use the TNotifyEvent then make sure you base all the controls w, h, top, left on the Forms width and height. Like if your form is 200 by 200, do like Button.top := form.height /20; just make everything relative in order to achieve the resizing somehow. Make 1 control relative to the form, then the rest of the controls relative to that control. Control = form component like a TButton.

Edited by LordJashin
Link to comment
Share on other sites

I'd like to see a snippet of the code. I must be missing something here, because I don't see why you couldn't put everything you need in the event handler for the button.

 

You can, but why when you can just drag the edges of the form, and set the largest/smallest the form can be. OnResize event for the form means, when someone drags the edge of the form this event is triggered.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...