0

I want to label or image on a factory map. When I click on this tag, I want to open the camera in that region. My points (labels) on the factory map should be erasable, movable, clickable. It is impossible to do this with DrawImage. Instead of using graphic draw image as an alternative way, I want to create a dynamic label and affect the image of the fixed size picturebox. But I can't assign 'pictureBox.Image' to the parent property for the label.

Where am I making mistakes. The picture box should be fixed and the picture in it should be zomable. But the label acts separately from the image. I request your help.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using Cyotek.Windows.Forms.Properties;


namespace Cyotek.Windows.Forms
{

internal partial class ScaledAdornmentsDemoForm : BaseForm
{
    #region Instance Fields

    //private List<Point> _landmarks;
    private List<Label> _landmarks;

    private Bitmap _markerImage;

    #endregion

    #region Public Constructors

    public ScaledAdornmentsDemoForm()
    {
        InitializeComponent();
    }

    #endregion

    #region Overridden Methods

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        imageBox.ZoomToFit();

        _markerImage = Resources.circle_24;
        _landmarks = new List<Label>();
        this.AddLabel(new Label() { Text = "", BackColor = Color.Transparent, Location = new Point(467, 447), Parent = imageBox, Image = _markerImage });
        this.AddLabel(new Label() { Text = "", BackColor = Color.Transparent, Location = new Point(662, 262), Parent = imageBox, Image = _markerImage });
        this.AddLabel(new Label() { Text = "", BackColor = Color.Transparent, Location = new Point(779, 239), Parent = imageBox, Image = _markerImage });
    }

    #endregion

    #region Private Members

    private void AddLabel(Label label)
    {
        Debug.Print("Added label: {0}", label);
        //label.Location = new Point(label.Location.X - (label.Size.Width / 2), label.Location.Y - _markerImage.Size.Height);
        // imageBox.Controls.Add(label);
        _landmarks.Add(label);
    }

    #endregion

    #region Event Handlers

    private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
    {
        //AboutDialog.ShowAboutDialog();
    }

    private void closeToolStripMenuItem_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    private void imageBox_MouseClick(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Right)
        {
            if (imageBox.IsPointInImage(e.Location))
            {
                this.AddLabel(new Label() { Text = "", BackColor = Color.Transparent, Location = e.Location, Parent = imageBox, Image = _markerImage });
            }
        }
    }

    private void imageBox_Paint(object sender, PaintEventArgs e)
    {
        Console.WriteLine();
        foreach (Label label in _landmarks)
        {
            label.Location = imageBox.GetOffsetPoint(label.Location);
            //imageBox.Controls.Add(label);
            //e.Graphics.DrawImage(_markerImage, new Rectangle(location, markerSize), new Rectangle(Point.Empty, _markerImage.Size), GraphicsUnit.Pixel);
        }
    }
    #endregion

 
}
}
MSM
  • 101
  • 5
  • You need a) a [moveable](https://stackoverflow.com/questions/50714327/edit-points-of-freeshape/50718793?r=SearchResults&s=1|32.9986#50718793) Label and b) a function to [scale](https://stackoverflow.com/questions/51138565/how-to-measure-length-of-line-which-is-drawn-on-image-c-sharp/51140133?r=SearchResults&s=4|31.7959#51140133) the Location up and down with the zooming. – TaW Jul 24 '20 at 15:02
  • I don't think I will see my job. – MSM Jul 27 '20 at 10:22
  • I don't understand. – TaW Jul 27 '20 at 14:25

0 Answers0