 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Kyle Dorian Guest
|
Posted: Fri May 13, 2005 1:28 am Post subject: Resizing of form components on a form resize |
|
|
Hi,
I was wondering if there was any way to simplify the resizing of components
on a form when a resize of the form occurs. What I am currently doing is
handling the OnResize event for the form, which in turn changes the size and
position of other components on the form, eg:
void __fastcall TfrmMainWindow::ScreenResize(TObject *Sender) {
unsigned short newHeight = 71 * (this->ClientHeight - 14) / 754;
unsigned short newWidth = (this->ClientWidth - 14) / 10;
if ((newHeight != _MWButtonHeight || newWidth != _MWButtonWidth) ||
Sender == NULL) {
_MWButtonHeight = newHeight;
_MWButtonWidth = newWidth;
// Change the sale screen
SaleScreen->Top = 3;
SaleScreen->Left = 3 + (!RightHanded * (6 * (_MWButtonWidth + 1)));
SaleScreen->Height = (6 * (_MWButtonHeight + 1)) +
_MWPageButtonHeight - 1;
SaleScreen->Width = (4 * (_MWButtonWidth + 1)) - 1;
// Change the buttons at the bottom of the screen
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 10; j++) {
if ((i == 3) && (j == 9)) {
break;
}
BottomButtons[i][j]->Top = 2 + SaleScreen->Height + (i *
(_MWButtonHeight + 1)) + 3;
BottomButtons[i][j]->Left = 2 + (j * (_MWButtonWidth + 1)) + 1;
BottomButtons[i][j]->ChangeSize(BtnSizeMap[BTN_BOTTOM_KEYS + (i
* 10) + j]);
}
}
// .........etc
}
}
However, what I would like to do is only change the size of the components
when the form has finished resizing (i.e. when the mouse is released). At
the moment, a simple resizing of the form by dragging the border of a form
results in about 5-10 calls to the OnResize event handler and as I have
about 800 components on a form, resizing of components multiple times
results in very sluggish redrawing. Therefore, is there a way where I can
determine when the mouse button has been released so the resizing and
redrawing of the form's components only occurs once?
- Kyzer
|
|
| Back to top |
|
 |
Hans Galema Guest
|
Posted: Fri May 13, 2005 7:27 am Post subject: Re: Resizing of form components on a form resize |
|
|
Kyle Dorian wrote:
| Quote: | However, what I would like to do is only change the size of the components
when the form has finished resizing (i.e. when the mouse is released).
|
If there was a simple function that would tell if the mouse
was down then you could use it here. It does not come to
mind right now.
But what you could do is to not resize in OnRisize(). Instead
take a TTimer. Let its eventhandler monitor the Width and
Heigth of the form. If they change then resize
the components accordingly but only if OnRisize() is not
going on. The code would look like:
void __fastcall TForm1::FormResize(TObject *Sender)
{
resizing = true; // private bool resizing;
}
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
if ( resizing )
{
resizing = false;
return;
}
static int width = Width;
static int height = Height;
// if there are more instances of this form
// then use private instead of static
if ( width != Width || height != Height )
{
static int times = 0;
Label3->Caption = "Resizing components " + IntToStr ( ++times );
//call resizing function here
width = Width;
height = Height;
}
}
The advantage of this approach is that as soon as the uses
pauzes a while, while resizing, the components are adjusted.
Now some comments on your code:
| Quote: | void __fastcall TfrmMainWindow::ScreenResize(TObject *Sender) {
unsigned short newHeight = 71 * (this->ClientHeight - 14) / 754;
unsigned short newWidth = (this->ClientWidth - 14) / 10;
|
Apart from an accolade that changed it's position you do not
need shorts as all is int in the VCL. Also omit 'this'.
void __fastcall TfrmMainWindow::ScreenResize(TObject *Sender)
{
int newHeight = 71 * (ClientHeight - 14) / 754;
int newWidth = (ClientWidth - 14) / 10;
| Quote: | SaleScreen->Top = 3;
SaleScreen->Left = 3 + (!RightHanded * (6 * (_MWButtonWidth + 1)));
SaleScreen->Height = (6 * (_MWButtonHeight + 1)) +
_MWPageButtonHeight - 1;
SaleScreen->Width = (4 * (_MWButtonWidth + 1)) - 1;
|
Those four statements can trigger four redrawings of the form.
Better use SetBounds ( ) which takes all at once.
| Quote: |
// Change the buttons at the bottom of the screen
|
Have a look at propertys ComponentCount and Components[]
or ControlCount and Controls[] of TForm and TPanel and other
controls. You just can adjust every control without needing to
know at forehand how many buttons there are.
Hans.
|
|
| Back to top |
|
 |
Jim Dodd Guest
|
Posted: Fri May 13, 2005 2:20 pm Post subject: Re: Resizing of form components on a form resize |
|
|
Kyle Dorian wrote:
| Quote: | Hi,
I was wondering if there was any way to simplify the resizing of components
on a form when a resize of the form occurs. What I am currently doing is
handling the OnResize event for the form, which in turn changes the size and
position of other components on the form, eg:
|
<snip>
| Quote: |
However, what I would like to do is only change the size of the components
when the form has finished resizing (i.e. when the mouse is released). At
the moment, a simple resizing of the form by dragging the border of a form
results in about 5-10 calls to the OnResize event handler and as I have
about 800 components on a form, resizing of components multiple times
results in very sluggish redrawing. Therefore, is there a way where I can
determine when the mouse button has been released so the resizing and
redrawing of the form's components only occurs once?
- Kyzer
|
There are a number of components on Torry's site:
http://www.torry.net/pages.php?id=159
This is the "VCL | Sizers, Scrollers, etc. | Sizers" section of
the site. Some are free and some come with source. Hope one of
those will solve your problem.
Regards,
Jim Dodd
Onset Computer Corp.
|
|
| Back to top |
|
 |
wgy Guest
|
Posted: Mon May 16, 2005 8:20 pm Post subject: Re: Resizing of form components on a form resize |
|
|
Yes, there is some optimize you can do
1. use TControl->SetBounder(...) to modify the control's size and position
at once, so they do not trigger the screen updating each time.
2. or you put all the controls that to be changed size in a panel, make the
panel unvisible befor you change the size and position of controls on it,
after it done, make the panel visible again (that cause screen flicks
,maybe, did not test it)
3. or use windows SDK call :
MoveWindows(Controls->Handle, left, top, width, height, true);
This will also prevent the control from spending time to update while it
is changing.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|