Mega Code Archive

 
Categories / Delphi / Forms
 

How to make your own title bar

Title: How to make your own title bar Question: How to make a different title bar? Answer: I made it on Delphi 5, but should work on older versions. Create a new form and set the property BorderStyle to bsNone. Insert an image named image1 - it will be the close button. Insert an image named image2 - it will be the title bar. Insert an image named image3 - it will be the minimize button. Insert an lable named label1 - it will be the title. If you want your title bar to look exactly like the windows title bar, then you will have to arrange the images all on the same roll and make some nice images for them. To make the label you will have to put it exactly over the bar, make it the same size as the bar, set the autosize of lable1 to false, set the Transparent to true and that's all. Thanks to Shannon(ICQ 5488969), We have a new very short version of this article: procedure TForm1.Image4MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if button = mbleft then //checks if left mouse button is down begin ReleaseCapture; Perform(WM_SYSCommand, $f019,0); //sends a command for moving //the form. Notice that $f019 is the hexdecimal value of SC_Move //(61456), but it not the same with SC_MOVE... end; end; That's All! Put this code in the mousedown event and you are done. This is my old article (My ICQ is 57662198): ....... var mdown:boolean; pos:TPoint; procedure TForm1.Image1Click(Sender: TObject); begin application.Terminate; end; procedure TForm1.Image3Click(Sender: TObject); begin Application.Minimize; end; procedure TForm1.Image2MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin mdown := false; //the user isn't holding down the left mouse btn end; procedure TForm1.Image2MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin mdown := true; //the user is holding down the left mouse button GetCursorPos(pos); //Get the position of the cursor at the momment when the user //clicks on the bar (the mouse hasn't made a move yet) end; procedure TForm1.Image2MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); var mouse:TPoint; A,B :integer; begin //check if the user is holding down the mouse button if mdown = true then begin //get the possible new position of the cursor GetCursorPos(mouse); //get the difference between the last mouse move and this one A := mouse.X - pos.x; B := mouse.Y - pos.y; form1.left := form1.left + A; //set the new left position form1.top := form1.top + B; //set the new top position GetCursorPos(pos); //get the mouse position end; ........