How to check if form is maximized? - delphi

I'm having a problem with a component I use.Its aligned to bottom ,and ,when form is maximized,the control is placed at the correct position,but when I attempt to minimize the form,the control stays at the position where it is.
I tried using a timer that always sets the align to bottom,but I'm sure a timer is the worst solution to my issue.
Please suggest a way to set the align to Bottom when the form is restored from maximize.(maximize->restore only).
My current idea is to check if form is maximized at FormResize event,but that won't work,because I need to do it when its restored,not maximized.

You can check if a form is maximised by using
Self.WindowState = wsMaximized
Other states are
wsNormal
wsMinimized
wsMaximized
Depending on what you are doing, you could also place the control on a panel and align the panel to the bottom of the form, if you turn the borders off and use the parent colour, you cant see the panel, that way it will stay at the bottom of the form without additional code.

Related

When to use TPanel FullRepaint?

I noticed that the resize flicker gets much better when I set TPanel.FullRepaint to False. Since the property exists and is True by default, there must be some reason for that.
How to decide whether it should be set or not?
The help just states:
FullRepaint controls how the panel responds when it is resized. When FullRepaint is true, the entire panel, including the beveled border repaints when the size changes. When FullRepaint is false, only the area inside the beveled border repaints.
http://docwiki.embarcadero.com/Libraries/XE3/en/Vcl.ExtCtrls.TPanel.FullRepaint
That text says what it does, but not why ...
The effect of a missing Fullrepaint can be shown and you will have to decide if you need it or not.
Place a panel on a form, set anchors to all directions
Set PaintCaption to false or use a empty caption
Place another panel on the form, so that if you are resizing the
form, parts of the first panel will be covered by the second panel.
Run the program and size the form, somtimes the borders of the first panel will not be refreshed.
This happens because in WMWindowPosChanged in case of (FullRepaint or (ShowCaption and (Caption <> ''))) a invalidate will be called, otherwise only InvalidateRect(Handle, Rect, True) of a rects only containing the right and/or bottom border are invalidated. (thanks to Sertac Akyuz for correction)
As you mentioned avoiding invalidate reduces flicker and in many cases the need for a full invalidate is not given, so the user can decide on his own how to proceed.
Panels as the rarely will be used, upper without Fullrepaint
In previous versions of Windows (not sure up to which version, exactly) FullRepaint was required to prevent graphical artefacting on panel borders when a form was resized.
To the best of my knowledge, this hasn't been an issue since at least Windows XP.

How to avoid image is Hidden by Button

I have kept an TImage component at the Top-right corner of a bitbutton.While loading of Form some part of image is Hidden by Button as like in image .How to avoid this.? and also tell me how to find corner of a Button such that i can place my image correctly to show notification correctly in case of Dynamically loaded buttons.
Yours Rakesh.
A TImage cannot be brought in front of a TBitButton since a BitButton is a windowed control (TWinControl). Instead of a TBitBtn or a TButton, you can use a control which does not descend from TWinControl, like a TSpeedButton.
The top-right corner of a button is at (Button.Left + Button.Width, Button.Top).
A TBitButton owns a window handle and only controls with an own window handle can be placed in front of it. You could place your bitmap on a TPanel (TPanel inherits from TWinControl and has a window handle), and this panel you can bring in front of any other control. Set the BorderStyle of the panel to bsNone, so it only works as a container and is not visible.
P.S. If your bitmap is as simple as the one in your example, you could directly write onto the panel and set the colors accordingly.

Why can't I see my scroll bars?

I have positioned a nested form on the applications main form along with another control and a TSplitter, as stated in my previous question. If you look at that question, the part labelled "design forms here" needs scrollbars.
No matter whether I set scroll bars programatically to be visible or use the AutoScroll property - I never see the scroll bars !! Grrrr!! I was wondering if something else that I am doing could be removing the scroll bars. For instance BorderStyle := bsNone;
It's not that - when I comment it out I still don't see scrollbars, but that has got me thinking .... any ideas?
Is there a reason to use a nested Form on the right side? I tried it with a TScrollBox instead (alclient) and the scrollbars appear as expected...

TWebBrowser with Align set to alClient will not resize when client area changes

I have a form with several splitters and panels. In the middle is a panel that ends up with a TWebBrowser set to align alClient.
In the past this has worked well. However, on Windows 7 with Internet Explorer 8 the the browser is not correctly resized. Everything else (i.e. the panels) are the correct size, just not the web browser. Sometimes when you click into the browser, or more often when you scroll the browser will jump to the correct size. That does not happen 100% of the time though.
I'm trying to deal with the resize directly and force the control to change size. I can't seem to find a method that makes any difference (i.e. .Invalidate; .Repaint; .Update;)
TWebBrowser is an OLE control (ActiveX) that wraps the Internet Explorer control. Any ideas on how I can make the resize happen?
Updated Background:
I narrowed this down to only happening when I have a child form that I change the parent to site it inside another form. My TWebBrowser control is on a child form that I use anytime I need to show an HTML document.
In my parent form I have a Grid, a splitter, and a panel with the grid set to Align top and the panel set to align client. My child form (called THtmlViewer) has its parent set to the panel. The THtmlViewer form is set to alClient and TWebBrowser control on the child form is also set to align client.
If I do anything in the form resize of the THtmlViewer form I run into this issue. Anything being directly in FormResize or indirectly using the align properties. However, if I call my resize from the parent form everything works fine.
The key seems to be turning off the resize code in the THtmlViewer form. If I leave a OnResize handler or the alignment set then it does not matter what I do in the parent, the resize is not done correctly.
I am still confused why this is needed and why I can't force it to update in the correct resize (THtmlViewer).
As a side note I also noticed that Delphi 2007 on Windows 7 has the exactly same problem with the "Welcome Page" in the IDE.
I have worked around the issue by adding a method to set OnResize of the child form to nil and then call my internal ForceResize from the parent's OnResize handler. I would still like to deal with this all from the THtmlViewer form and would accept an answer that let's me avoid this hack.
To resize controls when their container changes size, you have two other options besides using "just" the Align property:
Use the Anchors property without the Align property, that is, set the Align property to alCustom or alNone, then set the anchors according to your needs. As the Align property is sort of short-hand for setting the Anchors, this is dependent upon the same alignment processing so may not work in your case.
Provide a handler for the OnResize event of the container on which the TWebBrowser sits and manually set the TWebBrowser's height and width to those of the container (optionally adjusted for any margins you want to have within the container).
That said, I don't have Windows7, so I can't vouch that this won't take more twiddling.
If your TWebBrowser jumps to the correct size on a scroll or click, it indicates that the control was sized correctly, just never received or processed the messages to actually respond to the changes.
This can be because realigning controls tries to prevent unnecessary repaints and recursions and somehow got mixed up. Using the OnResize method may then get better results as it "speaks to the TWebBrowser directly".
Repaint is "just" shorthand for Invalidate and Update unless the control has csOpaque in its ControlStyle, in which case painting seems more immediate. So you could try to fiddle with the Transparent property of the TWebBrowser and/or the container it sits on.
If all else fails, you could try to send a WM_PAINT (or similar) to the TWebBrowser directly. For exmample in the OnResize event of the TWebBrowser or the container it sits on. The a WM_Paint handler of the TWebBrowser calls OleDraw, which talks to the ActiveX directly using the ClientRect, which should have the correct dimensions when called from an OnResize event.
I had a similar problem.
It was solved by putting a TPanel "underneath" the TWebBrowser, and aligning the web browser to alClient.
Maybe the same solution for this question works: Resize problem using AcroPDF in Delphi
In OnResize:
if Visible and (WebBrowser1 <> nil) then
begin
FocusControl(nil);
FocusControl(WebBrowser1);
end;
I'd try something like
changing WebBrowser1.Align to alLeft,
setting WebBrowser1.Width to WebBrowser1.Width - 1 and
setting WebBrowser1.Align to alClient again
in an OnResize handler.

How to set the glyph for a toolbar button to blank?

I add a toolbar with some standard Delphi components to my application. Unfortunately, the stupid arrow is first glyph (does anyone even know what it is for?)
I would like to destroy it totally, or, at least, set itcs icon to blank, so that it blends in with the toolbar.
How can I do this?
I need some code which can be executed twice without causing an exception. Thanks
TToolButton gets its image from combining its ImageIndex property with the enclosing toolbar's Images property, which refers to a TImageList. To make a toolbar button have no image, assign ImageIndex := -1.
To remove the glyph from a TSpeedButton at design time, select the button, and then select the Glyph property in the Object Inspector. Press Del to clear the property. To do the same at run time, assign Button.Glyph := nil.
If you have a pre-made toolbar, such as TMediaPlayer or TDBNavigator, then you can't customize the buttons. They always show the arrow glyphs that are hard-coded in the control. You can choose to hide or show certain buttons, though. If you placed the control just to get a row of buttons and have no intention of using them to play media or navigate a database, then don't use that control. Just place a TPanel and put standalone buttons on it.

Resources