developers I'm new in c# .. i want to make periodic table .. but prob is i don't know how to make that periodic chart .. :( .. i i even dont know which section should i read to learn how make that chart ... i want to place picture of element to each box of table (like ca, Na,k bla bla) and when palce mouse over it ..it should displace info about each element in corner pic ...

i can handle last query by mouse over event ... but how to make chart with with element pic with mouse over event

if your dont know what periodic table is please click on the link below


5 Years
Discussion Span
Last Post by MORFIOUS
Featured Replies
  • 1

    I would create a class that holds each element and the information that you need about that element. Then I'd create a class that knows how to display that information and generate a tooltip on mouseover. Then I'd put them on a form :) Read More

  • 1
    __avd 1,826   5 Years Ago

    @morfious90 Please provide evidence of having done some work yourself if posting questions [URL="http://www.daniweb.com/forums/faq.php?faq=daniweb_policies"]from school or work assignments.[/URL] Similar thread : [url]http://answers.yahoo.com/question/index?qid=20110830135629AADCKGi[/url] Read More

  • Done it! Here is the code, jsut copy and paste it into a brand new project (attention, change project name, so you wont copy complete code of mine to yours created project!!) You dont need to put anything on the form - keep it empty. Code: [CODE] using System; using … Read More


I would create a class that holds each element and the information that you need about that element. Then I'd create a class that knows how to display that information and generate a tooltip on mouseover. Then I'd put them on a form :)


If you know something about WPF you could design a button with label for atom symbol, atomic number etc.


basicly i want to do that in windows application,, so please let me know which topic should i read to make graph that each box can have picture off element and when i mouse over the element ,in another corner another pic should describe its info ....

and when i click on that box(element ) another page should be open in right hand side with full info ....

please let me know which topic should i study to do so .. please guide me ....m here to learn i know basics .....i need it in only C# windows application thanks


m not in school yeah i posted it on yahoo too to get answer o what wrong ?? its not assignment also .. i want to make it bcoz my friend know enough about periodic table .. and i want to make software with his chemistry knowledge, it just for fun or can say curiosity to learn ... i have asked this question to yahoo too .. please dear ans if u can ....


Have you ever seen a picture of the noble gas elements like Helium, Neon, Argon, Krypton, Xenon and Radon? they are as visible as Nitrogen and Oxygen etc. It is of course a noble (no pun intended) cause to help out your friend, but show us some of your code a we will try to help you out. :)


You should read up on how to make User Controls. You can compose these of the controls you want and then add them to your form as though they are a single control (like a button or textbox etc.)

Google and MSDN will help you in your quest ^^


I would do as Momerat h said. Create a class of one Element, and then create a List<T> which will hold the list of all elements. Class will hold data (properties) specific for each element (Name, Shortname, Number, (and position maybe, because the periodic table is not simetric - for example H is on top left, He is on top right)).
Next, to create a physical table, I would personally choose or labels or buttons. Create one by one, position it (based on the Position property from the element list<T> and place it on the form.
If you need any help, let me know.


@Momerath: Looking foreward for the event! Your code snippets are always great and I learn alot from them! :)

Edited by ddanbe: n/a


I was bored last night so I created a periodic table form control. Maybe I'll post the code sometime :)

Damn... I forgot to make it. I promised, but completely forgot it.
Will do my version. And looking forward to see yours Momerath.


You all seem to have far too much spare time!
I look forward to all solutions as they will undoubtedly demonstrate some new technique that I can admire (and copy;)).


:) too much time? hmm, this would be a nice debate to talk about...
No, not too much time, just didnt do anything like it before. But to create a decent Periodical table, its not that simple task. I was thinking of creating a file (*.txt) which will hold of the data, and then just reading it to create the table.
If you want to create the table just by the code, there will be too much of work and too much of the code, because there is nothing "simetrical" about this table.

From the beginning there is a bit more work to create the file (to insert all the data), but when this is done, its only a few minutes of work with the code to make it work.


This is indeed not a so easy job, consider for example this
To display the table, I would consider a matrix of ints, stored as a resource in the program. I would fill it with the atomic numbers or zero for places in the table that are "empty", like the "place" right of Hydrogen and above Beryllium. To display the periodic table I would for-loop through my matrix and with the help of the atomic number I can find the info I need out of a List with elementinfo.
Or is all this a bad idea?


Just did one hell of a job. Did the whole text file with all required data for 118 elemetns.
Now lets create an application which will draw the periodical table :)


Done it!
Here is the code, jsut copy and paste it into a brand new project (attention, change project name, so you wont copy complete code of mine to yours created project!!)
You dont need to put anything on the form - keep it empty.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Sep05_PeriodicalTable  //CHANGE TO YOUR NAMESPACE!!!
    public partial class Form1 : Form
        List<ElementData> elementsList;
        List<LegendData> legendList;
        Button[] elebuttons;
        Button[] legButtons;

        public Form1()
            string fileName = "PeriodicalTable.txt";
            string path = Environment.CurrentDirectory;
            path = Path.Combine(path, fileName);

            //creating new list<T>:
            elementsList = new List<ElementData>();
            legendList = new List<LegendData>();

            //reading file line by line and adding data into list<T>:
            string type = null;
            foreach (string data in ReadingData(path))
                if (data == "ELEMENT_LIST")
                    type = "elements";
                else if (data == "LEGEND")
                    type = "legend";

                if (type == "elements")
                else if (type == "legend")
            //Creating phisical periodical table from the data:
            //Creating legends:

        private void CreatingElements()
            elebuttons = new Button[elementsList.Count];
            //starting position for 1st upper left button:
            int x = 20;
            int y = 60;
            //and size of buttons:
            int size = 48;
            foreach (ElementData el in elementsList)
                if (el.LocationX > 0)
                    x = 20 + size * el.LocationX;
                    x = 20;
                if (el.LocationY > 0)
                    y = 60 + size * el.LocationY;

                elebuttons[el.SequenceNumber - 1] = new Button();
                string btnText = String.Format("{0}\r\n{1}\r\n{2}\r\n{3}", el.SequenceNumber, el.ShortName, el.FullName, el.AtomicMass);
                elebuttons[el.SequenceNumber - 1].Location = new Point(x, y);
                elebuttons[el.SequenceNumber - 1].Size = new Size(size, size);
                elebuttons[el.SequenceNumber - 1].Font = new Font("Arial", 6, FontStyle.Regular);
                elebuttons[el.SequenceNumber - 1].Text = btnText;
                elebuttons[el.SequenceNumber - 1].Tag = el.FullName;
                elebuttons[el.SequenceNumber - 1].BackColor = GetButtonColor(el.Color);
                elebuttons[el.SequenceNumber - 1].Click += new EventHandler(ButtonElements_Click);
                this.Controls.Add(elebuttons[el.SequenceNumber - 1]);

        private void CreatingLegends()
            legButtons = new Button[legendList.Count];
            //starting position for 1st upper left button:
            int x = 164;
            int y = 60;
            decimal size = 48;
            foreach (LegendData le in legendList)
                x = Convert.ToInt32(20 + size * le.LocationX);
                if (le.LocationY > 0)
                    y = Convert.ToInt32(60 + size * le.LocationY);
                    y = 60;

                legButtons[le.Number - 1] = new Button();
                legButtons[le.Number - 1].Text = le.GroupName;
                legButtons[le.Number - 1].Size = new Size(120, 25);
                legButtons[le.Number - 1].Location = new Point(x, y);
                legButtons[le.Number - 1].Font = new Font("Arial", 8, FontStyle.Regular);
                legButtons[le.Number - 1].BackColor = GetButtonColor(le.Number);
                legButtons[le.Number - 1].Tag = le.GroupName;
                legButtons[le.Number - 1].Click += new EventHandler(ButtonLegends_Click);
                this.Controls.Add(legButtons[le.Number - 1]);

        private void ButtonElements_Click(object sender, EventArgs e)
            Button btn = sender as Button;
            MessageBox.Show(String.Format("Element {0} was selected.", btn.Tag));

        private void ButtonLegends_Click(object sender, EventArgs e)
            Button btn = sender as Button;


        private void SeperateElementData(string data)
            string[] array = data.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
            //removing tabs
            for (int i = 0; i < array.Length; i++)
                if (array[i].Contains("\t"))
                    array[i] = array[i].Replace("\t", "");

            ElementData el = new ElementData();
            el.SequenceNumber = int.Parse(array[0]);
            el.ShortName = array[1];
            el.FullName = array[2];
            el.AtomicMass = Convert.ToDecimal(array[3]);
            el.Brackets = (array[4] == "1") ? true : false;
            el.Color = int.Parse(array[5]);
            decimal[] xy = SeperateLocation(array[6]);
            el.LocationX = (int)xy[0];
            el.LocationY = (int)xy[1];
            el.Details = array[7];

            //addind data of element to list<T>:

        private void SeperateLegendData(string data)
            string[] array = data.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
            //removing tabs
            for (int i = 0; i < array.Length; i++)
                if (array[i].Contains("\t"))
                    array[i] = array[i].Replace("\t", "");

            LegendData le = new LegendData();
            le.Number = int.Parse(array[0]);
            le.GroupName = array[1];
            decimal[] xy = SeperateLocation(array[2]);
            le.LocationX = xy[0];
            le.LocationY = xy[1];


        private decimal[] SeperateLocation(string str)
            string[] arr = str.Split('x');
            decimal x = decimal.Parse(arr[0]);
            decimal y = decimal.Parse(arr[1]);

            return new decimal[] { x, y };

        private Color GetButtonColor(int value)
            Color backColor = new Color();
            switch (value)
                case 1:
                    backColor = Color.LimeGreen;
                case 2:
                    backColor = Color.Blue;
                case 3:
                    backColor = Color.Orange;
                case 4:
                    backColor = Color.Yellow;
                case 5:
                    backColor = Color.ForestGreen;
                case 6:
                    backColor = Color.Aquamarine;
                case 7:
                    backColor = Color.GreenYellow;
                case 8:
                    backColor = Color.Red;
                case 9:
                    backColor = Color.Pink;
                case 10:
                    backColor = Color.Magenta;
            return backColor;

        private IEnumerable<string> ReadingData(string path)
            using (StreamReader sr = new StreamReader(path))
                string line;
                while ((line = sr.ReadLine()) != null)
                    if (!line.StartsWith("##") && line != "")
                        yield return line;

    class ElementData
       public int SequenceNumber { get; set; }
       public string ShortName { get; set; }
       public string FullName { get; set; }
       public decimal AtomicMass { get; set; }
       public bool Brackets { get; set; }
       public int Color { get; set; }
       public int LocationX { get; set; }
       public int LocationY { get; set; }
       public string Details { get; set; }

    class LegendData
        public int Number { get; set; }
        public string GroupName { get; set; }
        public decimal LocationX { get; set; }
        public decimal LocationY { get; set; }

[I]Download the file[/I] which is needed that application will work. You get it here.
[I]Copy the file into the debug folder of current project[/I] (ie: ...\MyProject\MyProject\bin\Debug\).

NOTE: If you will not put it there, you have to change the path (its on top of the Form1 class.

There is still work to do, but mostly it works. Details are not included, but it can be.
Hope you like it.
Excellent first go!
Nice effort :)

Great job Mitja!
Are the buttons in the middle meant to be labels or have you further plans with them?
ONe advise: if you use color(colour?) make it more subtle, pastel, I don't know the exact word. It is hard to read what is printed in a harsh dark blue in the noble gasses column.


Hi, thx mate.
They can be labels, even they are now buttons, and I had in mind do something with them, like coloring just the elements that belong to selected group (all other will be colors differently but the same), so the difference will be visible.

Anyway, there is still a lot of work do to, to implement all the details for each element, but this is mostly in writing text. Then when this is done, only a new form is needed what will show selected element`s details, by reading the appropriate file (or all in one, the appropriate line of text).

And thx for the adivce. I know what you mean (not to use so colorful colors), its hard to read when so-red (and so-green, ...) colors are used. I will consider your advice.

Maybe only the buttons location can be done a bit better, I complicated a bit to much, and this is the only code I dont like... will repair it.


I knew any efforts would produce some new ideas for me.
I like the ReadingData method.:cool:
I have not done anything that returns IEnumerable before.
Your neat example will be put to some good use.:)
Thanks. A great piece of coding.


getting this error Error 2 Using the generic type 'System.Collections.Generic.List<T>' requires '1' type arguments C:\Users\akash\Documents\Visual Studio 2008\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 16 9 WindowsFormsApplication2

This article has been dead for over six months. Start a new discussion instead.
Be sure to adhere to our posting rules.