Mega Code Archive

 
Categories / Delphi / Examples
 

Make SwitchBar Like mIRCs SwitchBar

Title: Make SwitchBar Like mIRC's SwitchBar Question: How to make SwitchBar Like mIRC's SwitchBar Answer: Here're the ideas for make thing such mIRC's SwitchBar 1. SwitchButton can be created automatically when a MDI Child created 2. Can change Font Color's SwitchButton triggered by some objects in MDI Child Form (such as messages coming,etc...). We use TSpeedButton because i have no idea to change font color on TToolButton ;-) 3. SwitchButton can be down or up depend on MDI Child Form status (Active/Deactive) 4. These methods are not perfect but Work!!! 5. These must be simple and easy to use for beginner (i don't write it for expert!, because they already knew it :-) ); ------------------------------------------------------------------------------- 1st Step : -------------------------------------------------------------------------------- a. New Application (of course :-)) b. Make 2 Form, we named first Form with MainForm and save it as MainFormUnit.pas and the second Form with ChildForm and save as ChildFormUnit.pas c. Because we're going to make MDI Application, here're the properties for each form MainForm : i. FormStyle=fsMDIForm ChildForm : i. FormStyle=fsMDIChild d. If you want childForm raised when u need it (show when needed), you must set ChildForm as "Available Forms". e. Put TToolBar on MainForm, assume we named it with Toolbar1 f. Set Toolbar1 properties : i. Flat=True ii. Autosize=True iii. BorderWidth=0/1/2 - whatever g. Put TImageList on MainForm and named it with ImageList1, we will put an image/icon to SwitchButton. h. Add some images/icon to ImageList, whatever you want :-) ------------------------------------------------------------------------------ 2nd Step : All procedures and variables in ChildForm ------------------------------------------------------------------------------ a. Using SpeedButton (Don't forget to add Uses Buttons;) Declare this object and prototypes in public section Public DynaButton:TspeedButton; procedure createDyna(Sender:TObject); procedure clickDyna(Sender:TObject); b. Procedure for Create a SwitchButton procedure TChildForm.createDyna(Sender:TObject); var ximage:TBitMap; begin ximage:=TBitmap.create; Mainform.ImageList1.GetBitmap(0,ximage); //take image from ImageList1 DynaButton:=TSpeedButton.create(self); with DynaButton do begin Name:='ChildFormButt1'; Parent:=MainForm.ToolbAr1; caption:=ChildForm.caption; Constraints.MaxHeight:=20; //set height of button AllowAllUp:=true; left:=ComponentIndex*100; //set position Glyph:=ximage; GroupIndex:=9; //grouping button Width:=(10*length(DynaButton.caption)+10); OnClick:=ClickDyna; //call procedure when OnClick event triggered Flat:=true; down:=true; Transparent:=false; end; ximage.free; end; c. Procedure for onClick Event (ClickDyna) procedure TChildForm.clickDyna(Sender:TObject); begin dynaButton.down:=true; dynaButton.font.color:=clBlack; //Restore the color when Switch button clicked if WindowState=wsminimized then WindowState:=wsNormal else show; end; d. "OnActive" event in ChildForm procedure TChildForm.FormActivate(Sender: TObject); begin if dynaButtonnil then clickDyna(sender); end; e. Change Font Color's SwitchButton when something triggered eg. "OnChange" Event on Memo1 begin if not dynabutton.Down then DynaButton.Font.color:=clRed; //change this part for other color end; ok, that's it for Child Form now, how to make it happens -------------------------------------------------------------------------- 3rd Step : -------------------------------------------------------------------------- a. Call ChildForm begin Application.createForm(TChildForm,ChildForm); ChildForm.caption:='Test'; //Change this part ChildForm.CreateDyna(Sender); end; ------Finish--------------------------------------------------------------