<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-9021371897721484347</id><updated>2013-12-07T20:30:57.483-02:00</updated><category term="C# Windows Forms"/><category term="C# AspNet"/><category term="Dicas"/><category term="Validador"/><category term="conversor"/><category term="Cronometro"/><category term="DataGridView"/><category term="HTML/CSS"/><category term="Jogo"/><category term="icon"/><category term="Confirmação"/><category term="Cron"/><category term="Download"/><category term="Eventos"/><category term="Exportar"/><category term="Gerador de Senhas"/><category term="JavaScript"/><category term="MailMessage"/><category term="MdiParent"/><category term="MessageBox AspNet"/><category term="QueryString"/><category term="Random"/><category term="SQL"/><category term="StopWatch"/><category term="Tela Splash"/><category term="calcular imc"/><category term="casting"/><category term="email"/><category term="recursão"/><category term="session"/><category term="sites"/><title type='text'>Dicas e projetos completos em C#</title><subtitle type='html'>Pequenos projetos em C#, AspNet, JS/jQuery com código fonte comentado explicando passo a passo.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://jhomps.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://jhomps.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>João Paulo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>49</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-9021371897721484347.post-1920345327453458882</id><published>2013-11-24T22:19:00.001-02:00</published><updated>2013-11-24T22:22:36.330-02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C# Windows Forms"/><title type='text'>Como criar um componente DataGridView customizado em C#</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;Olá pessoal,&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Algumas vezes precisamos mudar as cores e/ou funcionalidades dos componentes de nosso programa. Para isso, ao invés de configurar um por um, podemos criar um novo componente herdando as características do componente original.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Neste exemplo eu criei um DataGridView com as linhas com cores alternadas em azul e ao clicar em uma célula toda a linha é selecionada. Ficou assim:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/-70MY49Cdf8M/UpFSJZgwhKI/AAAAAAAAC88/zJW559WDYjs/s1600/dgv.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://4.bp.blogspot.com/-70MY49Cdf8M/UpFSJZgwhKI/AAAAAAAAC88/zJW559WDYjs/s1600/dgv.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Para fazer isto é muito simples. Precisamos apenas criar uma nova classe para o projeto (Shift + Alt + C) e fazê-la herdar da classe DataGridView. Após isto, basta sobrescrevermos(override) o método InitLayout() para nossas necessidades.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Abaixo está o código da classe criada comentado com todas as alterações que fiz.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;//Adicionar esta biblioteca&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;using&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; System.Windows.Forms;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;namespace&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; CriarComponentes&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;//Herdar da classe DataGridView&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;class&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&lt;span style=&quot;color: #2b91af;&quot;&gt;DataGridViewAlternado&lt;/span&gt; : &lt;span style=&quot;color: #2b91af;&quot;&gt;DataGridView&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;protected&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;override&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt;InitLayout()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;base&lt;/span&gt;.InitLayout();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: green;&quot;&gt;//Cor de fundo das linhas&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.DefaultCellStyle.BackColor = System.Drawing.&lt;span style=&quot;color: #2b91af;&quot;&gt;Color&lt;/span&gt;.FromArgb(184, 204, 228);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: green; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;//Cor do texto&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.DefaultCellStyle.ForeColor = System.Drawing.&lt;span style=&quot;color: #2b91af;&quot;&gt;Color&lt;/span&gt;.FromArgb(0, 0, 0);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;//Cor de fundo das linhas alternadas&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.AlternatingRowsDefaultCellStyle.BackColor = System.Drawing.&lt;span style=&quot;color: #2b91af;&quot;&gt;Color&lt;/span&gt;.FromArgb(219, 229, 241);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: green;&quot;&gt;//Cor do texto das linhas alternadas&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;this&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;.AlternatingRowsDefaultCellStyle.ForeColor = System.Drawing.&lt;span style=&quot;color: #2b91af;&quot;&gt;Color&lt;/span&gt;.FromArgb(0, 0, 0);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;//Cor de fundo da linha selecionada&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.RowsDefaultCellStyle.SelectionBackColor = System.Drawing.&lt;span style=&quot;color: #2b91af;&quot;&gt;Color&lt;/span&gt;.FromArgb(78, 129, 189);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: green;&quot;&gt;//Cor do texto da linha selecionada&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;this&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;.RowsDefaultCellStyle.SelectionForeColor = System.Drawing.&lt;span style=&quot;color: #2b91af;&quot;&gt;Color&lt;/span&gt;.FromArgb(255, 255, 255);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;//Cor de fundo do DataGridView (parte sem nenhuma informação)&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;this&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;.BackgroundColor = System.Drawing.&lt;span style=&quot;color: #2b91af;&quot;&gt;Color&lt;/span&gt;.FromArgb(220, 220, 220);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;//Gosto de deixar o modo de seleção como FullRowSelect, desta forma ao clicar em uma célula a linha inteira é marcada&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.SelectionMode = &lt;span style=&quot;color: #2b91af;&quot;&gt;DataGridViewSelectionMode&lt;/span&gt;.FullRowSelect;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Após o projeto ser compilado o novo componente será adicionado ao Toolbox, ficando ao seu dispor junto com os demais.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-iAqyczTEAto/UpFSEcfdzfI/AAAAAAAAC80/0znIPEem82E/s1600/dgv1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://1.bp.blogspot.com/-iAqyczTEAto/UpFSEcfdzfI/AAAAAAAAC80/0znIPEem82E/s1600/dgv1.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Esta customização pode ser feita em qualquer componente e é muito útil para centralizar estilos. Gosto de comparar esta técnica às folhas de estilos .css, usadas em html, porém com a diferença que neste caso é possível alterar funcionalidades, enquanto o css limita-se ao design.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Até a próxima!&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhomps.blogspot.com/feeds/1920345327453458882/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://jhomps.blogspot.com/2013/11/como-criar-um-componente-datagridview-em-chsarp.html#comment-form' title='1 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/1920345327453458882'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/1920345327453458882'/><link rel='alternate' type='text/html' href='http://jhomps.blogspot.com/2013/11/como-criar-um-componente-datagridview-em-chsarp.html' title='Como criar um componente DataGridView customizado em C#'/><author><name>João Paulo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-70MY49Cdf8M/UpFSJZgwhKI/AAAAAAAAC88/zJW559WDYjs/s72-c/dgv.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9021371897721484347.post-8744891853732471341</id><published>2013-11-19T11:55:00.002-02:00</published><updated>2013-11-19T11:55:36.069-02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C# Windows Forms"/><title type='text'>Evento apertar teclas de função F1 F2 F3 em C#</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;Olá pessoal, hoje trago uma dica rápida para usar as teclas de funções F1, F2, F3 até F24 (Sim, vai até o F24).&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Primeiro precisamos definir a propriedade &lt;b&gt;KeyPreview&lt;/b&gt; do Form para True. Isto fará com que o Form também receba todos os pressionamentos da tecla, mesmo quando o foco está em outro componente dele.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-AV59XDVCzLw/UotrpdacbJI/AAAAAAAAC8I/1SitejWTWXY/s1600/f1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://1.bp.blogspot.com/-AV59XDVCzLw/UotrpdacbJI/AAAAAAAAC8I/1SitejWTWXY/s1600/f1.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Agora basta dar um duplo clique no evento &lt;b&gt;KeyUp&lt;/b&gt; do Form e criarmos as seguintes condições para vermos qual tecla foi pressionada e então criarmos nossas rotinas.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-6-zc_X0l6Eo/UotsLeUyrUI/AAAAAAAAC8Q/z4tG1Q5z5U4/s1600/up.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://1.bp.blogspot.com/-6-zc_X0l6Eo/UotsLeUyrUI/AAAAAAAAC8Q/z4tG1Q5z5U4/s1600/up.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;private&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; Form1_KeyUp(&lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt; sender, &lt;span style=&quot;color: #2b91af;&quot;&gt;KeyEventArgs&lt;/span&gt;e)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (e.KeyCode == &lt;span style=&quot;color: #2b91af;&quot;&gt;Keys&lt;/span&gt;.F1)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;MessageBox&lt;/span&gt;.Show(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Você pressionou o F1.&quot;&lt;/span&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (e.KeyCode == &lt;span style=&quot;color: #2b91af;&quot;&gt;Keys&lt;/span&gt;.F2)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;MessageBox&lt;/span&gt;.Show(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Você pressionou o F2.&quot;&lt;/span&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (e.KeyCode == &lt;span style=&quot;color: #2b91af;&quot;&gt;Keys&lt;/span&gt;.F3)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;MessageBox&lt;/span&gt;.Show(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Você pressionou o F3.&quot;&lt;/span&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;                           &lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;text-align: justify;&quot;&gt;Por hoje é só, pessoal.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;text-align: justify;&quot;&gt;Até a próxima!&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhomps.blogspot.com/feeds/8744891853732471341/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://jhomps.blogspot.com/2013/11/evento-apertar-teclas-de-funcao-f1-f2-f3-csharp.html#comment-form' title='0 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/8744891853732471341'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/8744891853732471341'/><link rel='alternate' type='text/html' href='http://jhomps.blogspot.com/2013/11/evento-apertar-teclas-de-funcao-f1-f2-f3-csharp.html' title='Evento apertar teclas de função F1 F2 F3 em C#'/><author><name>João Paulo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-AV59XDVCzLw/UotrpdacbJI/AAAAAAAAC8I/1SitejWTWXY/s72-c/f1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9021371897721484347.post-8252290012281976100</id><published>2013-11-12T23:09:00.000-02:00</published><updated>2013-11-12T23:14:15.052-02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C# Windows Forms"/><title type='text'>Como criar tela de Login em C#</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Olá leitor!&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;No artigo de hoje quero mostrar como fiz uma tela de Login em C# para um aplicativo genérico. No exemplo que fiz para este artigo a tela abaixo é aberta antes da aplicação em si. Isto foi feito no Program.cs, instanciando o Form normalmente.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Na tela de Login há alguns controles básicos: Labels, TextBoxes e Buttons, porém uma imagem de fundo e um ícone de cadeado deram um toque especial para ela.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Através das propriedades do Form AcceptButton e CancelButton eu consigo vincular teclas do teclado a botões da aplicação. Sabendo disso vinculei o Button Login à tecla enter e o Button Sair à tecla ESC por questões de usabilidade e praticidade.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Para conseguir validar a senha no executável disponibilizado para download no fim deste artigo digite o usuário &quot;&lt;b&gt;admin&lt;/b&gt;&quot; e a senha &quot;&lt;b&gt;123&lt;/b&gt;&quot;.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Não estou usando nenhum tipo de encriptação no programa e os dados estão definidos dentro do próprio código fonte, porém você deverá usar suas rotinas para capturar os dados de seu banco de dados e encriptar a senha antes de fazer as comparações.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-dwepvC7ewuE/UoLMGiCB_vI/AAAAAAAAC7o/xpgx0a8G65w/s1600/login.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://1.bp.blogspot.com/-dwepvC7ewuE/UoLMGiCB_vI/AAAAAAAAC7o/xpgx0a8G65w/s1600/login.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;A mensagem abaixo é mostrada caso o usuário ou senha esteja errado.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-hWK_YXP4kX0/UoLMIZy4rLI/AAAAAAAAC7w/JTdVbdE-LZ8/s1600/loginErro.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://3.bp.blogspot.com/-hWK_YXP4kX0/UoLMIZy4rLI/AAAAAAAAC7w/JTdVbdE-LZ8/s1600/loginErro.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Caso as informações estejam corretas, antes do sistema ser aberto eu estou guardando o nome de usuário nas &lt;a href=&quot;http://msdn.microsoft.com/pt-br/library/aa730869(v=vs.80).aspx&quot; target=&quot;_blank&quot;&gt;configurações do aplicativo&lt;/a&gt;, desta forma da próxima vez que o sistema ser usado o nome de usuário já estará preenchido.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;No meu exemplo fiz apenas uma janela que recebe o nome do Usuário como parâmetro para ser mostrado num StatusStrip para fins demonstrativos. Você deverá chamar o Form principal de sua aplicação.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-YlTsjQQabOk/UoLMKYuOrnI/AAAAAAAAC74/cmJogX_vq1k/s1600/loginSucesso.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://1.bp.blogspot.com/-YlTsjQQabOk/UoLMKYuOrnI/AAAAAAAAC74/cmJogX_vq1k/s1600/loginSucesso.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Espero que tenha ajudado ou ao menos gerado algumas ideias para você melhorar o código.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;O .exe compilado para o .NET Framework 4.0 do programa pode ser baixado no seguinte link:&amp;nbsp;&lt;a href=&quot;http://goo.gl/H5PV5Y&quot; target=&quot;_blank&quot;&gt;http://goo.gl/H5PV5Y&lt;/a&gt;&amp;nbsp;(Usuário &quot;admin&quot; e senha &quot;123&quot;)&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Porém sugiro que baixe o projeto e código fonte completo do programa em C# criado com o VisualStudio2010 para ver com mais detalhes o funcionamento:&amp;nbsp;&lt;a href=&quot;http://goo.gl/dN4t0E&quot; target=&quot;_blank&quot;&gt;http://goo.gl/dN4t0E&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Fico por aqui.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Até a próxima!&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhomps.blogspot.com/feeds/8252290012281976100/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://jhomps.blogspot.com/2013/11/criar-tela-de-login-em-csharp.html#comment-form' title='0 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/8252290012281976100'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/8252290012281976100'/><link rel='alternate' type='text/html' href='http://jhomps.blogspot.com/2013/11/criar-tela-de-login-em-csharp.html' title='Como criar tela de Login em C#'/><author><name>João Paulo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-dwepvC7ewuE/UoLMGiCB_vI/AAAAAAAAC7o/xpgx0a8G65w/s72-c/login.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9021371897721484347.post-6239108807684635794</id><published>2013-10-22T22:34:00.002-02:00</published><updated>2013-10-22T22:34:56.896-02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C# Windows Forms"/><title type='text'>Como criar um MessageBox de confirmação em C#</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;Uma coisa muito importante na hora de remover registros em banco de dados, por exemplo, é criar MessageBox para o usuário confirmar a ação.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Para isso criamos um &lt;b&gt;MessageBox&lt;/b&gt; comum e comparamos o botão apertado com um valor da &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.windows.forms.dialogresult.aspx&quot; target=&quot;_blank&quot;&gt;enumeração &lt;b&gt;DialogResult&lt;/b&gt;&lt;/a&gt;.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Abaixo está um exemplo&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;//Criar um MessageBox com os botões Sim e Não e deixar o botão 2(Não) selecionado por padrão e comparar o bot&lt;/span&gt;&lt;span style=&quot;color: green; font-family: Consolas; font-size: x-small;&quot;&gt;ã&lt;/span&gt;&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;o apertado&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; (&lt;span style=&quot;color: #2b91af;&quot;&gt;DialogResult&lt;/span&gt;.Yes == &lt;span style=&quot;color: #2b91af;&quot;&gt;MessageBox&lt;/span&gt;.Show(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Tem certeza que deseja apagar o registro?&quot;&lt;/span&gt;, &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Confirmação&quot;&lt;/span&gt;, &lt;span style=&quot;color: #2b91af;&quot;&gt;MessageBoxButtons&lt;/span&gt;.YesNo, &lt;span style=&quot;color: #2b91af;&quot;&gt;MessageBoxIcon&lt;/span&gt;.Question, &lt;span style=&quot;color: #2b91af;&quot;&gt;MessageBoxDefaultButton&lt;/span&gt;.Button2))&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: green;&quot;&gt;//Sua rotina de exclusão&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: green;&quot;&gt;//Confirmando exclusão para o usuário&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;MessageBox&lt;/span&gt;.Show(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Registro apagado com sucesso&quot;&lt;/span&gt;, &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Sucesso&quot;&lt;/span&gt;, &lt;span style=&quot;color: #2b91af;&quot;&gt;MessageBoxButtons&lt;/span&gt;.OK, &lt;span style=&quot;color: #2b91af;&quot;&gt;MessageBoxIcon&lt;/span&gt;.Information);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-XU99mISxCis/UmcV2torz0I/AAAAAAAAC6k/CY5e9iFRapg/s1600/conf.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://1.bp.blogspot.com/-XU99mISxCis/UmcV2torz0I/AAAAAAAAC6k/CY5e9iFRapg/s1600/conf.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Na DialogResult encontramos alguns valores possíveis de serem retornados pela MessageBox, e um deles é o &quot;Yes&quot;. Na nossa condição if, caso o &quot;Yes&quot; tenha sido retornado ele entrará no bloco e seguirá com sua rotina de exclusão dos registros.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;Espero que tenha ajudado!&lt;br /&gt;Até mais&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhomps.blogspot.com/feeds/6239108807684635794/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://jhomps.blogspot.com/2013/10/messagebox-de-confirmacao-em-csharp.html#comment-form' title='0 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/6239108807684635794'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/6239108807684635794'/><link rel='alternate' type='text/html' href='http://jhomps.blogspot.com/2013/10/messagebox-de-confirmacao-em-csharp.html' title='Como criar um MessageBox de confirmação em C#'/><author><name>João Paulo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-XU99mISxCis/UmcV2torz0I/AAAAAAAAC6k/CY5e9iFRapg/s72-c/conf.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9021371897721484347.post-9101446565183181359</id><published>2013-09-25T14:43:00.001-03:00</published><updated>2013-09-25T14:43:46.889-03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C# Windows Forms"/><category scheme="http://www.blogger.com/atom/ns#" term="Cronometro"/><title type='text'>Contagem Regressiva em C#</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Olá leitor,&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Neste post mostro um exemplo de contagem regressiva feita com C# para WindowsForms.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;O projeto consiste em duas telas, sendo a primeira mostrada na imagem logo abaixo, onde contém um &lt;b&gt;DateTimePicker&lt;/b&gt; para o usuário escolher a data e hora que tem como alvo e um &lt;b&gt;Button &lt;/b&gt;para iniciar a contagem.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-2Vnv5i7aiL8/UkMdZ0OZXiI/AAAAAAAAC5c/C1rFGjjiO9M/s1600/cr01.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://3.bp.blogspot.com/-2Vnv5i7aiL8/UkMdZ0OZXiI/AAAAAAAAC5c/C1rFGjjiO9M/s1600/cr01.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Caso o usuário escolha uma data anterior ao momento em que o botão é clicado esta mensagem de erro é mostrada através de uma &lt;b&gt;MessageBox&lt;/b&gt;.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-GJS00z3axZI/UkMdZubpKjI/AAAAAAAAC5Q/NJZWRSoIwNo/s1600/cr02.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-GJS00z3axZI/UkMdZubpKjI/AAAAAAAAC5Q/NJZWRSoIwNo/s1600/cr02.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;A outra janela contem apenas Labels que são atualizados a cada Tick de um &lt;b&gt;Timer&lt;/b&gt; configurado com intervalo de 1000ms.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-A4FOeKf7qXM/UkMdZniyHyI/AAAAAAAAC5U/MmiWDqcX554/s1600/cr03.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://1.bp.blogspot.com/-A4FOeKf7qXM/UkMdZniyHyI/AAAAAAAAC5U/MmiWDqcX554/s1600/cr03.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Por fim, quando é chegado o momento escolhido pelo usuário outro MessageBox informa o ocorrido.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/-VIARKQvt77c/UkMdaIgb8zI/AAAAAAAAC5k/LL01GDW30DI/s1600/cr04.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://4.bp.blogspot.com/-VIARKQvt77c/UkMdaIgb8zI/AAAAAAAAC5k/LL01GDW30DI/s1600/cr04.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;A ideia é bem simples. Caso queiram ver o executável do projeto funcionando podem baixar neste link:&amp;nbsp;&lt;a href=&quot;http://goo.gl/TU9ax9&quot;&gt;http://goo.gl/TU9ax9&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Se preferirem, o código fonte completo está aqui:&amp;nbsp;&lt;a href=&quot;http://goo.gl/s7BZmt&quot;&gt;http://goo.gl/s7BZmt&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Até a próxima!&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhomps.blogspot.com/feeds/9101446565183181359/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://jhomps.blogspot.com/2013/09/contagem-regressiva-em-csharp.html#comment-form' title='0 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/9101446565183181359'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/9101446565183181359'/><link rel='alternate' type='text/html' href='http://jhomps.blogspot.com/2013/09/contagem-regressiva-em-csharp.html' title='Contagem Regressiva em C#'/><author><name>João Paulo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-2Vnv5i7aiL8/UkMdZ0OZXiI/AAAAAAAAC5c/C1rFGjjiO9M/s72-c/cr01.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9021371897721484347.post-3570173461999980347</id><published>2013-09-20T02:30:00.000-03:00</published><updated>2013-11-02T01:31:20.522-02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C# Windows Forms"/><title type='text'>Como pegar variável do Form aberto em C#</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;Olá pessoal,&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;No post anterior ensinei a passar uma variável de um Form já aberto para um novo Form(&lt;a href=&quot;http://jhomps.blogspot.com.br/2011/05/passar-variavel-para-outro-form-em-c.html&quot; target=&quot;_blank&quot;&gt;link&lt;/a&gt;). Hoje gostaria de explicar o processo inverso, ou seja: &lt;u&gt;Pegar a variável do Form que foi aberto&lt;/u&gt; e usar no Form pai(que deu origem ao novo).&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Para exemplificar criei um projeto com dois Forms, o primeiro apenas com um Button para chamar o segundo formulário e dois labels para mostrar a variável do Form a ser aberto.&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-LWvdDr5NPbY/UnRt4FW_QgI/AAAAAAAAC7I/hz49iCSCQJ0/s1600/f1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://3.bp.blogspot.com/-LWvdDr5NPbY/UnRt4FW_QgI/AAAAAAAAC7I/hz49iCSCQJ0/s1600/f1.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Já no Form secundário coloquei um Label com um TextBox para o usuário digitar algo e um botão que atribuirá o texto à uma &lt;b&gt;propriedade&lt;/b&gt; e em seguida fechará a Form.&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-8Q9DUr9qLPM/UnRuSpJdWXI/AAAAAAAAC7Q/EVP221nZAcM/s1600/f2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://1.bp.blogspot.com/-8Q9DUr9qLPM/UnRuSpJdWXI/AAAAAAAAC7Q/EVP221nZAcM/s1600/f2.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Após a Form secundária ser fechada, a Form principal pega o valor da propriedade definida na Form secundária e mostra no Label.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/-Mb5GF3lgusE/UnRuhgdqWZI/AAAAAAAAC7Y/hopbq711QlE/s1600/f3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://4.bp.blogspot.com/-Mb5GF3lgusE/UnRuhgdqWZI/AAAAAAAAC7Y/hopbq711QlE/s1600/f3.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Para fazer isto é bem simples. Na &lt;b&gt;Form secundária&lt;/b&gt;, ou seja, que terá o valor a ser usado eu criei uma propriedade do tipo String desta forma:&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;b&gt;public string TextoTeste { get; set; }&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;E então atribui um valor como se fosse uma variável comum:&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;b&gt;TextoTeste = tbTexto.Text;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;Agora na &lt;b&gt;Form principal&lt;/b&gt;, ou seja, na Form que usará o valor basta recuperar a variável desta forma:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;lblTextoRecebido.Text = novaForm.TextoTeste;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;Sendo que novaForm é o nome da variável que dei para a instância da FormSecundaria.&lt;br /&gt;&lt;br /&gt;Caso queiram ver o projeto com todo o código fonte ele pode ser baixado neste link:&amp;nbsp;&lt;a href=&quot;http://goo.gl/YfVkcf&quot;&gt;http://goo.gl/YfVkcf&lt;/a&gt;&lt;br /&gt;Se preferirem &amp;nbsp;apenas o executável, acessem este link:&amp;nbsp;&lt;a href=&quot;http://goo.gl/lM4hSH&quot;&gt;http://goo.gl/lM4hSH&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Espero ter ajudado.&lt;br /&gt;&lt;br /&gt;Até a próxima.&lt;br /&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhomps.blogspot.com/feeds/3570173461999980347/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://jhomps.blogspot.com/2013/09/pegar-variavel-do-form-aberto-em-csharp.html#comment-form' title='0 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/3570173461999980347'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/3570173461999980347'/><link rel='alternate' type='text/html' href='http://jhomps.blogspot.com/2013/09/pegar-variavel-do-form-aberto-em-csharp.html' title='Como pegar variável do Form aberto em C#'/><author><name>João Paulo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-LWvdDr5NPbY/UnRt4FW_QgI/AAAAAAAAC7I/hz49iCSCQJ0/s72-c/f1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9021371897721484347.post-7056413338452240604</id><published>2013-08-07T22:35:00.000-03:00</published><updated>2013-10-22T22:56:16.292-02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C# Windows Forms"/><title type='text'>Como confirmar antes de fechar a janela em C#</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;Em alguns casos recomenda-se confirmar a decisão que o usuário tomou, como por exemplo fechar uma janela. Pra isso podemos usar um &lt;b&gt;MessageBox&lt;/b&gt; configurado como o da imagem abaixo:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-TLKHFbXWX1w/UmccOlPgzbI/AAAAAAAAC6w/gDMENo5aLdk/s1600/fechar.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://3.bp.blogspot.com/-TLKHFbXWX1w/UmccOlPgzbI/AAAAAAAAC6w/gDMENo5aLdk/s1600/fechar.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Para isso, vamos adicionar o código abaixo no evento &lt;b&gt;FormClosing&lt;/b&gt; do Form, ficando desta maneira:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;private&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; Form1_FormClosing(&lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt;sender, &lt;span style=&quot;color: #2b91af;&quot;&gt;FormClosingEventArgs&lt;/span&gt; e)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: green;&quot;&gt;//Criar um MessageBox com os botões Sim e Não e deixar o botão 2(Não) selecionado por padrão&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #2b91af;&quot;&gt;DialogResult&lt;/span&gt;.Yes != &lt;span style=&quot;color: #2b91af;&quot;&gt;MessageBox&lt;/span&gt;.Show(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Tem certeza que deseja fechar a janela?&quot;&lt;/span&gt;, &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Confirmação&quot;&lt;/span&gt;, &lt;span style=&quot;color: #2b91af;&quot;&gt;MessageBoxButtons&lt;/span&gt;.YesNo, &lt;span style=&quot;color: #2b91af;&quot;&gt;MessageBoxIcon&lt;/span&gt;.Question, &lt;span style=&quot;color: #2b91af;&quot;&gt;MessageBoxDefaultButton&lt;/span&gt;.Button2))&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: green;&quot;&gt;//Cancelar o evento&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; e.Cancel = &lt;span style=&quot;color: blue;&quot;&gt;true&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;               &lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;O código cria o MessageBox e já compara o resultado retornado com a enum &lt;b&gt;DialogResult&lt;/b&gt;. Qualquer coisa retornada&amp;nbsp;&lt;b&gt;diferente de &#39;Yes&#39;&lt;/b&gt; faz com que o evento disparado seja cancelado, fazendo com que o Form não se feche.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt; text-align: justify;&quot;&gt;PS: Para que o próprio VisualStudio adicione o bloco de código deste evento basta dar um duplo clique no respectivo nome de evento, que fica na mesma janela das propriedades do Form.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/-C7DD4HCwtO4/Umcdh1EJawI/AAAAAAAAC64/iJ1biIpuEc8/s1600/evento.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://4.bp.blogspot.com/-C7DD4HCwtO4/Umcdh1EJawI/AAAAAAAAC64/iJ1biIpuEc8/s1600/evento.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;Agora basta fazer as alterações que precisarem, ou mesmo usar como já está.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;Até a próxima dica!&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhomps.blogspot.com/feeds/7056413338452240604/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://jhomps.blogspot.com/2013/08/confirmar-antes-de-fechar-janela-em-csharp.html#comment-form' title='0 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/7056413338452240604'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/7056413338452240604'/><link rel='alternate' type='text/html' href='http://jhomps.blogspot.com/2013/08/confirmar-antes-de-fechar-janela-em-csharp.html' title='Como confirmar antes de fechar a janela em C#'/><author><name>João Paulo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-TLKHFbXWX1w/UmccOlPgzbI/AAAAAAAAC6w/gDMENo5aLdk/s72-c/fechar.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9021371897721484347.post-64652412338265063</id><published>2013-07-18T09:34:00.000-03:00</published><updated>2013-08-12T02:41:53.553-03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C# AspNet"/><category scheme="http://www.blogger.com/atom/ns#" term="Validador"/><title type='text'>Como comparar dois TextBox em C# AspNet</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;Olá pessoal,&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Dando continuidade ao post anterior&amp;nbsp;&lt;a href=&quot;http://jhomps.blogspot.com.br/2013/07/como-validar-um-campo-obrigatorio-em-c.html&quot; target=&quot;_blank&quot;&gt;Como validar um campo obrigatório em C# AspNet&lt;/a&gt;&amp;nbsp;agora trago mais um controle de validação:&amp;nbsp;&lt;b&gt;CompareValidator&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Ele será muito útil em casos de alteração de dados críticos onde o usuário deve digitar duas vezes para confirmar, como por exemplo cadastro de emails ou alteração de senhas.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;No exemplo de hoje usaremos os seguintes itens:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;- 1 Label e 1 Text Box&lt;/b&gt;&amp;nbsp;para o usuário digitar a senha pela primeira vez.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: maroon; font-family: Consolas; font-size: 9.5pt;&quot;&gt;asp&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: maroon; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Label&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: red;&quot;&gt;ID&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;Label1&quot;&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;runat&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;server&quot;&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;AssociatedControlID&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;tbNovaSenha&quot;&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;Text&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;Nova senha:&quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;asp&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;Label&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt; &lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: maroon; font-family: Consolas; font-size: 9.5pt;&quot;&gt;asp&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: maroon; font-family: Consolas; font-size: 9.5pt;&quot;&gt;TextBox&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: red;&quot;&gt;ID&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;tbNovaSenha&quot;&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;runat&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;server&quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;asp&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;TextBox&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;- Mais 1 Label e 1 Text Box&lt;/b&gt;&amp;nbsp;para o usuário digitar a senha pela segunda vez.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: maroon; font-family: Consolas; font-size: 9.5pt;&quot;&gt;asp&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: maroon; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Label&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: red;&quot;&gt;ID&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;Label2&quot;&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;runat&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;server&quot;&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;AssociatedControlID&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;tbNovaSenhaConfirmacao&quot;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: red;&quot;&gt;Text&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;Confirme a nova senha:&quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;asp&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;Label&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;   &lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: maroon; font-family: Consolas; font-size: 9.5pt;&quot;&gt;asp&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: maroon; font-family: Consolas; font-size: 9.5pt;&quot;&gt;TextBox&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: red;&quot;&gt;ID&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;tbNovaSenhaConfirmacao&quot;&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;runat&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;server&quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;asp&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;TextBox&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;- E finalmente o&amp;nbsp;&lt;/b&gt;&lt;b&gt;CompareValidator com algumas propriedades alteradas&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: maroon; font-family: Consolas; font-size: 9.5pt;&quot;&gt;asp&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: maroon; font-family: Consolas; font-size: 9.5pt;&quot;&gt;CompareValidator&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: red;&quot;&gt;ID&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;CompareValidator1&quot;&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;runat&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;server&quot;&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;ControlToCompare&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;tbNovaSenha&quot;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt; &lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: red;&quot;&gt;ControlToValidate&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;tbNovaSenhaConfirmacao&quot;&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;ErrorMessage&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;Senhas não conferem&quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;asp&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;CompareValidator&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Nele alteramos as propriedades&amp;nbsp;&lt;b&gt;ControlToCompare e&amp;nbsp;ControlToValidate&lt;/b&gt;&amp;nbsp;para o ID dos TextBoxes acima e informamos uma mensagem de erro na &lt;b&gt;ErrorMessage.&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Caso o usuário digite valores diferentes nos TextBoxes a mensagem configurada no ErrorMessage será mostrada:&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-7IrThnW5Flo/Ugh08W_K7gI/AAAAAAAAC3E/bc8BG-lP_Ig/s1600/cv.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://1.bp.blogspot.com/-7IrThnW5Flo/Ugh08W_K7gI/AAAAAAAAC3E/bc8BG-lP_Ig/s1600/cv.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Porém se ele digitar corretamente nada é mostrado. E o melhor, tudo sem precisar enviar informações para o servidor.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-wPzeW2P7KBs/Ugh1LfmQ0ZI/AAAAAAAAC3M/0BbIisScRDU/s1600/cv2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-wPzeW2P7KBs/Ugh1LfmQ0ZI/AAAAAAAAC3M/0BbIisScRDU/s1600/cv2.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Até a próxima!&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhomps.blogspot.com/feeds/64652412338265063/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://jhomps.blogspot.com/2013/07/como-comparar-dois-textbox-em-c-aspnet.html#comment-form' title='0 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/64652412338265063'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/64652412338265063'/><link rel='alternate' type='text/html' href='http://jhomps.blogspot.com/2013/07/como-comparar-dois-textbox-em-c-aspnet.html' title='Como comparar dois TextBox em C# AspNet'/><author><name>João Paulo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-7IrThnW5Flo/Ugh08W_K7gI/AAAAAAAAC3E/bc8BG-lP_Ig/s72-c/cv.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9021371897721484347.post-8820568650721991051</id><published>2013-07-17T02:12:00.000-03:00</published><updated>2013-08-12T02:12:50.136-03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C# AspNet"/><category scheme="http://www.blogger.com/atom/ns#" term="Validador"/><title type='text'>Como validar um campo obrigatório em C# AspNet</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;Olá pessoal,&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Hoje escrevo sobre este componente do .net fácil de usar e que muitas vezes acaba esquecido e substituído por validações no CodeBehind (arquivos .cs).&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Para validar um campo e torná-lo de preenchimento obrigatório basta usar o &lt;b&gt;RequiredFieldValidator&lt;/b&gt;.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Neste exemplo vou usar os seguintes itens em uma página .aspx nova:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Label&lt;/b&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Apenas para ilustrar melhor o exemplo e dar um sentido para o TextBox.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: maroon; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;asp&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;:&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: maroon; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;Label&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;ID&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;Label1&quot;&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;runat&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;server&quot;&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;AssociatedControlID&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;tbUsuario&quot;&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;Text&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;Usuário:&quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;asp&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;Label&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;TextBox&lt;/b&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Este TextBox não aceitará valores nulos como entrada e o bloqueio é feito através da propriedade&amp;nbsp;&lt;b&gt;ControlToValidate&lt;/b&gt;&amp;nbsp;do&amp;nbsp;&lt;b&gt;RequiredFieldValidator&lt;/b&gt;.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: maroon; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;asp&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;:&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: maroon; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;TextBox&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;ID&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;tbUsuario&quot;&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;runat&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;server&quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;asp&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;TextBox&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;RequiredFieldValidator&lt;/b&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;É aqui que a validação ocorre. Neste componente configuramos a propriedade&amp;nbsp;&lt;b&gt;ControlToValidate&lt;/b&gt;&amp;nbsp;com o valor do controle que queremos validar, neste caso o TextBox &quot;&lt;b&gt;tbUsuario&lt;/b&gt;&quot;, e também colocamos uma mensagem de erro na &lt;b&gt;ErrorMessage &lt;/b&gt;para informar o usuário que o campo é obrigatório.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: maroon; font-family: Consolas; font-size: 9.5pt;&quot;&gt;asp&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: maroon; font-family: Consolas; font-size: 9.5pt;&quot;&gt;RequiredFieldValidator&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: red;&quot;&gt;ID&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;RequiredFieldValidator1&quot;&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;runat&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;server&quot;&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;ControlToValidate&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;tbUsuario&quot; &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;ErrorMessage&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;Informe um nome de usuário&quot;&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;Font-Bold&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;True&quot;&lt;/span&gt; &lt;span style=&quot;color: red;&quot;&gt;ForeColor&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;Maroon&quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;asp&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: maroon;&quot;&gt;RequiredFieldValidator&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Button&lt;/b&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;Ao clicar neste Button a página não processará enquanto o controle não receber um valor.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: maroon; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;asp&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;:&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: maroon; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;Button&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;ID&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;btnEnviar&quot;&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;runat&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;server&quot;&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;Text&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;=&quot;Enviar&quot;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;/&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Feito isto, a validação já deverá funcionar e a página ficará parecida com esta abaixo:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Caso o usuário não seja informado o erro é mostrado:&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-wYAYLsHCyhw/UghuBBAxArI/AAAAAAAAC2s/ws1P2s6hmqY/s1600/rfv.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://1.bp.blogspot.com/-wYAYLsHCyhw/UghuBBAxArI/AAAAAAAAC2s/ws1P2s6hmqY/s1600/rfv.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Caso preencha o campo a mensagem de erro desaparece automaticamente:&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-OKfHMZHeqPE/UghuLEYmWEI/AAAAAAAAC20/ah7_nFXWgkQ/s1600/rfv2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-OKfHMZHeqPE/UghuLEYmWEI/AAAAAAAAC20/ah7_nFXWgkQ/s1600/rfv2.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Por hora é isso.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Espero que tenham gostado.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Abraço!&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhomps.blogspot.com/feeds/8820568650721991051/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://jhomps.blogspot.com/2013/07/como-validar-um-campo-obrigatorio-em-c.html#comment-form' title='0 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/8820568650721991051'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/8820568650721991051'/><link rel='alternate' type='text/html' href='http://jhomps.blogspot.com/2013/07/como-validar-um-campo-obrigatorio-em-c.html' title='Como validar um campo obrigatório em C# AspNet'/><author><name>João Paulo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-wYAYLsHCyhw/UghuBBAxArI/AAAAAAAAC2s/ws1P2s6hmqY/s72-c/rfv.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9021371897721484347.post-4881488458031200034</id><published>2013-06-30T01:46:00.000-03:00</published><updated>2013-09-27T01:47:21.062-03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C# Windows Forms"/><title type='text'>Inverter Array manualmente em C#</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;Olá!&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Aqui vai uma dica rápida para casos em que não desejamos usar o método&amp;nbsp;&lt;b&gt;Array.Reverse(seuArray)&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Abaixo está todo o código que fiz, já comentado explicando o que foi feito em cada linha.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;//Variáveis que receberão os valores (para testar se a inversão funcionou corretamente)&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;string&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;strNormal = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;&quot;&lt;/span&gt;, strInvertido = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;&quot;&lt;/span&gt;;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: green; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;//Declarando array&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;int&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;[] arrayNumeros = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;//Guardando valores do arrayNumeros na string strNormal para comparar a saída depois&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;for&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;(&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; i = 0; i &amp;lt; arrayNumeros.Length; i++)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; strNormal += arrayNumeros[i];&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;//Declarando o novo array que receberá os valores invertidos já com o tamanho do anterior&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;int&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;[] arrayInvertido = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;[arrayNumeros.Length];&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;//Pegar a última posição do arrayNumeros e jogar na primeira do arrayInvertido&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;for&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;(&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; i = 0; i &amp;lt; arrayNumeros.Length; i++)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: green;&quot;&gt;//Subtrair 1 pois os índices dos Arrays começam a partir do 0&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arrayInvertido[i] = arrayNumeros[arrayNumeros.Length - 1 - i];&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;//Guardando valores do arrayInvertido na string strInvertido para comparar a saída depois&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;for&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;(&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; i = 0; i &amp;lt; arrayInvertido.Length; i++)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; strInvertido += arrayInvertido[i];&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;color: green; font-family: Consolas; font-size: 9.5pt;&quot;&gt;//Jogar as strings num label para ver se funcionou corretamente&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;label1.Text = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Normal: &quot;&lt;/span&gt; + strNormal +&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;\n&quot;&lt;/span&gt; +&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Invertido: &quot;&lt;/span&gt; + strInvertido;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;                                                           &lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;text-align: justify;&quot;&gt;Espero que o código ajude.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;text-align: justify;&quot;&gt;Fico por aqui.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;text-align: justify;&quot;&gt;Até a próxima!&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhomps.blogspot.com/feeds/4881488458031200034/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://jhomps.blogspot.com/2013/06/inverter-array-manualmente-em-csharp.html#comment-form' title='0 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/4881488458031200034'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/4881488458031200034'/><link rel='alternate' type='text/html' href='http://jhomps.blogspot.com/2013/06/inverter-array-manualmente-em-csharp.html' title='Inverter Array manualmente em C#'/><author><name>João Paulo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9021371897721484347.post-669774425979956306</id><published>2013-06-04T23:38:00.000-03:00</published><updated>2013-06-05T00:36:53.911-03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C# Windows Forms"/><title type='text'>Permitir apenas uma instância do programa em C#</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Olá leitor,&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Abaixo coloco um pequeno projeto que impede duas instâncias do mesmo programa em C# serem abertas no mesmo computador. Caso o usuário tente abrir, a seguinte MessageBox será mostrada e a segunda instância será fechada.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-EcNOpCF1xr8/Ua6ixYwFwvI/AAAAAAAAC04/RXyIH5pU8OE/s1600/erroDuplicado.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://3.bp.blogspot.com/-EcNOpCF1xr8/Ua6ixYwFwvI/AAAAAAAAC04/RXyIH5pU8OE/s1600/erroDuplicado.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;O código é baseado no post &quot;&lt;a href=&quot;http://jhomps.blogspot.com.br/2013/05/verificar-se-processo-esta-rodando-com-c.html&quot; target=&quot;_blank&quot;&gt;Verificar se processo está rodando com C#&lt;/a&gt;&quot; e possui apenas um pequeno trecho adicional no método Main() da classe &lt;b&gt;Program.cs&lt;/b&gt; que faz este trabalho. Ficou assim:&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; Main()&lt;/span&gt;&lt;br /&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: green;&quot;&gt;//Pega o nome do processo deste programa&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; nomeProcesso = &lt;span style=&quot;color: #2b91af;&quot;&gt;Process&lt;/span&gt;.GetCurrentProcess().ProcessName;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: green;&quot;&gt;//Busca os processos com este nome que estão em execução&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Process&lt;/span&gt;[] processos = &lt;span style=&quot;color: #2b91af;&quot;&gt;Process&lt;/span&gt;.GetProcessesByName(nomeProcesso);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: green;&quot;&gt;//Se já houver um aberto&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (processos.Length &amp;gt; 1)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: green;&quot;&gt;//Mostra mensagem de erro e finaliza&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;MessageBox&lt;/span&gt;.Show(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Não é possível abrir duas instâncias deste programa.&quot;&lt;/span&gt;, &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Erro&quot;&lt;/span&gt;, &lt;span style=&quot;color: #2b91af;&quot;&gt;MessageBoxButtons&lt;/span&gt;.OK, &lt;span style=&quot;color: #2b91af;&quot;&gt;MessageBoxIcon&lt;/span&gt;.Exclamation);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Application&lt;/span&gt;.Exit();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: green;&quot;&gt;//Caso contrário continue normalmente&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;else&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Application&lt;/span&gt;.EnableVisualStyles();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: #2b91af;&quot;&gt;Application&lt;/span&gt;.SetCompatibleTextRenderingDefault(&lt;span style=&quot;color: blue;&quot;&gt;false&lt;/span&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Application&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;.Run(&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;Form1&lt;/span&gt;());&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Lembrando que para usar a classe &lt;b&gt;Process&lt;/b&gt; você deve importar o &lt;b&gt;System.Diagnostics&lt;/b&gt; no início do código.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;O .exe compilado para o .NET Framework 4.0 do programa pode ser baixado no seguinte link: &amp;nbsp;&lt;a href=&quot;http://goo.gl/f93Qw&quot;&gt;http://goo.gl/f93Qw&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;O projeto e código fonte completo do programa em C# criado com o VisualStudio2010 está em:&amp;nbsp;&lt;a href=&quot;http://goo.gl/myldp&quot;&gt;http://goo.gl/myldp&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Até a próxima!&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhomps.blogspot.com/feeds/669774425979956306/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://jhomps.blogspot.com/2013/06/permitir-apenas-uma-instancia-csharp.html#comment-form' title='3 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/669774425979956306'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/669774425979956306'/><link rel='alternate' type='text/html' href='http://jhomps.blogspot.com/2013/06/permitir-apenas-uma-instancia-csharp.html' title='Permitir apenas uma instância do programa em C#'/><author><name>João Paulo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-EcNOpCF1xr8/Ua6ixYwFwvI/AAAAAAAAC04/RXyIH5pU8OE/s72-c/erroDuplicado.jpg" height="72" width="72"/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9021371897721484347.post-2053100384591777314</id><published>2013-05-19T15:07:00.004-03:00</published><updated>2013-05-19T15:08:07.276-03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C# Windows Forms"/><title type='text'>Verificar se processo está rodando com C#</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Olá,&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;O pequeno código em C# abaixo serve para verificar se um processo está em execução no Windows. Tudo que ele faz é pegar um Array com todos os processos existentes e comparar os nomes com o escrito no TextBox.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Exemplos de uso:&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/-2npVxkT6FMQ/UZjy6tFZyMI/AAAAAAAAC0o/Zet2v4Bja34/s1600/naorodando.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://4.bp.blogspot.com/-2npVxkT6FMQ/UZjy6tFZyMI/AAAAAAAAC0o/Zet2v4Bja34/s1600/naorodando.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-ua54YNifZWA/UZjy3K6WsCI/AAAAAAAAC0g/lKOrl4IhHuc/s1600/rodando.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-ua54YNifZWA/UZjy3K6WsCI/AAAAAAAAC0g/lKOrl4IhHuc/s1600/rodando.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;O .exe compilado para o .NET Framework 4.0 do programa pode ser baixado no seguinte link:&amp;nbsp;&lt;a href=&quot;http://goo.gl/dtGs0&quot;&gt;http://goo.gl/dtGs0&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;O projeto e &lt;b&gt;código fonte comentado&lt;/b&gt; completo do programa em C# criado com o VisualStudio2010:&amp;nbsp;&lt;a href=&quot;http://goo.gl/0qArS&quot;&gt;http://goo.gl/0qArS&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Abraço&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhomps.blogspot.com/feeds/2053100384591777314/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://jhomps.blogspot.com/2013/05/verificar-se-processo-esta-rodando-com-c.html#comment-form' title='2 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/2053100384591777314'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/2053100384591777314'/><link rel='alternate' type='text/html' href='http://jhomps.blogspot.com/2013/05/verificar-se-processo-esta-rodando-com-c.html' title='Verificar se processo está rodando com C#'/><author><name>João Paulo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-2npVxkT6FMQ/UZjy6tFZyMI/AAAAAAAAC0o/Zet2v4Bja34/s72-c/naorodando.jpg" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9021371897721484347.post-9071498211717521854</id><published>2013-05-18T03:45:00.001-03:00</published><updated>2013-05-18T03:45:38.990-03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C# Windows Forms"/><category scheme="http://www.blogger.com/atom/ns#" term="Dicas"/><title type='text'>Limpar todos os textBox de uma vez em C#</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;Olá leitor,&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Abaixo está um método simples que serve para zerar todos os &lt;b&gt;textBox&lt;/b&gt;&amp;nbsp;de seu formulário de uma única vez. Em casos onde há poucos controles para limpar o conteúdo o bom e velho textBox1.Text = String.Empty ainda pode ser a melhor opção, mas imagine formulários com 20 ou até mais campos. O código ficaria bem feio, não?&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-8AXX0A48JoA/UZci2uQJcLI/AAAAAAAACzo/4rPK4aVwTVI/s1600/textbox.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-8AXX0A48JoA/UZci2uQJcLI/AAAAAAAACzo/4rPK4aVwTVI/s1600/textbox.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Ao invés de limpar um por um, a partir de agora você pode usar este método:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;code&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;private&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; limparTextBoxes(&lt;span style=&quot;color: #2b91af;&quot;&gt;Control&lt;/span&gt;.&lt;span style=&quot;color: #2b91af;&quot;&gt;ControlCollection&lt;/span&gt; controles)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: green;&quot;&gt;//Faz um laço para todos os controles passados no parâmetro&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;foreach&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt; (&lt;span style=&quot;color: #2b91af;&quot;&gt;Control&lt;/span&gt; ctrl &lt;span style=&quot;color: blue;&quot;&gt;in&lt;/span&gt; controles)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: green;&quot;&gt;//Se o contorle for um TextBox...&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;if&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt; (ctrl &lt;span style=&quot;color: blue;&quot;&gt;is&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;TextBox&lt;/span&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ((&lt;span style=&quot;color: #2b91af;&quot;&gt;TextBox&lt;/span&gt;)(ctrl)).Text = &lt;span style=&quot;color: #2b91af;&quot;&gt;String&lt;/span&gt;.Empty;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;E para chamar o método basta usar o seguinte comando no evento desejado:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;code&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;limparTextBoxes(&lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.Controls);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Por hoje é só. Espero que ajude.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;[]&#39;s&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhomps.blogspot.com/feeds/9071498211717521854/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://jhomps.blogspot.com/2013/05/limpar-todos-os-textbox-de-uma-vez-em-c.html#comment-form' title='0 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/9071498211717521854'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/9071498211717521854'/><link rel='alternate' type='text/html' href='http://jhomps.blogspot.com/2013/05/limpar-todos-os-textbox-de-uma-vez-em-c.html' title='Limpar todos os textBox de uma vez em C#'/><author><name>João Paulo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-8AXX0A48JoA/UZci2uQJcLI/AAAAAAAACzo/4rPK4aVwTVI/s72-c/textbox.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9021371897721484347.post-7594061657082655940</id><published>2013-05-15T02:14:00.001-03:00</published><updated>2013-05-15T22:27:39.534-03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C# Windows Forms"/><title type='text'>Ler e escrever arquivos txt e caixas de diálogos de arquivo em C#</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Olá leitor,&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Deixo aqui um simples exemplo de como salvar e recuperar dados de arquivos txt em C#. Além disso também fiz os exemplos usando o&amp;nbsp;&lt;b&gt;saveFileDialog&lt;/b&gt;, que abre uma caixa de diálogo de perguntando onde deseja &amp;nbsp;que o arquivo seja salvo e o &lt;b&gt;openFileDialog&lt;/b&gt;, que serve para localizar e abrir um arquivo.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;A tela principal do programa ficou assim:&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-AEKQukjBgIg/UZMZWvzbjUI/AAAAAAAACy8/u8SRQNAO-Mw/s1600/principal.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://3.bp.blogspot.com/-AEKQukjBgIg/UZMZWvzbjUI/AAAAAAAACy8/u8SRQNAO-Mw/s1600/principal.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Ao digitar um texto no textBox esquerdo e clicar em salvar, a caixa da imagem abaixo será mostrada. Nela você pode configurar propriedades como a pasta padrão que será aberta (&lt;b&gt;InitialDirectory&lt;/b&gt;), o filtro de tipos de arquivo mostrados (&lt;b&gt;Filter&lt;/b&gt;) o título do formulário(&lt;b&gt;Title&lt;/b&gt;) e mais algumas coisas.&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-C5zA1KEKyyE/UZMZX0HFltI/AAAAAAAACzE/CsP5xGv7wpo/s1600/ofd.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://1.bp.blogspot.com/-C5zA1KEKyyE/UZMZX0HFltI/AAAAAAAACzE/CsP5xGv7wpo/s1600/ofd.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;No lado direito da tela principal tem o outro textBox que mostrará um arquivo escolhido através do botão &quot;Procurar&quot;, que por sua vez também abrirá uma tela similar à do &quot;Salvar&quot;.&lt;br /&gt;&lt;br /&gt;Para chamar estas telas eu arrastei os componentes diretamente para o formulário em que quis usar, como mostra a imagem a seguir:&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/-Chpw1fiNZuI/UZQr2c7u47I/AAAAAAAACzU/LcliHoO7nPY/s1600/comp.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;439&quot; src=&quot;http://4.bp.blogspot.com/-Chpw1fiNZuI/UZQr2c7u47I/AAAAAAAACzU/LcliHoO7nPY/s640/comp.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Também é possível usá-los da mesma forma sem precisar arrastar, criando-os diretamente no código desta forma:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;OpenFileDialog&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; abreArquivo = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;OpenFileDialog&lt;/span&gt;();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;color: #2b91af; font-family: Consolas; font-size: 9.5pt;&quot;&gt;SaveFileDialog&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; salvaArquivo = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;color: #2b91af;&quot;&gt;SaveFileDialog&lt;/span&gt;();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Para verem melhor o programa funcionando é possível baixar o .exe compilado para o .NET Framework 4.0 do programa pode seguinte link:&amp;nbsp;&lt;a href=&quot;http://goo.gl/SIbyG&quot;&gt;http://goo.gl/SIbyG&lt;/a&gt;&lt;br /&gt;O projeto e código fonte completo do programa em C# criado com o VisualStudio2010 está aqui:&amp;nbsp;&lt;a href=&quot;http://goo.gl/fTeQY&quot;&gt;http://goo.gl/fTeQY&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Espero que tenha ajudado&lt;br /&gt;&lt;br /&gt;Abraço</content><link rel='replies' type='application/atom+xml' href='http://jhomps.blogspot.com/feeds/7594061657082655940/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://jhomps.blogspot.com/2013/05/ler-e-escrever-arquivos-txt-csharp.html#comment-form' title='1 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/7594061657082655940'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/7594061657082655940'/><link rel='alternate' type='text/html' href='http://jhomps.blogspot.com/2013/05/ler-e-escrever-arquivos-txt-csharp.html' title='Ler e escrever arquivos txt e caixas de diálogos de arquivo em C#'/><author><name>João Paulo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-AEKQukjBgIg/UZMZWvzbjUI/AAAAAAAACy8/u8SRQNAO-Mw/s72-c/principal.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9021371897721484347.post-7176470682710048776</id><published>2013-04-29T15:22:00.000-03:00</published><updated>2013-05-03T15:23:51.092-03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C# Windows Forms"/><category scheme="http://www.blogger.com/atom/ns#" term="MdiParent"/><title type='text'>Exemplos de formulários pai e filho em C#</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;Olá leitores,&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Abaixo mostro um pequeno exemplo, porém muito útil, de como trabalhar com formulários pai e filho.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Isto serve para que o programa feito seja baseado todo na janela principal e as demais telas sempre fiquem dentro dela, como mostra a imagem abaixo.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/--erVHG-vYuo/UYP7hQL-NTI/AAAAAAAACto/O8LlURrO5bI/s1600/formsfilho.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;480&quot; src=&quot;http://4.bp.blogspot.com/--erVHG-vYuo/UYP7hQL-NTI/AAAAAAAACto/O8LlURrO5bI/s640/formsfilho.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;No projeto estão 6 formulários, sendo um Principal que será o pai e por isso está com a propriedade &lt;b&gt;IsMdiContainer&lt;/b&gt; como &lt;b&gt;True&lt;/b&gt; e outros 5 formulários filhos, que não precisam de alterações.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;No formulário principal está um &lt;b&gt;toolStrip&lt;/b&gt; com 5 botões, um para cada formulário. Nos eventos de clique dos botões estão as chamadas do método que fiz para abrir os formulários filhos sem deixar que eles fiquem duplicados.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Se o form já estiver aberto ele apenas ganhará o Focus() novamente, caso contrário será mostrada uma nova instância dele.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Para entenderem melhor vocês podem baixar o .exe compilado para o .NET Framework 4.0 do programa no seguinte link:&amp;nbsp;&lt;a href=&quot;http://goo.gl/ikfSv&quot;&gt;http://goo.gl/ikfSv&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;O projeto e código fonte completo do programa criado com o VisualStudio2010 está neste link:&amp;nbsp;&lt;a href=&quot;http://goo.gl/rPAEr&quot;&gt;http://goo.gl/rPAEr&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Espero ter ajudado.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Até a próxima&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhomps.blogspot.com/feeds/7176470682710048776/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://jhomps.blogspot.com/2013/04/exemplos-de-formularios-pai-e-filho-em-c.html#comment-form' title='0 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/7176470682710048776'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/7176470682710048776'/><link rel='alternate' type='text/html' href='http://jhomps.blogspot.com/2013/04/exemplos-de-formularios-pai-e-filho-em-c.html' title='Exemplos de formulários pai e filho em C#'/><author><name>João Paulo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/--erVHG-vYuo/UYP7hQL-NTI/AAAAAAAACto/O8LlURrO5bI/s72-c/formsfilho.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9021371897721484347.post-8893729842179068642</id><published>2013-04-26T02:56:00.001-03:00</published><updated>2013-04-26T02:56:27.013-03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C# Windows Forms"/><category scheme="http://www.blogger.com/atom/ns#" term="Random"/><title type='text'>Gerar número aleatório em C#</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Olá leitor,&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Abaixo está um simples programa que demonstra o uso básico da classe Random para gerar números aleatórios em C#&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/-w3mEsB0An-4/UXRQfIDAMeI/AAAAAAAACrQ/G4prSmMLOqk/s1600/aleatorio.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://4.bp.blogspot.com/-w3mEsB0An-4/UXRQfIDAMeI/AAAAAAAACrQ/G4prSmMLOqk/s1600/aleatorio.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;O que é feito é ao clicar no botão &quot;Gerar&quot;:&lt;br /&gt;&lt;br /&gt;Uma nova variável do tipo random é criada:&lt;br /&gt;&lt;code&gt;Random rnd = new Random();&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Um valor de &lt;b&gt;maior ou igual&lt;/b&gt; a 0 e &lt;b&gt;menor&lt;/b&gt; que 1000 é sorteado e passado ao TextBox, já pulando uma linha.&lt;br /&gt;&lt;code&gt;tbNumeros.Text += rnd.Next(0, 1000) + Environment.NewLine;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Para um conteúdo completo sobre a classe recomendo que acessem &lt;a href=&quot;http://msdn.microsoft.com/pt-br/library/vstudio/system.random.aspx&quot; target=&quot;_blank&quot;&gt;este link&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;O .exe compilado para o .NET Framework 4.0 do programa pode ser baixado no seguinte link: &lt;a href=&quot;http://goo.gl/oMBGP&quot;&gt;http://goo.gl/oMBGP&lt;/a&gt;&lt;br /&gt;O projeto e código fonte completo do programa em C# criado com o VisualStudio2010:&amp;nbsp;&lt;a href=&quot;http://goo.gl/FxzpG&quot;&gt;http://goo.gl/FxzpG&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Abraço</content><link rel='replies' type='application/atom+xml' href='http://jhomps.blogspot.com/feeds/8893729842179068642/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://jhomps.blogspot.com/2013/04/gerar-numero-aleatorio-em-c.html#comment-form' title='2 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/8893729842179068642'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/8893729842179068642'/><link rel='alternate' type='text/html' href='http://jhomps.blogspot.com/2013/04/gerar-numero-aleatorio-em-c.html' title='Gerar número aleatório em C#'/><author><name>João Paulo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-w3mEsB0An-4/UXRQfIDAMeI/AAAAAAAACrQ/G4prSmMLOqk/s72-c/aleatorio.png" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9021371897721484347.post-2326314437113644352</id><published>2013-04-12T02:14:00.001-03:00</published><updated>2013-04-12T02:14:58.832-03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C# Windows Forms"/><title type='text'>Criar arquivo txt em C#</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;Olá leitor,&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Neste post mostrei uma forma muito simples de criar arquivos com extensão .txt em C#.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Para isso utilizarei como base o &lt;a href=&quot;http://jhomps.blogspot.com.br/2011/02/gerador-de-senhas-c.html&quot; target=&quot;_blank&quot;&gt;Gerador de Senhas&lt;/a&gt; que eu havia postado algum tempo atrás, porém um pouco melhorado.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-mDc4nKlHY_U/UWeWjnF3PTI/AAAAAAAACqM/BlVz6ouNahk/s1600/gerador_de_senhas.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;365&quot; src=&quot;http://3.bp.blogspot.com/-mDc4nKlHY_U/UWeWjnF3PTI/AAAAAAAACqM/BlVz6ouNahk/s400/gerador_de_senhas.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;O que o programa faz é simplesmente pedir que o usuário informe a quantidade de senhas e quantos caracteres cada senha terá através das &lt;b&gt;TrackBars&lt;/b&gt;. Após clicar em &quot;Gerar Senhas&quot; ele habilita para o usuário o botão &quot;Gerar txt&quot; e este ao ser pressionado pede que o usuário selecione uma pasta em que o arquivo seja criado.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-VWGejDuUi7g/UWeWxG2RzAI/AAAAAAAACqU/PbjlnydgeeE/s1600/gerador_de_senhas2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;366&quot; src=&quot;http://3.bp.blogspot.com/-VWGejDuUi7g/UWeWxG2RzAI/AAAAAAAACqU/PbjlnydgeeE/s400/gerador_de_senhas2.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;O evento clique do botão &quot;Gerar txt&quot; primeiramente usa a classe&amp;nbsp;&lt;b&gt;FolderBrowserDialog&lt;/b&gt;&amp;nbsp;para que o usuário possa escolher onde deseja salvar o arquivo. (porém você pode pular esta etapa e forçar que o arquivo seja gravado em um local fixo determinado dentro do código)&lt;br /&gt;&lt;br /&gt;Em seguida ele usa o método&amp;nbsp;&lt;b&gt;WriteAllText()&lt;/b&gt; da classe &lt;b&gt;File &lt;i&gt;(System.IO.File)&lt;/i&gt;&lt;/b&gt;&amp;nbsp;para gravar o arquivo. Este método pede apenas o caminho do arquivo a ser criado e o seu conteúdo.&lt;br /&gt;&lt;br /&gt;Caso já exista um arquivo com o mesmo nome ele o substituirá, portanto convém criar bloqueios e regras para que o usuário possa escolher o que deseja fazer.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Para testar o funcionamento você pode baixar o programa compilado neste link: &lt;a href=&quot;http://goo.gl/cLbIK&quot;&gt;http://goo.gl/cLbIK&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Se preferir, baixe o código fonte completo do criador de txt em C# neste link: &lt;a href=&quot;http://goo.gl/OCdqL&quot;&gt;http://goo.gl/OCdqL&lt;/a&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhomps.blogspot.com/feeds/2326314437113644352/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://jhomps.blogspot.com/2013/04/criar-arquivo-txt-em-c.html#comment-form' title='1 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/2326314437113644352'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/2326314437113644352'/><link rel='alternate' type='text/html' href='http://jhomps.blogspot.com/2013/04/criar-arquivo-txt-em-c.html' title='Criar arquivo txt em C#'/><author><name>João Paulo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-mDc4nKlHY_U/UWeWjnF3PTI/AAAAAAAACqM/BlVz6ouNahk/s72-c/gerador_de_senhas.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9021371897721484347.post-6838386493014514105</id><published>2013-03-31T01:10:00.000-03:00</published><updated>2013-05-06T01:12:30.159-03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C# Windows Forms"/><category scheme="http://www.blogger.com/atom/ns#" term="Confirmação"/><title type='text'>Caixa com mensagem de confirmação de saída em C#</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Olá leitores,&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Abaixo está um clássico exemplo para criar um&amp;nbsp;&lt;b&gt;MessageBox &lt;/b&gt;que pede confirmação de saída para o usuário. No exemplo abaixo foi criada uma tela com apenas um Button para fechar a aplicação.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;No evento &lt;b&gt;Click&lt;/b&gt; deste Button está o seguinte código:&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;/div&gt;&lt;code&gt;&lt;/code&gt;&lt;br /&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;code&gt;&lt;/code&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; (&lt;span style=&quot;color: #2b91af;&quot;&gt;MessageBox&lt;/span&gt;.Show(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Tem certeza que deseja sair da aplicação?&quot;&lt;/span&gt;, &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Confirmação&quot;&lt;/span&gt;, &lt;span style=&quot;color: #2b91af;&quot;&gt;MessageBoxButtons&lt;/span&gt;.YesNo, &lt;span style=&quot;color: #2b91af;&quot;&gt;MessageBoxIcon&lt;/span&gt;.Question) == &lt;span style=&quot;color: #2b91af;&quot;&gt;DialogResult&lt;/span&gt;.Yes)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;code&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.Close();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/code&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Ele mostra uma MessageBox com o texto e título, os botões disponíveis e o ícone. O resultado será comparado com o DialogResult.Yes, assim retornando verdadeiro quando o usuário clicar em sim.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;E o resultado ao clicar nele é este da imagem:&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-WMj5yI5XOsk/UYcoZLLwdAI/AAAAAAAACvA/1iWO9NHPccI/s1600/confirma%C3%A7%C3%A3o.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-WMj5yI5XOsk/UYcoZLLwdAI/AAAAAAAACvA/1iWO9NHPccI/s1600/confirma%C3%A7%C3%A3o.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;Também podemos usar o evento &lt;b&gt;FormClosing&lt;/b&gt; do Form para quando o usuário fechar diretamente pelo &quot;X&quot;. Neste caso, se o usuário clicar em &quot;Não desejo sair&quot;, devemos cancelar o evento da seguinte forma:&lt;br /&gt;&lt;br /&gt;Dar duplo clique no evento &lt;b&gt;FormClosing&lt;/b&gt; do Form&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-EwigtK75XXE/UYcrLtfSEOI/AAAAAAAACvQ/XdFRu-1rqP0/s1600/evento..jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-EwigtK75XXE/UYcrLtfSEOI/AAAAAAAACvQ/XdFRu-1rqP0/s1600/evento..jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;E no método que o Visual Studio criar, adicionar o seguinte código:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;code&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;private&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; Form1_FormClosing(&lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt;sender, &lt;span style=&quot;color: #2b91af;&quot;&gt;FormClosingEventArgs&lt;/span&gt; e)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;code&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #2b91af;&quot;&gt;MessageBox&lt;/span&gt;.Show(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Tem certeza que deseja sair da aplicação?&quot;&lt;/span&gt;, &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Confirmação&quot;&lt;/span&gt;, &lt;span style=&quot;color: #2b91af;&quot;&gt;MessageBoxButtons&lt;/span&gt;.YesNo, &lt;span style=&quot;color: #2b91af;&quot;&gt;MessageBoxIcon&lt;/span&gt;.Question) == &lt;span style=&quot;color: #2b91af;&quot;&gt;DialogResult&lt;/span&gt;.No)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; e.Cancel = &lt;span style=&quot;color: blue;&quot;&gt;true&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;/code&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Neste caso, a comparação é feita com o &quot;DialogResult.No&quot;, pois se o usuário não quiser sair será atribuído o valor true para o atributo Cancel.&lt;br /&gt;&lt;br /&gt;Além de confirmações para sair da aplicação, também é possível fazer várias outras coisas com este modelo, como confirmação de exclusão, inserção, atualização de registros, etc. Basta seguir a mesma lógica.&lt;br /&gt;&lt;br /&gt;Até o próximo post.&lt;br /&gt;Abraço&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhomps.blogspot.com/feeds/6838386493014514105/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://jhomps.blogspot.com/2013/03/mensagem-de-confirmacao-csharp.html#comment-form' title='0 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/6838386493014514105'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/6838386493014514105'/><link rel='alternate' type='text/html' href='http://jhomps.blogspot.com/2013/03/mensagem-de-confirmacao-csharp.html' title='Caixa com mensagem de confirmação de saída em C#'/><author><name>João Paulo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-WMj5yI5XOsk/UYcoZLLwdAI/AAAAAAAACvA/1iWO9NHPccI/s72-c/confirma%C3%A7%C3%A3o.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9021371897721484347.post-6163272056649736028</id><published>2013-03-06T13:46:00.000-03:00</published><updated>2013-10-07T20:40:15.434-03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C# Windows Forms"/><title type='text'>Manter janelas sempre quadradas em C#</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;Olá!&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Nesta postagem trago uma rápida dica para manter sua janela sempre com a proporção 1:1, ou seja, quadrada.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Sempre que a janela é redimensionada em C#, assim que o botão do mouse é solto o evento &lt;b&gt;ResizeEnd &lt;/b&gt;é disparado. É nele que igualaremos as dimensões, usando a maior delas como valor em comum.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;O código ficará assim:&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;private&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; Form1_ResizeEnd(&lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt;sender, &lt;span style=&quot;color: #2b91af;&quot;&gt;EventArgs&lt;/span&gt; e)&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: green;&quot;&gt;//Define o valor das propriedades iguais, usando o maior deles como base&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;if&lt;/span&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt; (&lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.Width &amp;gt; &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.Height)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.Height = &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.Width;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;font-family: Consolas; font-size: 9.5pt; mso-ansi-language: EN-US;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;this&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;.Width = &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.Height;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 0.0001pt;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;Espero que ajude.&lt;br /&gt;Até a próxima!</content><link rel='replies' type='application/atom+xml' href='http://jhomps.blogspot.com/feeds/6163272056649736028/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://jhomps.blogspot.com/2013/03/manter-janelas-sempre-quadradas-em-charp.html#comment-form' title='0 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/6163272056649736028'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/6163272056649736028'/><link rel='alternate' type='text/html' href='http://jhomps.blogspot.com/2013/03/manter-janelas-sempre-quadradas-em-charp.html' title='Manter janelas sempre quadradas em C#'/><author><name>João Paulo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9021371897721484347.post-5719798512803267864</id><published>2013-02-04T12:30:00.004-02:00</published><updated>2013-02-04T12:31:49.493-02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C# AspNet"/><title type='text'>Cálculo da área de figuras geométricas em C#</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Olá leitores,&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Hoje trago um pequeno programa que faz cálculos simples da área das seguintes figuras geométricas:&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;Cálculo da área de quadrados&lt;/li&gt;&lt;li&gt;Cálculo da área de círculos&lt;/li&gt;&lt;li&gt;Cálculo da área de triângulos escalenos&lt;/li&gt;&lt;li&gt;Cálculo da área de triângulos equiláteros&lt;/li&gt;&lt;li&gt;Cálculo da área de retângulos&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;A tela principal é a mostrada abaixo. Nela estão 4 &lt;b&gt;buttons&lt;/b&gt;, cada um com uma imagem configurada na propriedade &lt;b&gt;&quot;Image&quot;&lt;/b&gt;.&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-4R-nyy_OnX8/UQ_DqsLMdWI/AAAAAAAACgA/dqVC9Tqr7RQ/s1600/area.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; src=&quot;http://1.bp.blogspot.com/-4R-nyy_OnX8/UQ_DqsLMdWI/AAAAAAAACgA/dqVC9Tqr7RQ/s400/area.jpg&quot; width=&quot;321&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Ao clicar em algum dos botões uma outra tela será mostrada solicitando informações como base, altura, raio, e outros dados dependendo da figura escolhida. Assim que o usuário digita as informações o resultado aparece automaticamente no &lt;b&gt;label&lt;/b&gt;&amp;nbsp;oculto logo abaixo.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/-5Vx9O9oZoKY/UQ_FdbQedFI/AAAAAAAACgI/AWuIh5ddvk0/s1600/info.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;http://4.bp.blogspot.com/-5Vx9O9oZoKY/UQ_FdbQedFI/AAAAAAAACgI/AWuIh5ddvk0/s320/info.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;O .exe compilado para o .NET Framework 4.0 do programa pode ser baixado no seguinte link: &lt;a href=&quot;http://goo.gl/D1RCH&quot;&gt;http://goo.gl/D1RCH&lt;/a&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Caso queiram ver o projeto e código fonte completo do programa calculador de área de figuras geométricas em C# criado com o VisualStudio2010 acesse&amp;nbsp;&lt;a href=&quot;http://goo.gl/jNrbZ&quot;&gt;http://goo.gl/jNrbZ&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Até a próxima.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhomps.blogspot.com/feeds/5719798512803267864/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://jhomps.blogspot.com/2013/02/calculo-da-area-de-figuras-geometricas.html#comment-form' title='0 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/5719798512803267864'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/5719798512803267864'/><link rel='alternate' type='text/html' href='http://jhomps.blogspot.com/2013/02/calculo-da-area-de-figuras-geometricas.html' title='Cálculo da área de figuras geométricas em C#'/><author><name>João Paulo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-4R-nyy_OnX8/UQ_DqsLMdWI/AAAAAAAACgA/dqVC9Tqr7RQ/s72-c/area.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9021371897721484347.post-474340509990386338</id><published>2013-01-20T01:46:00.000-02:00</published><updated>2013-01-20T15:44:23.811-02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="HTML/CSS"/><title type='text'>Fazer div com borda arredondada sem imagens HTML/CSS</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;Olá a todos.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;A mais ou menos dois anos atrás, enquanto ainda estava aprendendo o básico de HTML e web em geral, lembro-me de querer fazer um layout com bordas arredondadas, o que até então era um pouco complicado e necessitava do uso de imagens, ou de códigos enormes e feios, como &lt;a href=&quot;http://codigofonte.uol.com.br/codigos/codigo.asp?categoria=css&amp;amp;subcategoria=efeitos&amp;amp;codigo=criar-bordas-arredondadas-sem-utilizar-imagens&amp;amp;aux=&amp;amp;7&amp;amp;cachecommand=bypass&amp;amp;cachecommand=bypass&quot; target=&quot;_blank&quot;&gt;este&lt;/a&gt;.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Para o bem de todos o CSS3 trouxe a nova propriedade &lt;code&gt;border-radius&lt;/code&gt;, que faz exatamente isto com apenas uma linha de código.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Por exemplo, se quisermos criar uma div com os quatro cantos arredondados em 25pixels (de onde começa até onde termina o canto), basta adicionarmos no estilo a propriedade &lt;b&gt;&lt;code&gt;border-radius: 25px;&lt;/code&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;O resultado será esse:&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-iP3BX1bdOWk/UPtlNiyIK7I/AAAAAAAACSw/YZNSHQjNn-w/s1600/radius25.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;155&quot; src=&quot;http://2.bp.blogspot.com/-iP3BX1bdOWk/UPtlNiyIK7I/AAAAAAAACSw/YZNSHQjNn-w/s320/radius25.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Já se quisermos apenas arredondar apenas os cantos de cima, fazemos definindo os valores dos quatro cantos na ordem: cima/esquerda, cima/direita, baixo/direita, baixo/esquerda. Ficará assim:&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-wW6iuJEwUCE/UPtl3szpN3I/AAAAAAAACS4/-Fk6D9j7i6w/s1600/radius25cima.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;152&quot; src=&quot;http://2.bp.blogspot.com/-wW6iuJEwUCE/UPtl3szpN3I/AAAAAAAACS4/-Fk6D9j7i6w/s320/radius25cima.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Somente embaixo é a mesma lógica:&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-WXwSqueqvGI/UPtmMgWmj9I/AAAAAAAACTA/Tk6Ai2HrZaA/s1600/radius25baixo.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;152&quot; src=&quot;http://2.bp.blogspot.com/-WXwSqueqvGI/UPtmMgWmj9I/AAAAAAAACTA/Tk6Ai2HrZaA/s320/radius25baixo.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;No site da &lt;a href=&quot;http://www.w3schools.com/cssref/css3_pr_border-radius.asp&quot; target=&quot;_blank&quot;&gt;w3schools&lt;/a&gt; há uma documentação completíssima sobre esta propriedade e para quem precisa de mais informações eu recomendo fortemente a visita.&lt;br /&gt;&lt;br /&gt;Já para quem quiser algo mastigado, o site&amp;nbsp;&lt;a href=&quot;http://border-radius.com/&quot;&gt;http://border-radius.com/&lt;/a&gt;&amp;nbsp;faz todo este trabalho automaticamente e na hora.&lt;br /&gt;&lt;br /&gt;Caso desejarem, &lt;a href=&quot;http://goo.gl/2Kw43&quot; target=&quot;_blank&quot;&gt;aqui está um arquivo .html&lt;/a&gt; com os códigos acima para visualizarem melhor.&lt;br /&gt;&lt;br /&gt;Abraço e até a próxima.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhomps.blogspot.com/feeds/474340509990386338/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://jhomps.blogspot.com/2013/01/fazer-div-com-borda-arredondada-sem.html#comment-form' title='0 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/474340509990386338'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/474340509990386338'/><link rel='alternate' type='text/html' href='http://jhomps.blogspot.com/2013/01/fazer-div-com-borda-arredondada-sem.html' title='Fazer div com borda arredondada sem imagens HTML/CSS'/><author><name>João Paulo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-iP3BX1bdOWk/UPtlNiyIK7I/AAAAAAAACSw/YZNSHQjNn-w/s72-c/radius25.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9021371897721484347.post-1718154368785042039</id><published>2012-12-30T02:51:00.000-02:00</published><updated>2013-05-19T12:07:27.442-03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C# Windows Forms"/><category scheme="http://www.blogger.com/atom/ns#" term="Exportar"/><title type='text'>Exportar DataGridView para txt em C#</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;Olá!&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Hoje trago um código simples para exportação de conteúdo do &lt;b&gt;DataGridView&lt;/b&gt; para um arquivo .txt e que também é possível adicionar um caractere delimitador entre as células, como vírgula, tab, ponto e vírgula, etc.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Em sua tela principal adicionei linhas no evento Load apenas para exemplificar o uso do método. Ficou assim:&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-aJVkNGNObUA/UZjnwEmtWhI/AAAAAAAACz4/J3nDPqJZuuQ/s1600/exportar.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://1.bp.blogspot.com/-aJVkNGNObUA/UZjnwEmtWhI/AAAAAAAACz4/J3nDPqJZuuQ/s1600/exportar.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Ao clicar no botão &quot;Exportar&quot; o método é chamado passando como parâmetro o &lt;b&gt;DataGridView&lt;/b&gt;. Um &lt;b&gt;SaveFileDialog&lt;/b&gt; é chamado para pegar o caminho e nome do arquivo que o usuário deseja salvar. Ele está configurado para filtrar apenas arquivos txt e abrirá sempre no Desktop.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/-0wRcytV2eo8/UZjoZiEWN0I/AAAAAAAAC0A/ECGmLgYz-1w/s1600/salvar.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://4.bp.blogspot.com/-0wRcytV2eo8/UZjoZiEWN0I/AAAAAAAAC0A/ECGmLgYz-1w/s1600/salvar.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Se o usuário digitou o nome e clicou em salvar então é criado um StreamWriter que adicionará linha por linha do DataGridView no arquivo txt, já adicionando os caracteres delimitadores.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Por fim, é mostrado um MessageBox de confirmação.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-Z9NvGtha_cg/UZjpdJdiZgI/AAAAAAAAC0Q/zUGUlVJZ_Hk/s1600/mbox.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-Z9NvGtha_cg/UZjpdJdiZgI/AAAAAAAAC0Q/zUGUlVJZ_Hk/s1600/mbox.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Por hoje é só. Espero que tenha ajudado.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Abraço&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;O .exe compilado para o .NET Framework 4.0 do programa pode ser baixado no seguinte link:&amp;nbsp;&lt;a href=&quot;http://goo.gl/eWyNr&quot;&gt;http://goo.gl/eWyNr&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;O projeto e código fonte completo do programa em C# criado com o VisualStudio2010:&amp;nbsp;&lt;a href=&quot;http://goo.gl/G28ak&quot;&gt;http://goo.gl/G28ak&lt;/a&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhomps.blogspot.com/feeds/1718154368785042039/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://jhomps.blogspot.com/2012/12/exportar-datagridview-para-txt-em-c.html#comment-form' title='2 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/1718154368785042039'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/1718154368785042039'/><link rel='alternate' type='text/html' href='http://jhomps.blogspot.com/2012/12/exportar-datagridview-para-txt-em-c.html' title='Exportar DataGridView para txt em C#'/><author><name>João Paulo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-aJVkNGNObUA/UZjnwEmtWhI/AAAAAAAACz4/J3nDPqJZuuQ/s72-c/exportar.jpg" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9021371897721484347.post-3979911804628896260</id><published>2012-12-22T18:05:00.000-02:00</published><updated>2012-12-22T18:05:26.822-02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C# Windows Forms"/><title type='text'>Fórmula de Bhaskara em C#</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;Caro leitor, bem vindo ao meu blog.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Hoje disponibilizarei um pequeno programa para calcular a famosa &lt;a href=&quot;http://pt.wikipedia.org/wiki/F%C3%B3rmula_de_Bhaskara&quot; target=&quot;_blank&quot;&gt;Fórmula de Bhaskara&lt;/a&gt; que aprendemos no colégio.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;A fórmula é a seguinte:&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://upload.wikimedia.org/math/8/e/4/8e4fef5352eb498b3534af481c8c4fd4.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://upload.wikimedia.org/math/8/e/4/8e4fef5352eb498b3534af481c8c4fd4.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Para usá-lo basta preencher os valores de &#39;a&#39;, &#39;b&#39; e &#39;c&#39; e clicar em &#39;Calcular&#39; que ele&amp;nbsp;retornará, quando possível, as duas raízes da equação. Ele ficou deste jeito:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/-IEuvm596E1Q/UNYRZhjrH1I/AAAAAAAACFc/6uVJxiH0MZs/s1600/bhaskara.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://4.bp.blogspot.com/-IEuvm596E1Q/UNYRZhjrH1I/AAAAAAAACFc/6uVJxiH0MZs/s1600/bhaskara.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Para ver o programa funcionando basta fazer o download do .exe compilado para o .NET Framework 4.0 no seguinte link: &lt;a href=&quot;http://goo.gl/ktyi7&quot;&gt;http://goo.gl/ktyi7&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Se quiserem o projeto e código fonte completo do programa em C# criado com o VisualStudio2010 baixem através deste link:&amp;nbsp;&lt;a href=&quot;http://goo.gl/qtPwZ&quot;&gt;http://goo.gl/qtPwZ&lt;/a&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhomps.blogspot.com/feeds/3979911804628896260/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://jhomps.blogspot.com/2012/12/formula-de-bhaskara-em-c.html#comment-form' title='1 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/3979911804628896260'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/3979911804628896260'/><link rel='alternate' type='text/html' href='http://jhomps.blogspot.com/2012/12/formula-de-bhaskara-em-c.html' title='Fórmula de Bhaskara em C#'/><author><name>João Paulo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-IEuvm596E1Q/UNYRZhjrH1I/AAAAAAAACFc/6uVJxiH0MZs/s72-c/bhaskara.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9021371897721484347.post-6641466305299702640</id><published>2012-11-19T21:53:00.000-02:00</published><updated>2013-03-13T21:59:57.347-03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="HTML/CSS"/><category scheme="http://www.blogger.com/atom/ns#" term="icon"/><title type='text'>Como colocar ícone em sites ao lado da barra de endereços</title><content type='html'>&lt;br /&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;Olá leitor,&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;Nas poucas linhas abaixo pretendo explicar como adicionar um ícone, ou favicon (&lt;b&gt;fav&lt;/b&gt;orite &lt;b&gt;ico&lt;/b&gt;n), ao lado do endereço de seu site.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;Primeiramente você precisa da imagem, de preferência quadrada, com tamanho de 16x16 pixels e com extensão gif ou png.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;Caso não tenha uma pronta, no site &lt;a href=&quot;http://www.iconarchive.com/&quot;&gt;http://www.iconarchive.com&lt;/a&gt; existem milhares disponibilizadas.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;Já com o link direto de sua imagem, substitua as informações das linhas abaixo e adicione o código dentro da tag &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; das páginas em que pretende que o ícone apareça.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;code&gt;&amp;lt;link rel=&quot;icon&quot; href=&quot;&lt;b&gt;LINK_DA_IMAGEM&lt;/b&gt;&quot; type=&quot;&lt;b&gt;image/gif || image/png&lt;/b&gt;&quot;&amp;gt;&lt;/code&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;No atributo href basta adicionar o &lt;b&gt;link direto da sua imagem&lt;/b&gt;, enquanto no atributo type você diz se ela é um &lt;b&gt;gif ou um png&lt;/b&gt;.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;Com estes simples passos, seu site mostrará seu favicon para todos os browsers modernos.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-UMHmGAZ95ns/UUEgq14FIvI/AAAAAAAACp8/MnbDzM3-j-A/s1600/favicon.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://3.bp.blogspot.com/-UMHmGAZ95ns/UUEgq14FIvI/AAAAAAAACp8/MnbDzM3-j-A/s1600/favicon.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;text-align: justify;&quot;&gt;Até a próxima.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://jhomps.blogspot.com/feeds/6641466305299702640/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://jhomps.blogspot.com/2012/11/colocar-favicon-em-seu-site.html#comment-form' title='0 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/6641466305299702640'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/6641466305299702640'/><link rel='alternate' type='text/html' href='http://jhomps.blogspot.com/2012/11/colocar-favicon-em-seu-site.html' title='Como colocar ícone em sites ao lado da barra de endereços'/><author><name>João Paulo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-UMHmGAZ95ns/UUEgq14FIvI/AAAAAAAACp8/MnbDzM3-j-A/s72-c/favicon.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9021371897721484347.post-7467163007974413087</id><published>2012-09-10T12:48:00.001-03:00</published><updated>2013-05-19T03:00:57.951-03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C# Windows Forms"/><category scheme="http://www.blogger.com/atom/ns#" term="Cronometro"/><category scheme="http://www.blogger.com/atom/ns#" term="StopWatch"/><title type='text'>Cronômetro fácil de fazer em C#</title><content type='html'>Olá pessoal,&lt;br /&gt;&lt;br /&gt;Desta vez trago um código simples, mas que dependendo da aplicação pode ser bem útil.&lt;br /&gt;Descobri há pouco a classe &lt;b&gt;StopWatch&lt;/b&gt; do namespace &lt;b&gt;System.Diagnostics &lt;/b&gt;e o quão fácil é de usá-la.&lt;br /&gt;&lt;br /&gt;Ela tem os métodos clássicos de um cronômetro como parar, reiniciar e zerar. Não é necessário fazer contas de milissegundos, minutos, etc.&lt;br /&gt;&lt;br /&gt;Fiz um programinha para ilustrar o uso de alguns dos métodos dela. Ele ficou assim:&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-H2K_tIeg6r0/UE4KHO1GrNI/AAAAAAAABQA/WuK5wAEiebQ/s1600/cronometro.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://1.bp.blogspot.com/-H2K_tIeg6r0/UE4KHO1GrNI/AAAAAAAABQA/WuK5wAEiebQ/s1600/cronometro.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Vocês podem ver todo o funcionamento do programa em C# baixando o executável no link &lt;a href=&quot;http://goo.gl/L3335&quot;&gt;http://goo.gl/L3335&lt;/a&gt;, ou então fazendo o download do código fonte do cronômetro completo no link&amp;nbsp;&lt;a href=&quot;http://goo.gl/AXBrT&quot;&gt;http://goo.gl/AXBrT&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Abraço e até a próxima.</content><link rel='replies' type='application/atom+xml' href='http://jhomps.blogspot.com/feeds/7467163007974413087/comments/default' title='Postar comentários'/><link rel='replies' type='text/html' href='http://jhomps.blogspot.com/2012/09/cronometro-facil-de-fazer-em-c.html#comment-form' title='1 Comentários'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/7467163007974413087'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9021371897721484347/posts/default/7467163007974413087'/><link rel='alternate' type='text/html' href='http://jhomps.blogspot.com/2012/09/cronometro-facil-de-fazer-em-c.html' title='Cronômetro fácil de fazer em C#'/><author><name>João Paulo</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-H2K_tIeg6r0/UE4KHO1GrNI/AAAAAAAABQA/WuK5wAEiebQ/s72-c/cronometro.png" height="72" width="72"/><thr:total>1</thr:total></entry></feed>