Archive for the ‘Blog’ Category
Já está disponível para Download a nova versão do sistema operativo FreeBSD, mais propriamente a versão 8.4.
Esta nova versão trás bastantes melhorias face à versão 8.3 e até introduz algumas novas funcionalidades, sendo que existe a possibilidade de usar o ambiente gráfico GNOME 2.32.1 ou o KDE 4.10.1.
Apesar da correcção de muitos problemas existentes na versão 8.3 a nova versão 8.4 também tem alguns problemas que podem ser consultados Aqui:
Poderá obter mais informações Aqui:
O Download poderá ser feito Aqui:
ShareDesde que passei a ser um pouco mais Geek que lia pela Internet que o uso de dois monitores em simultâneo aumentava bastante a produtividade, e em certo ponto é verdade pois caso contrário os profissionais da edição de vídeo e modelação 3D não os usariam.
Até os programadores mais exigentes utilizam dois monitores em simultâneo, eu próprio já o experimentei e gostei bastante da área extra e a possibilidade de estar a programar tendo a documentação de apoio e enunciados mesmo ao lado, pronta a consultar e comparar com o código criado.
Gostaria de saber as vossas opiniões acerca deste assunto, assim como as dicas que achem importantes para quem usa dois monitores em simultâneo.
Será que vocês também concordam com o aumento de produtividade?
ShareCom o início da aprendizagem da linguagem de programação C# sendo a minha primeira experiência no desenvolvimento de aplicações Windows forms aplications a nível universitário, o primeiro desafio que me foi proposto foi a criação de uma calculadora simples ao estilo da calculadora padrão do Windows.
Eu deitei mãos à obra e consegui o seguinte resultado:
O código criado foi o seguinte:
Program.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; namespace Calculadora { static class Program { [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Calculadora()); } } } |
Calculadora.Designer.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
namespace Calculadora { partial class Calculadora { private System.ComponentModel.IContainer components = null; protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code private void InitializeComponent() { this.button_0 = new System.Windows.Forms.Button(); this.textBox_res = new System.Windows.Forms.TextBox(); this.button_4 = new System.Windows.Forms.Button(); this.button_3 = new System.Windows.Forms.Button(); this.button_2 = new System.Windows.Forms.Button(); this.button_1 = new System.Windows.Forms.Button(); this.button_5 = new System.Windows.Forms.Button(); this.button_6 = new System.Windows.Forms.Button(); this.button_7 = new System.Windows.Forms.Button(); this.button_8 = new System.Windows.Forms.Button(); this.button_9 = new System.Windows.Forms.Button(); this.button_soma = new System.Windows.Forms.Button(); this.button_subtraccao = new System.Windows.Forms.Button(); this.button_divisao = new System.Windows.Forms.Button(); this.button_multiplicacao = new System.Windows.Forms.Button(); this.button_igual = new System.Windows.Forms.Button(); this.button_limpar = new System.Windows.Forms.Button(); this.button_retroceder = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button_0 // this.button_0.Location = new System.Drawing.Point(13, 225); this.button_0.Name = "button_0"; this.button_0.Size = new System.Drawing.Size(56, 23); this.button_0.TabIndex = 0; this.button_0.Text = "0"; this.button_0.UseVisualStyleBackColor = true; this.button_0.Click += new System.EventHandler(this.button_0_Click); // // textBox_res // this.textBox_res.Location = new System.Drawing.Point(13, 13); this.textBox_res.Multiline = true; this.textBox_res.Name = "textBox_res"; this.textBox_res.Size = new System.Drawing.Size(259, 40); this.textBox_res.TabIndex = 1; this.textBox_res.Text = "0"; this.textBox_res.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; // // button_4 // this.button_4.Location = new System.Drawing.Point(13, 196); this.button_4.Name = "button_4"; this.button_4.Size = new System.Drawing.Size(56, 23); this.button_4.TabIndex = 2; this.button_4.Text = "4"; this.button_4.UseVisualStyleBackColor = true; this.button_4.Click += new System.EventHandler(this.button_4_Click); // // button_3 // this.button_3.Location = new System.Drawing.Point(13, 167); this.button_3.Name = "button_3"; this.button_3.Size = new System.Drawing.Size(56, 23); this.button_3.TabIndex = 3; this.button_3.Text = "3"; this.button_3.UseVisualStyleBackColor = true; this.button_3.Click += new System.EventHandler(this.button_3_Click); // // button_2 // this.button_2.Location = new System.Drawing.Point(13, 138); this.button_2.Name = "button_2"; this.button_2.Size = new System.Drawing.Size(56, 23); this.button_2.TabIndex = 4; this.button_2.Text = "2"; this.button_2.UseVisualStyleBackColor = true; this.button_2.Click += new System.EventHandler(this.button_2_Click); // // button_1 // this.button_1.Location = new System.Drawing.Point(13, 109); this.button_1.Name = "button_1"; this.button_1.Size = new System.Drawing.Size(56, 23); this.button_1.TabIndex = 5; this.button_1.Text = "1"; this.button_1.UseVisualStyleBackColor = true; this.button_1.Click += new System.EventHandler(this.button_1_Click); // // button_5 // this.button_5.Location = new System.Drawing.Point(92, 109); this.button_5.Name = "button_5"; this.button_5.Size = new System.Drawing.Size(56, 23); this.button_5.TabIndex = 10; this.button_5.Text = "5"; this.button_5.UseVisualStyleBackColor = true; this.button_5.Click += new System.EventHandler(this.button_5_Click); // // button_6 // this.button_6.Location = new System.Drawing.Point(92, 138); this.button_6.Name = "button_6"; this.button_6.Size = new System.Drawing.Size(56, 23); this.button_6.TabIndex = 9; this.button_6.Text = "6"; this.button_6.UseVisualStyleBackColor = true; this.button_6.Click += new System.EventHandler(this.button_6_Click); // // button_7 // this.button_7.Location = new System.Drawing.Point(92, 167); this.button_7.Name = "button_7"; this.button_7.Size = new System.Drawing.Size(56, 23); this.button_7.TabIndex = 8; this.button_7.Text = "7"; this.button_7.UseVisualStyleBackColor = true; this.button_7.Click += new System.EventHandler(this.button_7_Click); // // button_8 // this.button_8.Location = new System.Drawing.Point(92, 196); this.button_8.Name = "button_8"; this.button_8.Size = new System.Drawing.Size(56, 23); this.button_8.TabIndex = 7; this.button_8.Text = "8"; this.button_8.UseVisualStyleBackColor = true; this.button_8.Click += new System.EventHandler(this.button_8_Click); // // button_9 // this.button_9.Location = new System.Drawing.Point(92, 225); this.button_9.Name = "button_9"; this.button_9.Size = new System.Drawing.Size(56, 23); this.button_9.TabIndex = 6; this.button_9.Text = "9"; this.button_9.UseVisualStyleBackColor = true; this.button_9.Click += new System.EventHandler(this.button_9_Click); // // button_soma // this.button_soma.Location = new System.Drawing.Point(185, 109); this.button_soma.Name = "button_soma"; this.button_soma.Size = new System.Drawing.Size(87, 23); this.button_soma.TabIndex = 15; this.button_soma.Text = "+"; this.button_soma.UseVisualStyleBackColor = true; this.button_soma.Click += new System.EventHandler(this.button_soma_Click); // // button_subtraccao // this.button_subtraccao.Location = new System.Drawing.Point(185, 138); this.button_subtraccao.Name = "button_subtraccao"; this.button_subtraccao.Size = new System.Drawing.Size(87, 23); this.button_subtraccao.TabIndex = 14; this.button_subtraccao.Text = "-"; this.button_subtraccao.UseVisualStyleBackColor = true; this.button_subtraccao.Click += new System.EventHandler(this.button_subtraccao_Click); // // button_divisao // this.button_divisao.Location = new System.Drawing.Point(185, 167); this.button_divisao.Name = "button_divisao"; this.button_divisao.Size = new System.Drawing.Size(87, 23); this.button_divisao.TabIndex = 13; this.button_divisao.Text = "/"; this.button_divisao.UseVisualStyleBackColor = true; this.button_divisao.Click += new System.EventHandler(this.button_divisao_Click); // // button_multiplicacao // this.button_multiplicacao.Location = new System.Drawing.Point(185, 196); this.button_multiplicacao.Name = "button_multiplicacao"; this.button_multiplicacao.Size = new System.Drawing.Size(87, 23); this.button_multiplicacao.TabIndex = 12; this.button_multiplicacao.Text = "x"; this.button_multiplicacao.UseVisualStyleBackColor = true; this.button_multiplicacao.Click += new System.EventHandler(this.button_multiplicacao_Click); // // button_igual // this.button_igual.Location = new System.Drawing.Point(185, 225); this.button_igual.Name = "button_igual"; this.button_igual.Size = new System.Drawing.Size(87, 23); this.button_igual.TabIndex = 11; this.button_igual.Text = "="; this.button_igual.UseVisualStyleBackColor = true; this.button_igual.Click += new System.EventHandler(this.button_igual_Click); // // button_limpar // this.button_limpar.Location = new System.Drawing.Point(146, 80); this.button_limpar.Name = "button_limpar"; this.button_limpar.Size = new System.Drawing.Size(126, 23); this.button_limpar.TabIndex = 16; this.button_limpar.Text = "Limpar"; this.button_limpar.UseVisualStyleBackColor = true; this.button_limpar.Click += new System.EventHandler(this.button_limpar_Click); // // button_retroceder // this.button_retroceder.Location = new System.Drawing.Point(12, 80); this.button_retroceder.Name = "button_retroceder"; this.button_retroceder.Size = new System.Drawing.Size(126, 23); this.button_retroceder.TabIndex = 17; this.button_retroceder.Text = "Retroceder"; this.button_retroceder.UseVisualStyleBackColor = true; this.button_retroceder.Click += new System.EventHandler(this.button_retroceder_Click); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(284, 262); this.Controls.Add(this.button_retroceder); this.Controls.Add(this.button_limpar); this.Controls.Add(this.button_soma); this.Controls.Add(this.button_subtraccao); this.Controls.Add(this.button_divisao); this.Controls.Add(this.button_multiplicacao); this.Controls.Add(this.button_igual); this.Controls.Add(this.button_5); this.Controls.Add(this.button_6); this.Controls.Add(this.button_7); this.Controls.Add(this.button_8); this.Controls.Add(this.button_9); this.Controls.Add(this.button_1); this.Controls.Add(this.button_2); this.Controls.Add(this.button_3); this.Controls.Add(this.button_4); this.Controls.Add(this.textBox_res); this.Controls.Add(this.button_0); this.Name = "Form1"; this.Text = "Calculadora"; this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.Button button_0; private System.Windows.Forms.TextBox textBox_res; private System.Windows.Forms.Button button_4; private System.Windows.Forms.Button button_3; private System.Windows.Forms.Button button_2; private System.Windows.Forms.Button button_1; private System.Windows.Forms.Button button_5; private System.Windows.Forms.Button button_6; private System.Windows.Forms.Button button_7; private System.Windows.Forms.Button button_8; private System.Windows.Forms.Button button_9; private System.Windows.Forms.Button button_soma; private System.Windows.Forms.Button button_subtraccao; private System.Windows.Forms.Button button_divisao; private System.Windows.Forms.Button button_multiplicacao; private System.Windows.Forms.Button button_igual; private System.Windows.Forms.Button button_limpar; private System.Windows.Forms.Button button_retroceder; } } |
Calculadora.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Calculadora { public partial class Calculadora : Form { //Variavel booleana para detectar se foi accionada a operação aritmetica bool detecta_operacao = true; string operacao; double resultado; double numero_1; double numero_2; public Calculadora() { InitializeComponent(); } //Definição dos Botões Numéricos private void button_1_Click(object sender, EventArgs e) { if (detecta_operacao) { textBox_res.Text = textBox_res.Text = ""; textBox_res.Text = textBox_res.Text = "1"; detecta_operacao = false; } else { textBox_res.Text = textBox_res.Text += "1"; } } private void button_2_Click(object sender, EventArgs e) { if (detecta_operacao) { textBox_res.Text = textBox_res.Text = ""; textBox_res.Text = textBox_res.Text = "2"; detecta_operacao = false; } else { textBox_res.Text = textBox_res.Text += "2"; } } private void button_3_Click(object sender, EventArgs e) { if (detecta_operacao) { textBox_res.Text = textBox_res.Text = ""; textBox_res.Text = textBox_res.Text = "3"; detecta_operacao = false; } else { textBox_res.Text = textBox_res.Text += "3"; } } private void button_4_Click(object sender, EventArgs e) { if (detecta_operacao) { textBox_res.Text = textBox_res.Text = ""; textBox_res.Text = textBox_res.Text = "4"; detecta_operacao = false; } else { textBox_res.Text = textBox_res.Text += "4"; } } private void button_5_Click(object sender, EventArgs e) { if (detecta_operacao) { textBox_res.Text = textBox_res.Text = ""; textBox_res.Text = textBox_res.Text = "5"; detecta_operacao = false; } else { textBox_res.Text = textBox_res.Text += "5"; } } private void button_6_Click(object sender, EventArgs e) { if (detecta_operacao) { textBox_res.Text = textBox_res.Text = ""; textBox_res.Text = textBox_res.Text = "6"; detecta_operacao = false; } else { textBox_res.Text = textBox_res.Text += "6"; } } private void button_7_Click(object sender, EventArgs e) { if (detecta_operacao) { textBox_res.Text = textBox_res.Text = ""; textBox_res.Text = textBox_res.Text = "7"; detecta_operacao = false; } else { textBox_res.Text = textBox_res.Text += "7"; } } private void button_8_Click(object sender, EventArgs e) { if (detecta_operacao) { textBox_res.Text = textBox_res.Text = ""; textBox_res.Text = textBox_res.Text = "8"; detecta_operacao = false; } else { textBox_res.Text = textBox_res.Text += "8"; } } private void button_9_Click(object sender, EventArgs e) { if (detecta_operacao) { textBox_res.Text = textBox_res.Text = ""; textBox_res.Text = textBox_res.Text = "9"; detecta_operacao = false; } else { textBox_res.Text = textBox_res.Text += "9"; } } private void button_0_Click(object sender, EventArgs e) { if (textBox_res.Text == "0") { return; } else { textBox_res.Text = textBox_res.Text += "0"; } } //Fim Definição dos Botões Numéricos //Definição dos Botões Operadores Aritméticos private void button_soma_Click(object sender, EventArgs e) { operacao = "+"; detecta_operacao = true; numero_1 = Convert.ToDouble(textBox_res.Text); } private void button_subtraccao_Click(object sender, EventArgs e) { operacao = "-"; detecta_operacao = true; numero_1 = Convert.ToDouble(textBox_res.Text); } private void button_divisao_Click(object sender, EventArgs e) { operacao = "/"; detecta_operacao = true; numero_1 = Convert.ToDouble(textBox_res.Text); } private void button_multiplicacao_Click(object sender, EventArgs e) { operacao = "*"; detecta_operacao = true; numero_1 = Convert.ToDouble(textBox_res.Text); } //Fim Definição dos Botões Operadores Aritméticos private void button_igual_Click(object sender, EventArgs e) { numero_2 = Convert.ToDouble(textBox_res.Text); detecta_operacao = true; switch (operacao) { case "+": { resultado = numero_1 + numero_2; textBox_res.Text = resultado.ToString(); break; } case "-": { resultado = numero_1 - numero_2; textBox_res.Text = resultado.ToString(); break; } case "*": { resultado = numero_1 * numero_2; textBox_res.Text = resultado.ToString(); break; } case "/": { resultado = numero_1 / numero_2; textBox_res.Text = resultado.ToString(); break; } } } //Fim Definição dos Botões Operadores Aritméticos ////Definição dos Botões Limpar e retroceder private void button_limpar_Click(object sender, EventArgs e) { resultado = 0; numero_1 = 0; numero_2 = 0; textBox_res.Text = textBox_res.Text = ""; } private void button_retroceder_Click(object sender, EventArgs e) { int x = textBox_res.Text.Length - 1; if (x >= 0) { textBox_res.Text = textBox_res.Text.Substring(0, x); } } private void Form1_Load(object sender, EventArgs e) { } } } |
As funções que necessitei de utilizar e aprender para este exercício foi a conversão de string para double usando o “Convert.ToDouble(Textbox_res.Text)” e o corte de uma string em pedaços de modo a efectuar o método retroceder com o “textBox_res.Text.Substring(0, x)”.
Quanto à função “textBox_res.Text.Substring(0, x)” o que ela faz e no contexto do código criado é o seguinte:
1 |
textBox_res.Text.Substring(0, x ); |
Da string já existente vamos criar uma nova string usando apenas parte da string original e que tem como parâmetro inicial o zero e irá correr até ao parâmetro x que neste caso será o comprimento da string final que pretendemos. Neste caso temos ainda a situação de que o valor x está sempre em mudança a cada processo, ou seja é retirado um carácter à string cada vez que o botão retroceder é accionado.
Sei que existem milhares de formas de resolver o mesmo problema, mas esta foi aquela que eu desenvolvi pelo que estou aberto a novas opiniões sobre o que efectuei.
Share