ActiveElementsOverlay sample code - new buttons - interface

I’m looking for a very simple solution, based on ActiveElementsOverlay sample:

  1. Button1 in top left corner of the camera box in Smart Client
  2. After clicking Button1 two new buttons appear: Button2 and Button3 (under Button1)
  3. When I click Button2 or Button3, Button2 and Button 3 disappears.

In general, looking for help with building interface. Of course I’ll add more actions, but just need help with simple sample code that I can use and add new features. I work in c# in visual studio.

I’d really appreciate if someone can send me sample code I can reuse and implement in my solution.

Thanks!

When you have installed the MIP SDK you have the sample source code in your hard drive.

See - https://developer.milestonesys.com/s/article/About-Milestone-software-development-Kit-SDK-download-link-For-MSP

Thanks, but this is not answering my question. Need similar example to one described above.

In example below I can change “CONTENT” for bbt button object:

private void bbt_Click(object sender, RoutedEventArgs e)

{

var bbt = sender as Button;

bbt.Content = “TEST”;

}

bbt.Content = “TEST”;

but how can I change content for other buttons, defined in my code? For example, another button name is “action1”?

action1.Content = “TEST”;

It looks like I need to add some prefix before referring to “action1”, because otherwise it’s not visible and generates:

CS0103 The name ‘action1’ does not exist in the current context

I think that you need to save a reference for your “action1” button in a object so that you can use it.

Thank you Rie - can you provide an example based on my code above?

My base is ActiveElementsOverlay sample code, it would be great if you can help me with that.

This modification to the sample works for me.

private void Button_Click(object sender, RoutedEventArgs e)
{
	var button = sender as Button;
	var imageViewerAddOn = _imageViewerAddOnButtons.First(keyValuePair => keyValuePair.Value == button).Key;
	//if ((Guid)button.Tag == Guid.Empty)
	//{
	//    button.Tag = AddBorder(imageViewerAddOn);
	//}
	//else
	//{
	//    imageViewerAddOn.ActiveElementsOverlayRemove((Guid)button.Tag);
	//    button.Tag = Guid.Empty;
	//}
	AddButton2(imageViewerAddOn);
}
 
private Guid AddButton2(ImageViewerAddOn imageViewerAddOn)
{
	var button2 = new Button()
	{
		Content = "New button",
		Width = 150,
		Height = 30,
		Background = Brushes.Transparent,
		Margin = new Thickness(0, 10, 10, 0)
	};
	Canvas.SetLeft(button2, 100);
	Canvas.SetTop(button2, 250);
	button2.Click += Button2_Click;
	return imageViewerAddOn.ActiveElementsOverlayAdd(new List<FrameworkElement> { button2 }, new ActiveElementsOverlayRenderParameters() { FollowDigitalZoom = true, ShowAlways = true, ZOrder = 2 });
}
 
private void Button2_Click(object sender, RoutedEventArgs e)
{
	MessageBox.Show("Click");
}

Thank you Bo - this is really helpful.

Let’s say, that I’ll create 3 buttons this way - how to make three of them disappear after clicking at least one of them (let’s say that buttons are named b1, b2, b3, when I click on any of them, b1, b2, and b3 disappears).

New modification to the sample.

I introduced another dictionary.. I hope you can make sense of it, I wonder if it could have been made simpler.

private Dictionary<Button, Button> _parentButton = new Dictionary<Button, Button>();
 
..
 
private void Button_Click(object sender, RoutedEventArgs e)
{
	var button = sender as Button;
	var imageViewerAddOn = _imageViewerAddOnButtons.First(keyValuePair => keyValuePair.Value == button).Key;
	List<Guid> extraButtons = new List<Guid>();
	extraButtons.Add(AddButtonExtra(imageViewerAddOn, 1, button));
	extraButtons.Add(AddButtonExtra(imageViewerAddOn, 2, button));
	button.Tag = extraButtons;
}
 
private Guid AddButtonExtra(ImageViewerAddOn imageViewerAddOn, int extraNumber, Button parentButton)
{
	var buttonExtra = new Button()
	{
		Content = "New button",
		Width = 150,
		Height = 30,
		Tag = extraNumber,
		Background = Brushes.Transparent,
		Margin = new Thickness(0, 10, 10, 0)
	};
	Canvas.SetLeft(buttonExtra, 100 * extraNumber);
	Canvas.SetTop(buttonExtra, 250);
	buttonExtra.Click += Button2_Click;
	_parentButton.Add(buttonExtra, parentButton);
 
	return imageViewerAddOn.ActiveElementsOverlayAdd(new List<FrameworkElement> { buttonExtra }, new ActiveElementsOverlayRenderParameters() { FollowDigitalZoom = true, ShowAlways = true, ZOrder = 2 });
}
 
private void Button2_Click(object sender, RoutedEventArgs e)
{
	Button thisButton = sender as Button;
	int? tag = (sender as Button).Tag as int?;
	int number = tag ?? 0;
	
	MessageBox.Show("Click on button number "+ number);
 
	// removing the two extra buttons again
	Button parent = new Button();
	if (_parentButton.TryGetValue(thisButton, out parent))
	{
		var imageViewerAddOn = _imageViewerAddOnButtons.First(keyValuePair => keyValuePair.Value == parent).Key;
		List<Guid> extraButtons = parent.Tag as List<Guid>;
		foreach(Guid extraButton in extraButtons)
		{
			imageViewerAddOn.ActiveElementsOverlayRemove(extraButton);
		}
	}
}

Hi Bo, this code works really great. Thank you! I was able to implement it into my solution, added 6 more buttons etc.

I’d like to use the same solution for another button on the same project. When I tried to duplicate the code, it started generating errors (inside smart client, not in Visual Studio, it’s hard to debug).

Can you guide me how to transform your solution to work on two or even three different buttons?

So we have two buttons A and B:

  1. When I click on A it displays button A1 & A2, after click they disappear (same as in existing example, no change required)
  2. When I click on B it displays B1, B2, B3 … Bx and behaves same like in #1

So in general, I need to duplicate your functionality. I’d really appreciate your help on that. Thanks!

You need to rethink how you use dictionary to save the button objects, you need to make it in a way to so that a child button knows the parent button.

PS. Might not be as hard to debug as you might think, try to see this article, specifically the chapter about debugging from Visual Studio.. https://developer.milestonesys.com/s/article/debugging-techniques-for-Smart-Client-plugins

Bo, is there a chance you can reply to my last post anytime soon? I need to have this functionality up and running today. It’s super important.

Thanks!

Peter Moscicki
KnowFalls.com

Thanks Bo, I need a little more guidance regarding dictionary. In existing example there is:

private Dictionary<Button, Button> _parentButton = new Dictionary<Button, Button>();

Should I add another “, Button” or rather create another dictionary entry with _parentButton2 like:

private Dictionary<Button, Button> _parentButton2 = new Dictionary<Button, Button>();

Thanks!

Bo, is there a chance you can reply to my last post anytime soon? I need to have this functionality up and running today. It’s super important.

Thanks!

I guess I should have explained instead.

The task is to be able to reference child buttons from parent buttons and vice versa, and every time you have a button find the references ImageViewerAddOn and Guids for the buttons as ShapesOverlay / FrameworkElements.

This draft is more extensible, but please do not use it, please understand it and implement something better..

http://download.milestonesys.com/MIPSDK/Samples/ActiveElementsOverlayBackgroundPlugin.zip