Hi, there! Have a question right here.

I've been preparing a project (Periodic table of Elements), so user by clicking on elements can access to another form which showing the element properties. Also, the user can search the element based on name, atomic number, year of discovered, and sign.

Don't have a clue how to connect labels in one form with strings and integers in the other, also dunno how to code a "Search"; wanna make for example "a name" from one form appear in the other form's label by searching it by name. It should be easy. Could someone teach me how to have it done?

You noted that this is in "c" and to get a mouse, graphics and connecting the mouse click on such will be highly dependent on the libraries and IDE used. As such there can be no answer until more is revealed.

commented: The tag says c and the title says c# so ??? +14
commented: Sorry for making you confused, that's all in C#, Visual Studio. +0

Anyone here?

commented: I fixed the tag. As to the title, it was off screen but my bad for not checking the post and title. +15

You ask "how to connect labels in one form with strings and integers in the other,"?

But I don't know your design. It's not common to have more than one form active so given I don't know your design how about how to change a title in a function/method to a specific form element?

You probably have seen or should know how to use Me.title.text etc. So for when I need to change Form1's title while in a method or another form's code I would reference it like this" Form1.title.text = "What I want."

I received your message. Can you supply a pair of pared down code examples? One would be for the one form and the other would be for the second form then I could give you a single line example of how I change content on another form or get a value from the other form.

However this assumes both forms are active. If they are not then you may have to put the value or such into a global variable.

So, let me make my situation clearer. I have a first Form with Periodic Table itself, there are pictureboxes, by clicking on one of the elements, second Form pops up. I have a public class, which has the properties for every element:

First Form:

private void pictureBox236_Click(object sender, EventArgs e)

        element h = new element();
        h.name = "Hydrogen";
        h.number = 1;
        h.oxidationState = "+1";
        h.sign = "H";
        h.yearDiscovered = 1671;
        h.atomicMass = 1;
        h.electronConf = "1s1";
        h.picAddress = @"someDir.jpg";
        Form2 formm = new Form2(h.name,h.atomicMass.ToString(), h.number.ToString(), h.oxidationState, h.sign, h.electronConf, h.yearDiscovered.ToString(),h.picAddress);
        formm.Show();
}
      Second Form:

      public Form2(string name, string atomicMass, string number, string oxidationState, string sign, string electronConf, string yearDiscovered,string location )
    {
        InitializeComponent();
        label1.Text = name;
        label11.Text = atomicMass;
        label10.Text = electronConf;
        label9.Text = oxidationState;
        label8.Text = yearDiscovered;
        label7.Text = sign;
        pictureBox1.ImageLocation= location;
        pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
    }

        Then, I came up with List<>, do I have to use FOR loop for it, I don't know:

        class eachElement
{
    public static IList<element> H1 = new List<element>() {

            new element()
        {   name="Lithium",
            atomicmass=6.94, **"number=3,"**
            oxidationstate = "+1",
            sign="Li",
            yeardiscovered=1817,
            electronconf="2s1",
            picaddress=@"C:\Users\bobou\Documents\GitHub\groupproject\Periodic Table\Periodic Table\images\Li3.jpg"
        }

        There's a third Form, which a user can access by clicking on "Search" button in the first Form; with labels and textboxes for them, and "Search" button. Also, there's a groupbox below them, where some element should pop up instead of labels by searching (atomic number, sign etc). I just don't know how to connect them, a code which would make labels' text in groupbox (there are labels in groupbox) change the text itself.

While the code is OK, it's not pared down to the minimum but I understand why.

So to reference an item on another form the format is simple once it sinks in.

form_name.theobject.thevalue

You do this on line 18 sans the form name. So to get or set the object text the full name of the object and value of line 18 is:
Form2.label1.Text

To set that it from form1 or another form would be:
Form2.label1.Text = "Message from Earth!";

To get the text this would be:
somestring = Form2.label1.Text

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.