[Solved] program succeded in no error but this method is not working


prgBar.Show()

Is this what you need? Did you forget to show the new form?

EDIT:

I’m answering to you comment…

you need a static property to access the form from somewhere else:

public partial class Form1 : Form
{
  // This is you constructor (not shown in your sample code).
  public Form1()
  {
    InitializeComponent();
    Instance = this;
  }

  public static Form1 Instance { get; private set;}

  game_rule dt = new game_rule();
  private void button2_Click(object sender, EventArgs e)
  {
    progressBar1.Increment(-200); // this is work
    dt.DoAttack(); // this is not work... but there is no build error at all!
  }
}


class game_rule
{
    public void DoAttack()
    {
        Form1.Instance.progressBar1.Increment(-200);
        SystemSounds.Asterisk.Play();
    }
}

or another approach could be by dependency injection (not a perfect one but it’s a good beginning):

public partial class Form1 : Form
{

  game_rule dt = new game_rule();
  private void button2_Click(object sender, EventArgs e)
  {
    progressBar1.Increment(-200); // this is work
    dt.DoAttack(this); // this is not work... but there is no build error at all!
  }
}


class game_rule
{        
    public void DoAttack(Form1 form)
    {
        form1.progressBar1.Increment(-200);
        SystemSounds.Asterisk.Play();
    }
}

2

solved program succeded in no error but this method is not working