M
M
Morrowind2021-12-07 17:41:06
C++ / C#
Morrowind, 2021-12-07 17:41:06

How to draw an element in a picturebox in Winform?

Hello.

There is such a hitch. I can't draw an element in a picturebox if I'm not doing it from the main Winfom window.
Let me explain:
There is a main form and when you click on the button, a square is drawn in an empty white field. The code is attached to the button
61af70e9ed3db836389300.png

(carefully pseudocode)

Object.AddFigure<Фигура>(тут указываются Point для позиции);


I need to reach this code from the form an order of magnitude lower.
When you click on Load, draw a shape.
61af7114d637c011234760.png

And here the problems begin: Unfortunately , I cannot reach the code in the main form ( Object.AddFigure<Figure> ) from the private void button1_Click(object sender, EventArgs e) method. Because there is no class instance. Creating a new instance spawns a new main window window (and this option is not needed). (If there is no other, then I don’t understand how to bang the old window). Please suggest options. I also have an assumption that the figures are drawn, but I do not update the form or window correctly. don't help.

Update() ResetText() Application.Restart()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Morrowind, 2021-12-07
@hekkaaa

As a Variant solution through events proposed by edward_freedom
The solution that was suggested to me is simpler.
When creating a form, on button click, toggles this . This is the main implicit form Form1 itself, which we can finally use later. Next, in the most child form with buttons, we make a field and assign a value to it. And TADAAM we can call the field and access the methods of Form1 .
var createform = new LoadProject(this);

Form1 _main; // Поле

        public LoadProject(Form1 main)
        {
            InitializeComponent();
            _main = main;
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question