2
I’m reading Caelum’s booklet about C# and object orientation, so I put it in Account.Cs the following code:
namespace Banco
{
class Conta
{
public int numero;
public string nome;
public double saldo;
public bool Sacar(double valor)
{
if (this.saldo >= valor)
{
this.saldo -= valor;
return true;
}
return false;
}
}
}
Has the class Bill with the method Draw. It says that to instantiate an object you have to do the following:
private void button1_Click(object sender, EventArgs e)
{
Conta r = new Conta();
r.numero = 1;
r.nome = "Flano";
r.saldo = 300;
if (r.Sacar(250.0)) {
MessageBox.Show("Operação realizada com sucesso!");
} else {
MessageBox.Show("Saldo insuficiente!");
}
}
I understand how everything works, I just don’t know where to put this "button".
Your object of type
Conta
is already instantiated, could be more clear in your doubt ? because from what I understand, you have this button code and do not know where to put correct ?– Enzo Tiezzi
Don’t worry about class
Conta
for this. She’s just your model, she has no relation to the presentation you’re trying to make. Of course, you use it in the presentation but it itself is not part of the presentation. Did you copy this in the project or have VS generate the Form code for you and just add this snippet? Does the handout show all the code, or did you just give it that snippet? It seems to me that you have to create the whole Form (the VS generates the code for you) and then fit this part.– Maniero
I know that the class is the reference for me to instantiate the objects. That must be right, must be missing create the form. But there it was like this, it didn’t show how to create the form.
– I Wanna Know
That @Enzotiezzi I instanciei, but I do not know where to put.
– I Wanna Know
first you need to identify if your project, is a
Windows Form
, if so you need to put a button on your screen, click on that button 2 times and include that code that is in the methodbutton1_Click
in the code it automatically generates, which will be similar to the one you have.– Enzo Tiezzi
The Button will be placed in the Graphical Interface. https://lh3.googleusercontent.com/-MRRwz5qyaE8/Tn0EKfJ8E9I/AAAAAAAABAY/16jDCAKW4cs/DynamicButtonsInWinforms.gif
– Tony
Visual Studio has a keyboard shortcut to indent code automatically:
CTRL + k + d
;)– Oralista de Sistemas
Thank you guys, I’ve identified everything here. Thank you very much.
– I Wanna Know