Hello I am 13 and trying to learn c#. I have a book that is teaching me but some codes I can't get to work I would like to run them by you(Who ever reads this) and see what is wrong.
First Code(I wrote this) I Put the whole code:

//This is supposed to fill a progress bar 

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;

namespace Book_Var_test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var a = 1;
            bool there = false;
            var p = progressBar1;
            a = a + 1;
            button1.Text = "Loading";
            while (there == false)
                if (p.Value == 100)
                {
                    button1.Text = "Finshed";
                }
                else
                {
                    p.Value = p.Value + 1;
                }

            
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

Recommended Answers

All 2 Replies

First question. What are you trying to do here? Are you trying to create a Windows form with a progress bar? If you are, this simple example should work.

using System;
using System.Drawing;
using System.Windows.Forms;

class myform: Form
{
    ProgressBar my_bar;
    
    public myform()
    {
        my_bar = new ProgressBar();

        my_bar.Minimum = 1;
        my_bar.Maximum = 100;
        my_bar.Value = 1;
        my_bar.Step = 1;
        my_bar.Size = new Size(225, 30);
        
        this.Text = "Click on the Progress Bar";
        this.Size = new Size(250, 200);
        this.CenterToScreen();
        
        my_bar.Click += new EventHandler(ClickProgressHandler);

        this.Controls.Add(my_bar);
    }
    
    private void ClickProgressHandler(object obj, EventArgs args)
    {
        ((ProgressBar)obj).Value += 5;
    }
}

namespace testit
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            myform me = new myform();
            Application.Run(me);
        }
    }
}

Thanks very much.
I am just starting so I might have more but thanks everyone!

Be a part of the DaniWeb community

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