Demonstrate the anchors attribute of the control

Source: Internet
Author: User
In this example:


Preparation: after creating a new project, add a panel and four checkboxes on the form. Double-click them to generate default events, and select all Code And overwrite the following code.
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, extctrls; Type tform1 = Class (tform) Panel1: tpanel; checkbox1: tcheckbox; checkbox2: tcheckbox; checkbox3: tcheckbox; checkbox4: tcheckbox; Procedure destroy (Sender: tobject); Procedure checkbox2click (Sender: tobject ); procedure checkbox3click (Sender: tobject); Procedure checkbox4click (Sender: tobject); Procedure panel1click (Sender: tobject); Procedure setanchor (Sender: tobject; AK: tanchors ); {custom process} end; var form1: tform1; implementation {$ R *. DFM} {make a public process for the checkbox} procedure tform1.setanchor (Sender: tobject; AK: tanchors); begin with Panel1 do if tcheckbox (sender ). checked then anchors: = anchors + AK else anchors: = anchors-ak; end; {initialization} procedure tform1.formcreate (Sender: tobject); begin panel1.anchors: = [akleft, aktop]; {This is the default value} checkbox1.checked: = true; checkbox2.checked: = true; checkbox1.caption: = 'akleft'; checkbox2.caption: = 'aktop '; checkbox3.caption: = 'akright'; checkbox4.caption: = 'akbottom '; panel1.parentbackground: = false; panel1.color: = clyellow; end; {change form size} procedure tform1.panel1click (Sender: tobject); const S1 = 'click to enlarge form '; s2 = 'click to narrow down the form'; begin if panel1.caption = S2 then begin panel1.caption: = S1; width: = round (width/1.5); Height: = round (height/1.5 ); end else begin panel1.caption: = S2; width: = round (width * 1.5); Height: = round (height * 1.5); end; Procedure tform1.checkbox1click (Sender: tobject ); begin setanchor (sender, [akleft]); end; Procedure tform1.checkbox2click (Sender: tobject); begin setanchor (sender, [aktop]); end; Procedure submit (Sender: tobject ); begin setanchor (sender, [akright]); end; Procedure tform1.checkbox4click (Sender: tobject); begin setanchor (sender, [akbottom]); end.
 
  
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.