简体   繁体   中英

c# Flowchart from buttons while the program is running

I need to create while running a flow chart for string input which I get from textbox1. the form size is 700*450, and it is allowed scroll.between each letter(char from the input string) has to be( in the output) an arrow(which is displayed on button) * the whole chart has to be ehxibited on buttons * for example, for this input string: 'ABZAZAZA' for each letter there is asuitable color that the background of the button should be colored in.

the program should be "print": A --> B --> Z --> A --> Z --> A --> Z --> A -->

the size of arrow button: 34*23 the size of letter button: 34*29

the problem with my code, that the flowchart isn't shown

Heres the code:

    public void DrawingSystem(string st)
    {
        shura_acid = 12;
        tur_acid = 185;

        for (int i = 1; i <= st.Length; i++)
        {
            if ((i % 7) == 0)
            {
                OpenNewLine();
            }
            CreateAcid(st[i - 1], i);
            shura_acid = shura_acid + 24 + 68;
        }
    }

    public void OpenNewLine()
    {
        tur_acid = tur_acid + 29 + 12;//34 because the size of button,12 because space between lines
        shura_acid = 12;
    }

    public void CreateAcid(char letter, int i)
    {
        //create acid
        Button acid = new Button();
        acid.Location = new System.Drawing.Point(shura_acid, tur_acid);
        acid.Name = "acid" + i;
        acid.Size = new System.Drawing.Size(34, 29);
        acid.TabIndex = 100 + i;
        acid.Text = Convert.ToString(letter);
        switch (letter)
        {
            case 'A': acid.BackColor = System.Drawing.Color.Fuchsia; break;
            case 'C': acid.BackColor = System.Drawing.Color.Pink; break;
            case 'D': acid.BackColor = System.Drawing.Color.Gray; break;
            case 'F': acid.BackColor = System.Drawing.Color.Azure; break;
            case 'G': acid.BackColor = System.Drawing.Color.Red; break;
            case 'H': acid.BackColor = System.Drawing.Color.Aqua; break;
            case 'I': acid.BackColor = System.Drawing.Color.Lime; break;
            case 'K': acid.BackColor = System.Drawing.Color.Yellow; break;
            case 'L': acid.BackColor = System.Drawing.Color.Olive; break;
            case 'M': acid.BackColor = System.Drawing.Color.Coral; break;
            case 'N': acid.BackColor = System.Drawing.Color.SaddleBrown; break;
            case 'P': acid.BackColor = System.Drawing.Color.Teal; break;
            case 'Q': acid.BackColor = System.Drawing.Color.Blue; break;
            case 'R': acid.BackColor = System.Drawing.Color.Orange; break;
            case 'S': acid.BackColor = System.Drawing.Color.Green; break;
            case 'T': acid.BackColor = System.Drawing.Color.SteelBlue; break;
            case 'V': acid.BackColor = System.Drawing.Color.DarkViolet; break;
            case 'W': acid.BackColor = System.Drawing.Color.Crimson; break;
            case 'X': acid.BackColor = System.Drawing.Color.MediumAquamarine; break;
            default: acid.BackColor = System.Drawing.Color.Gold; break;
        }


        //create arrow
        Button arrow = new System.Windows.Forms.Button();
        arrow.Location = new System.Drawing.Point(shura_acid + 34 + 12, tur_acid);
        arrow.Name = "acid" + i;
        arrow.Size = new System.Drawing.Size(34, 23);
        arrow.TabIndex = 100 + i;
        arrow.Text = "-->";
        arrow.UseVisualStyleBackColor = false;


    }

I'll take a stab at it. No where in your code do I see you actually adding the acid or arrow buttons to a container.

You need something like this:

this.Controls.Add(acid);

and

this.Controls.Add(arrow);

Change this.Controls to the container you want them to appear in.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM