Three cases of C Builder button design
During the process of use, the most frequent visual component can be said to be the button. If you add some special display for the button when we design the program, then you will add a lot of taste to your application. The following author introduces three special image buttons to display special effects, and its operation is as shown in the following figure. First, implement the image button (start button in the figure) During the programming process, use the image creation button not only makes the color and shape change of the button but also do not need to write too much code, you can achieve the effect of halving. . Here are you to introduce how to use the image component design button. The steps to the design image button are as follows: 1. New window, inserted into an image component TIMAGE for creating a button and named image1; then add a TLABEL component to name Label1. 2. Specify the Picture property of the TIMAGE component as the original image file initially displayed. Set it to TRUE in which the AutoSize property is set to the image size. Setting its transperate attribute to true, making the TIMAGE itself a transparent background; ------------------------------- void __fastcall tform1 :: image2mousedown (Tobject * Sender, TMousebutton Button, TshiftState Shift, Int X , int y) {image1-> Picture-> LoadFromFile (".// START2.BMP"); // Load the image displayed when the mouse is pressed, the file name is start2.bmp} // This event handle is put into the mouse On the status of the button ------------------------------------- void __fastcall tform1 :: image1mouseup TOBJECT * Sender, TMouseButton Button, TshiftState Shift, Int x, int y) {image1-> Picture-> LoadFromFile (".// stt1.bmp"); // Mount the mouse to press the image displayed, the file name is START1.BMP} 4, write code that needs to be processed for the TIMAGE component's onclick event, that is, use the TIMAGE component as a button component. In this example, we just make programs display a title "You press the image button". Its code is as follows: void __fastcall tform1 :: image1click (TOBJECT * Sender) {label1-> caption = "You selected image button";} II, implement any shape of the button (such as any shape button in the figure) The button is a button of an irregular shape, and we use the image processing software to draw two irregular shaped buttons. One is a convex button a flat or concave button, and the remains of the remaining parts are the same. Then you can add OnMousedown, onMouseUp, and onclick events as described in the above example. Third, the implementation of the animated button animation button is still based on reasonable use of TIMAGE components. The basic implementation principle is to add a TTIMER component in the form to control the loop shift of the image, and then call the prior design continuous bitmap cycle. The process of the button clicked the post-handling event is still implemented by the ONCLICK event handle.
The actual steps are as follows: 1, add a TTIMER component in the form, and set its enabled attribute to true, set its interval property to 100; then add an image component for creating an animation button in the form TIMAGE And named image1; add a TLABEL component named label1. Specify the Picture property of the TIMAGE component as the image file initially displayed. Set it to TRUE in which the AutoSize property is set to the image size. Setting its transperate attribute to true, making the TIMAGE itself a transparent background; For example: int LoadFlag; 3, define the TTIMER component's ONTIMER event handle as follows: void __fastcall tform1 :: time1timal (TOBJECT * Sender) {showbtnimage (loadingflag);}: This event handle calls a user-defined function, which The function is displayed in accordance with the loadFlag value. The content showbtnimage is as follows: // ------------------------------------------- -------------------------------- Void TFORM1 :: ShowbTnImage (int N) {ified (loadingflag> 0 && loadingflag <6) // (1) {image1-> Picture-> LoadFromFile (".// btnimage3 -" INTTOSTR (N) ". BMP"); // (2) LoadFlag ; // (3)} else loadFlag = 1 ; // (4)} // ----------------------------------------- ---------------------------------- routine explanation: (1) Sentence is used to determine whether LoadFlag is in 1 On 6, this range is related to the number of images that requires the load, because now the six image string animation is used, so LoadFlag is limited between 1 and 6, so the benefit is that the Ontimer event can be made Each loaded image must be continuous and will not be repeated. (2) Instruments call the LoadFromFile method of the Picture object to load the image from the specified image file. (3) Increase the image display flag to ensure the next continuous image next time. (4) The sentence is when the LoadFlag flag exceeds the number of image files, so that it automatically returns to 1, that is, the next loaded image file must be the first image. Finally, the custom function is also available in the program header file as follows: Void ShowbTnImage (INT N); 4, writing event handles for the TIMAGE component to handle specific program events.