AddToolButton problem with June 21st build

Stimulsoft Reports.NET discussion
Post Reply
Mark Smith
Posts: 37
Joined: Tue Jun 13, 2006 8:59 am
Location: Yorkshire, UK

AddToolButton problem with June 21st build

Post by Mark Smith »

Hi -

I'm having a problem getting my buttons to show up.

Code: Select all

StiStandardToolbarService stdToolbar = StiStandardToolbarService.GetService(Designer);
stdToolbar.AddToolButton(this.imageList1, 17, "Open Report..", new System.EventHandler (this.mbiFileNewReport_Activate));
doesn't show the button. The old .Add (ref, etc... ) method worked fine but that is now protected.

Additionally, I'm seeing a crash when the application closes, even when my toolbutton is not installed:

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
at Stimulsoft.Report.Design.Toolbars.StiToolbarService.GetToolbarServices(StiDesigner designer)
at Stimulsoft.Report.Design.StiToolbarOrderHelper.OrderToolbars(StiDesigner designer)
at Stimulsoft.Report.Design.StiDesigner.OnOrderToolbarsClick(Object sender, EventArgs e)
at Stimulsoft.Report.Design.StiDesigner.InvokeOrderToolbars()
at Stimulsoft.Report.Design.StiDesigner.OnSizeChanged(EventArgs e)
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

AddToolButton problem with June 21st build

Post by Edward »

Mark wrote:

Code: Select all

StiStandardToolbarService stdToolbar = StiStandardToolbarService.GetService(Designer);
stdToolbar.AddToolButton(this.imageList1, 17, "Open Report..", new System.EventHandler (this.mbiFileNewReport_Activate));
Please describe us in more details what is 'Designer'? Is it a StiDesignerControl?
Mark wrote:doesn't show the button. The old .Add (ref, etc... ) method worked fine but that is now protected.
Please inform us about the name of that method which is now inherited.

Thank you.
Mark Smith
Posts: 37
Joined: Tue Jun 13, 2006 8:59 am
Location: Yorkshire, UK

AddToolButton problem with June 21st build

Post by Mark Smith »

Hi Edward.

Yes, Designer is the StiDesigner instance associated with a report.

In the 2007.1 release, class StiToolbarService had a method called Add which was public. It allows one to add a button to a tool bar though the method signature was a bit weird.

At some point since 2007.1, you've changed the StiToolbarService class to make the Add method protected, and added AddToolButton to provide the same functionality. It is these changes which don't work.

I've reverted to 2007.1 now since that works.

Vital
Posts: 1278
Joined: Fri Jun 09, 2006 4:04 am

AddToolButton problem with June 21st build

Post by Vital »

Sorry, but method Add in release 2007.1 is protected. Please see source code of 2007.1:

Code: Select all

protected void AddToolButtonSeparator()
		{
			StiToolButton toolButton = new StiToolButton();
			toolButton.Size = new Size(6, 22);
			toolButton.Dock = DockStyle.Left;
			toolButton.Style = ToolBarButtonStyle.Separator;
			ToolBar.Controls.Add(toolButton);
			ToolBar.Controls.SetChildIndex(toolButton, 0);
		}


		protected void Add(ref StiToolButton button, string hint, EventHandler handler)
		{
			Add(ref button, null, -1, hint, handler);
		}

		
		protected void Add(ref StiToolButton button, ImageList imageList, int imageIndex, string hint,
			EventHandler handler)
		{
			button = new StiToolButton();
			button.Size = new Size(22, 22);
			button.Dock = DockStyle.Left;
			button.ImageList = imageList;
			button.ImageIndex = imageIndex;
			button.HotDragDrop = true;
			button.Click += handler;
			
			ToolBar.Controls.Add(button);
			ToolBar.Controls.SetChildIndex(button, 0);
			Designer.ToolTip.SetToolTip(button, StiHint.CreateHint(hint));
		}


		public void AddToolButton(ImageList imageList, int imageIndex, EventHandler eventHandler)
		{
			AddToolButton(imageList, imageIndex, string.Empty, eventHandler);
		}

		
		public void AddSeparator()
		{
			AddToolButton("-", null);
		}

		
		public void AddToolButton(string text, EventHandler eventHandler)
		{
			AddToolButton(null, -1, text, eventHandler);
		}

		
		public void AddToolButton(ImageList imageList, int imageIndex, string text, EventHandler eventHandler)
		{
			if (this is StiToolboxToolbarService)
				throw new Exception("You can't add Tool Button to StiToolboxToolbarService!");
			if (ToolButtons == null)ToolButtons = new ArrayList();
			ToolButtons.Add(
				new StiToolButtonInfo(imageList, imageIndex, text, eventHandler));
		}
Mark Smith
Posts: 37
Joined: Tue Jun 13, 2006 8:59 am
Location: Yorkshire, UK

AddToolButton problem with June 21st build

Post by Mark Smith »

Hi Vital -

With respect, I'm using a binary file labelled 2007.1, where the Add method is accessible. The date I see on it is 18/5/2007 which is probably wrong.

More to the point, the code works. The new equivalent which I've shown, does not work. If you can please demonstrate to me how to add buttons to your toolbar in a later build that works, I can move forward.

Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

AddToolButton problem with June 21st build

Post by Edward »

In the current realization of the StimulReport.Net you can add a custom button on the StandardToolBar of the StiDesignerControl only before creating of that control.

via the following code:

Code: Select all

StiStandardToolbarService stdToolbar = StiStandardToolbarService.GetService();
stdToolbar.AddToolButton(this.imageList1, 17, "Open Report..", new System.EventHandler (this.mbiFileNewReport_Activate));
Thank you.
Post Reply