Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Form resizing
#1
Hi guys,

I have a grid on a form, and when the user resizes the form, I want to resize individual columns in the grid. I catch the resize and set the number of pixels to adjust Column width by, in the Forms OnAsyncResize, but the size of the grid is not changed. I suppose it is because I use OnAsyncResize. However, the OnResize is not fired when I resize the form by pulling it.

I have tried Grid.invalidate and Grid.Update but not luck.

Does anyone have any ideas of what I could try ?

Regards
Soren
Reply
#2
Hi Soren, in IWDBGrid i use:
Code:
IWDBGrid_mygrid.DoRefreshControl := True;
Reply
#3
Hi Jose,

Sorry for the long delay. I tried to apply your proposal, but it was not possible. I forgot to mention it's a TMS IWAdvWebGrid I'm using. Not a DBAware, just plain one.

Been trying to find a solution since and have finally arrived at a acceptable one:

It turns out the grid is only adjusted after a round-trip to the server, but also that the FormAsyncResize event is called, not only when the form is resized, but also after every non-async event. Knowing that I have done like this:

Added two integers on form level, called CurrentHeight and CurrentWidth. In FormCreate I set them to the Height and Width of the form.
Added a integer on form level, called FirstTime. In FormCreate I set it to -1.

Added an IWButton, set it's visible property to false, and added an OnClick event, but with no codelines except for a comment (to avoid it being removed at next save)

Added an IWTimer, set the interval to 10 ms and set enabled to false, and added an OnIWTimer event with two lines of code:
IWTimer.enabled := false;
IWButton1Click(Sender);

Added a FormAsyncResize event with the following code:
If FirstTime <> 0 then
begin
  CurrentWidth := self.Width;
  CurrentHeight := self.Height;
  FirstTime := 0;
  Exit;
end;
If (self.Width <> CurrentWidth) or
  (self.Height <> CurrentHieght) then
begin
  IWTimer1.enabled := true;
  CurrentWidth := self.Width;
  CurrentHeight := self.Height;
end;

That way the grid size (and other components reacting to form resize) is only adjusted when the form size is actually changed and not also everytime a non-Async OnClick event is fired. And in my case, because I set a user defined font size and - family name as a general function of any form, which will change the size compared to the designed one, the FirstTime also preventes the resize to executed when the form is created at first.

Regards
Soren
Reply
#4
Hi again,

I have managed to optimize my code which then present a new problem with regards to FormResizing:

The FormResizing event is fired multiple times while dragging or pulling the form, meaning my code with relation to resizing is executed multiple times. Is there a way to delay the event firing until the final size is reached, so that the event is only fired once at the end of the resize operation. Recording the sizes (height and Width) at the resizing time, it seems as if the event is fired for every 16 pixels the width is changed. I have not checked the height yet...

UPDATE: The event i definitely fired for every 16 pixels the width is changed, especially when going from larger to smaller while when the other way (smaller to larger) the event is only fired once (it seems).

Regards
Soren
Reply
#5
What event are you using, sync or async? Resize already does that, i.e. it only fires when the user stops moving the window
Reply
#6
Hi Alexandre,

Happy New Year and sorry for the delay in answering. I am using the OnAsyncResize, but have tried both and there do not seem to be any difference. I have tried to make a small program to demonstrate the behavior, but it is not as simple as that.

Making a simple from, with a region anchored top, left and right, it does resize on the fly. Only to the designed width though. If the region is assigned as OnTop, or Client aso., it does resize all the way.

I'll try to explain the behavior I experience: My form has a designed size of 1080 * 888. I have a region, left 16 with a width of 856, leaving another 16pixels on the right, between the region and forms right side. I put on a TMS grid (it too has a left of 16 like the region above it), put its usefullwidth and usefullheight to true to keep it within the boundaries of the screen size, and fill it dynamically with columns and rows, depending on the executed SQL statement. Sometimes the width of the grid is more than 1080 and sometimes smaller.

When I create the form, it starts with the designed size, and the adjust itself to the last know size of the browser window / tap. That's the first time the OnAsyncResize is fired. If the grid is smaller than the designed width, I can manually resize it to the designed size with out problems, that is, OnResize is only fired once. If the grid width is higher than the designed size (and higher than the current form width, OnResize fires only once when I increase the width. However, when I decrease it, it appears to be done in one go, but the OnResize is fired for every 16 pixels I have decreased it. Until it reaches the designed size.

With a grid wider than designed size: if I maximize the windows, and restore it, or if it is already at max when the grid is shown, and I restore it, the OnResize fires only once. The problem is only when I drag the right side towards the left.

Physically what happens, when a grid is larger than the browser window size at start, is that I can enlarge it and the normal components, region and others, will resize on the spot. The Grid will not. I have to make a roundtrip to the server, and use a OnClick event on a button for that. When dragging the right side of the browser window towards left, all components stay enlarged, and I have to press the button to decrease the width. However, as it only happens in blocks of 16 pixels, I have to press the button a number of times.

I tried with a timer, letting it press the button for every 50ms, and it works, but still in blocks of 16 pixels.

I have not been able to create a small test program to show the behavior which makes me believe it might be a combination of settings of various components, causing it. I just haven't found out which it is yet.

Still I hope this description have given you an idea of what it might be and I hope you can propose something I can do to try to solve the problem. The obvious solution is to disallow the user to resize the window by dragging it, and only allow Max and Restore, but I'm not happy with that.

Regards
Soren
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)