I'm starting to study C # and just like in Java, IDEs provide features that make it possible to build GUIs easily by dragging components. The netbeans has a powerful build tool where you can drag Swing components for JFrame
, JDialog
, etc. In the visual-studio I felt at home, it is pretty much the same scheme.
My question is: In Netbeans, the code generated by the GUI Builder is functional, but very complicated to maintain - assuming that maintenance is not going to use the Netbeans interface builder (eg a eclipse ). Depending on the requirements in the graphical interface it is much better to write the code "on the nail", making the source code much simpler to read. I do not know how the window code is generated in C #, but I would like to know if it is possible to build a graphical interface in the "pure" code manually.
For example, in Java, the following excerpt is used to show a window:
import java.awt.event.*;
import javax.swing.*;
public class MinhaJanela extends JFrame {
public MinhaJanela(){
super("Minha Janela");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(300, 300);
setLocationRelativeTo(null);
JButton btn = new JButton("Click aqui");
btn.addActionListener((ActionEvent e) -> {
btnClick();
});
getContentPane().add(btn);
setVisible(true);
}
private void btnClick(){
JOptionPane.showMessageDialog(null, "Clicou!");
}
public static void main(String[] args) {
new MinhaJanela();
}
}
How would you create the same window in C#
?
PS: No, I'm not a hater of GUI builders, it's more of a curiosity even though I want to understand how it works.