AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Contents · Computing

Visible and Enabled

Lessons 45–46 · 2 lessons · N. I. Taylaqov (general editor), A. B. Akhmedov, M. D. Pardayeva, A. A. Abdug‘aniyev, U. M. Mirsanov. Informatics and Information Technologies, Grade 10, 1st edition. “Extremum-Press”, Tashkent, 2017
45

Enabled and visible states of control objects

Textbook: pp. 98–101
GoalDistinguishes the Visible and Enabled properties, uses the logical values True/False and the not operation, and controls an application by hiding or disabling buttons.
New words
Visible: whether the object is shown on the window · VisibleEnabled: whether the object reacts to the user · EnabledTrue / False: the two values of the logical type · True / Falsenot: the operation that reverses a logical value · not
Explanation

Most controls have the properties Visible and Enabled; both are of the logical type and take only the value True or False. If Visible = False, the object is not shown in the window but still exists and the code can refer to it. If Enabled = False, the object is visible but greyed out and the user cannot work with it. With these two properties an application guides the user: it disables a button that is not needed now or hides it to save space. The not operation reverses a logical value, so the statement Label1.Visible := not Label1.Visible; shows and hides the text each time it is pressed. For an object to answer a click it must be both visible and enabled.

Property = FalseResult
Visiblethe object is not shown but still exists
Enabledthe object is visible but greyed out – cannot be used
💡 Where will I use this?
In real life

In an online application the “Send” button stays grey and cannot be pressed until all required boxes are filled in. Once they are filled, the button turns normal. This prevents sending an incomplete form.

Who uses it

Web and app developers, designers of bank forms and game menu designers switch off or hide unneeded buttons for a time.

Try it today

Write two “not yet” rules in your notebook, for example “the Next button stays grey until an answer is chosen”, and test each rule by asking a friend to play the user.

Worked examples
Pascal
1procedure TForm1.Button1Click(Sender: TObject);
2begin
3  Form1.Width := Form1.Width + 20;
4  if Form1.Width >= 500 then
5  begin
6    Button1.Enabled := False;
7    Button2.Visible := True;
8  end;
9end;
The window width is 400 and Button2.Visible = False. When Button1 is pressed – code above. At the fifth click the width becomes 400+5·20 = 500: Button1 greys out and Button2 appears.
Label1.Visible := not Label1.Visible; At the start the Label is visible (True). The 1st click hides it, the 2nd shows it; after an odd number of clicks it is hidden, after an even number it is visible. After 7 clicks the Label is hidden.
Class activity

“The hidden button”: in a two-button application the first button hides or shows the second; another pair predicts the state after 9 clicks.

Practice
1
Which property becomes False for an object to grey out?
2
The Label is visible. If switching with not is done 5 times, what is the state?
3
The window grows from 400 by +20 per click; Button1 is disabled when the width reaches 500. After how many clicks?
4
Why can code still refer to a hidden object?
Story of the Week · The Khwarizmi Way1000 readers in 7 rounds?Close the week: all of this week’s subjects in one storyRead →