Click here to Skip to main content
15,868,074 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have 3 Forms
base - contains two Panel (Panel1 and Panel2)
Immagini
Note - contain a TextBox

Note is usable from base and Immagini

the goal is to write text on TextBox both from base and from Images calling ShowNote

From base all ok
from Images it is executed but has no effect TextBox does not display the new text

[edit]
Added as a solution by the OP:
There are 3 modules A, B, C
A - container with Panel
B - displays thumbnails
C - manages the notes of each thumbnail
D - other managements that require C
the main one is A (form), B is a Panel on A (1 panel + 1 picturebox + 1 label , for each thumbnail)

at each click on a thumbnail, displays on C the notes where they can be modified.

the scheme is A->B->C , A->D->C, C is always next to A
C - has an event which is triggered at every Keys.Enter modification, which returns to A which takes care of writing the text on C - TexBox, same thing with D

to have a Form visualized inside a Panel, doesn't create problems, it is created and destroyed when needed, but it offers the advantage to create the controls in visual way and to position them (Panel, Button, Label), after all C# doesn't have a Frame control (TFrame in Delphi)

[/edit]

What I have tried:

using Note;
using Immagini;

namespace Base
{
    public partial class Form1 : Form
    {
        frmNote gesNote = new frmNote();
        frmImmagini gesImg = new frmImmagini();

 private void Form1_Load(object sender, EventArgs e)
        {
            //add form to panel2         
            gesNote.TopLevel = false;
            gesNote.Top = 0;
            gesNote.Left = 0;
            gesNote.Height = panel2.Height;
            gesNote.Width = panel2.Width;
            this.panel2.Controls.Add(gesNote);
            gesNote.Show();
            gesNote.BringToFront();

            //ok this show on textbox
            gesNote.ShowNote("first text");


            //add form a panel1           
            gesImg.TopLevel = false;
            gesImg.Top = 0;
            gesImg.Left = 0;
            gesImg.Height = panel1.Height;
            gesImg.Width = panel1.Width;
            this.panel1.Controls.Add(gesImg);
            gesImg.Show();
            gesImg.BringToFront();

            gesImg.ShowImg();
        }

---- Form Note -----
namespace Note
 public void ShowNote(string testo)
        {
            textBox1.Text = testo;
        }

---- Form Immagini -----
using Note;
namespace Immagini
{
    public partial class frmImmagini : Form
    {
        frmNote gesNote = new frmNote();

        public frmImmagini()
        {
            InitializeComponent();
        }

        public void ShowImg()
        {
            //TextBox no Note is changed but not visible 
            gesNote.ShowNote("new text");
        }
    }
}
Posted
Updated 23-Dec-20 21:37pm
v3

You don't appear to be passing any information between the forms.

Have a read of this series of Tips that will show you the right way to do this
Transferring information between two forms, Part 1: Parent to Child[^]
Transferring information between two forms, Part 2: Child to Parent[^]
Transferring information between two forms, Part 3: Child to Child[^]
 
Share this answer
 
Comments
Maciej Los 23-Dec-20 6:18am    
5ed!
CHill60 23-Dec-20 7:01am    
Thank you! Hopefully the OP will upvote OriginalGriff's Tips too :-)
Maciej Los 23-Dec-20 7:29am    
It's Christmas time, so we need to believe ;)
Merry Christmas, Caroline!
CHill60 23-Dec-20 10:58am    
And to you and yours Maciej!
BillWoodruff 23-Dec-20 16:53pm    
Voted #1: Did you even read the OP's code and realize what a mess it is ?
There is never a reason to add a Form to the Control Collection of another Form, or another ControlCollection inside a Form. Use a Panel, or a UserControl, instead.

You can set the 'Owner Property of a Form instance to another Form instance: that will ensure the "owned Form" always appears above the "owner Form" on the screen.

You need to describe what you want to achieve much more clearly. What is the main Form, what are the other Forms: how do you expect them to interact ?

In the form 'frmImmagini, you create a new 'frmNote which you never make visible/show; that's just one example of how confused your code is.

You need to get a good book on WinForms, and review the basic ideas and practices.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900