Download presentation
Presentation is loading. Please wait.
1
C++ programming in Windows environment
Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 37./0. C++ programming in Windows environment Position adjusters and indicators in the program ScrollBar control TrackBar control ProgressBar control UpDown control Demonstration program on position adjusters and indicators
2
Department of Information Engineering INFORMATION TECHNOLOGY dr
Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 37./1. ScrollBar control The scroll bar is used to scroll in the window the contents that cannot see fully in the window. Its parts are the slider, bar and scrolling buttons. The scroll bar can be handled by mouse or keyboard equally, it has the suitable event handlers. Its orientation can be vertical or horizontal, depending on the value of Kind property. The interval of movement of the content to be scrolled has to scaled to the range of the moving of the slider setting the values for the Min and Max properties. The actual position of slider between Min and Max can be written or read by the Position property. The position will change by steps determined by the value of SmallChange if the scrolling buttons are used. At paging, so clicking between the slider and scrolling buttons or scrolling by the PgUp, PgDn keys the position changes by value of LargeChange property. When changing the position an OnChange event happens. The skeleton of this function can be created double clicking on the scroll bar component. To generate this event the position can be changed by mouse, by keyboard or from program. In the event handler the new position of the scrollable content has to be calculated and set.
3
Department of Information Engineering INFORMATION TECHNOLOGY dr
Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 37./2. The continuously changing value caused by the continuous moving can be used for other purpose too, e.g. rotating an object, performing movements. The scrollbar is controlled by an inner timer. The Min, Max and Position properties can be set all at once calling the SetParams( ) method. Information on the position of slider or manner of scrolling can be get in the OnScroll event handler function. TrackBar control The control that reminds to a scale of an instrument is suitable for controlling or indicating a value which can change in an interval. Its most important property is the location of the pointer that can be written or read by the Position property. The Orientation can be horizontal and vertical. The interval of scale determined by Min and Max properties, and a visually emphasized subrange can be given inside by SelStart and SelEnd properties. The side of the scale determined by TikMarks, the style by TickStyle property. The density of scale can be set by Frequency.
4
ProgressBar control UpDown control
Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 37./3. ProgressBar control The progress bar suitable for indicating the state of processes taking place in time. Its most important property is the Position, that can take values between Min and Max limits. The newer segment determined by Step property appears calling the StepIt( ) method. The value of Position can be increased with arbitrary step calling the StepBy( ) method. The value of Smooth property determines the continuous or segmented form. UpDown control This control is suitable for incrementing or decrementing the value of the Position property by a given integer value. The step is stored in the Increment property. It can be associated to an Edit control by Associate property. After association the position can be entered or stepped using the buttons. The Position can be read or modified from program too. Its value has to be between Min and Max. The most important event handler is the OnClick. The Orientation determines its direction.
5
Demonstration program on position adjusters and indicators
Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 37./4. Demonstration program on position adjusters and indicators The task: make a program that can be characterised by the next window!
6
Department of Information Engineering INFORMATION TECHNOLOGY dr
Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 37./5. The red wheel can be rolled to the left or to the right by the ScrollBar, by the TrackBar or by modifying the UpDown control. The Pointer of the TrackBar indicates the actual height of the centre of the white Fleck, the slider on the ScrollBar moves parallel to the vertical position of the Wheel, while the ProgressBar measures the passed from the starting of the program time. Solution: 1. Create a new folder and save into this a newly opened empty application using Slider.prj name. 2. Place the required controls on the Form, give the sizes and positons according to the given figure of the window. The task of the Timer component is to call in every 5 seconds its OnTimer( ) event handler function and to actualise the progress indicator in this function. The Wheel and the Fleck are TShape components. Their Shape property is set to stEllipse. The Color of the Brush property of the Wheel is set to clRed The black base bar is a TShape type component and its Shape property has a stRectangle value
7
The Form after placing the components:
Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 37./6. The Form after placing the components:
8
4. We will need some global variables, define them after the
Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 37./7. 3. The Orientation property of TrackBar component has to be set to trVertical value. 4. We will need some global variables, define them after the TForm1 *Form line: int position,Dx,Dy,dx,dy,R,r; double angle; The position is the parameter of the motion, can have a value from the interval. Its value corresponds to the length of the distance covered by the Wheel, as the radius of Wheel is equal to 100. 5. The computations require the sin, cos, acos functions that have been defined in the math.h headerfile. Insert this file under the line including the Unit1.h header file: #include "math.h” 6. The BorderStyle property of the Form has bsDialog value, the ReadOnly property of the Edit1 is true. 7. Give the Captions for the components as shown in the figure, and modify it for ScrollBar, TaskBar and ProgressBar demonstration program for the Form.
9
8. Set the Font property of the main title to 10 point bold value.
Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 37./8. 8. Set the Font property of the main title to 10 point bold value. 9. Rename some components: Shape1 --> ShapeWheel Shape2 --> ShapeFleck Shape3 --> ShapeBase. 10. Though most of these initialisation values could be set in the Object Inspector too, give them now in the constructor of the Form: __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { Dx= 113; Dy= 120; //shift relative to the corner of the window dx= 201; dy= 208; //starting centre of Wheel - r: Dx+R-r; Dy+R-r R= 100; r= 12; //radiuses UpDown1->Position= 157; UpDown1->Min= 0; UpDown1->Max= 314; //continued Dx, Dy dx,dy
10
ScrollBar1->SetParams(157,1,314);
Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 37./9. ScrollBar1->SetParams(157,1,314); ScrollBar1->SmallChange = 1; // fine stepping interval ScrollBar1->LargeChange = 10; // big stepping interval TrackBar1->Position=100; TrackBar1->Min= 0; TrackBar1->Max= 200; // for displaying only TrackBar1->SelStart= r; TrackBar1->SelEnd= 2*R-r; TrackBar1->PageSize= 4; TrackBar1->Frequency= 4; ProgressBar1->Min= 0; ProgressBar1->Max= 600; // 5 minutes (600/10 * 5 sec) ProgressBar1->Width= 600; // 2 pixel in the drawing == 1 sec ProgressBar1->Step= 10; // 1 step==10 pixel == 5 sec ProgressBar1->Position= 0; Timer1->Interval=5000; // 5 sec Timer1->Enabled= true; // it starts with the program }
11
ScrollBar that reflects to the change of the position of the slider:
Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 37./10. 11. The most important function is the OnChange( ) event handler of the ScrollBar that reflects to the change of the position of the slider: void __fastcall TForm1::ScrollBar1Change(TObject *Sender) { // Reading out the position of the slider: position= ScrollBar1->Position; Edit1->Text= position; // displaying // Positioning the Wheel: ShapeWheel->Left= Dx+position; // really it slides only… // Positioning the Fleck: angle= (double)position/R; ShapeFleck->Left= dx+position-(int)(R-r)*sin(angle); ShapeFleck->Top= dy+(int)(R-r)*cos(angle); TrackBar1->Position= R+(int)(R-r)*cos(angle); // slider } The turning of the Wheel is made sensible by moving of Fleck. The Pointer is set to the middle of height of white Fleck here too.
12
void __fastcall TForm1::Timer1Timer(TObject *Sender) {
Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 37./11. 12. The Timer gives alarm at every 5 seconds and calls its OnTimer( ) event handler function: void __fastcall TForm1::Timer1Timer(TObject *Sender) { ProgressBar1->StepIt(); // actualises the progress bar } 13. Clicking on one of the buttons of the UpDown control its OnClick() event handler function is invoked that increments or decrements the position motion parameter depending on the button was pushed: void __fastcall TForm1::UpDown1Click(TObject *Sender, TUDBtnType Button) if (Button == btNext) position++; else position--; ScrollBar1->Position= position; // Initiates all the activities, } // because means OnChange event at the ScrollBar!
13
void __fastcall TForm1::TrackBar1Change(TObject *Sender) { int sv;
Department of Information Engineering INFORMATION TECHNOLOGY dr. László Dudás 37./12. 14. Finally program that case when the Pointer of the TrackBar is moved up and down by mouse and because of this have to move everything: Wheel, Fleck, ScrollBar, Edit1 numerical display. The vertical position of the Pointer will be converted to position value and using this will be activated the OnChange( ) event handler of the ScrollBar, that moves everything:. void __fastcall TForm1::TrackBar1Change(TObject *Sender) { int sv; sv= TrackBar1->Position; if (sv<12) sv=12; if (sv>188) sv=188; angle= acos((double)(sv-R)/(R-r)); position= (int)(R*angle); ScrollBar1->Position=position; // Initiates all the activities. } 15. The program works well, though some refinement possibilities are there, e.g. the Timer is not stopped, the application will stop it, the Edit1 field can not get entries and move the Wheel such manner, the usability of keyboard is not checked, etc.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.