http://vbex.ru/api.php?action=feedcontributions&user=Admin&feedformat=atom
VB Эксперт - Вклад участника [ru]
2024-03-29T07:02:47Z
Вклад участника
MediaWiki 1.30.0
http://vbex.ru/index.php?title=%D0%97%D0%B0%D0%B3%D0%BB%D0%B0%D0%B2%D0%BD%D0%B0%D1%8F_%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0&diff=3957
Заглавная страница
2010-06-01T16:07:25Z
<p>Admin: Защищена страница «Заглавная страница» ([edit=sysop] (бессрочно) [move=sysop] (бессрочно))</p>
<hr />
<div><div style="text-align: center; width: 90%; padding: 0.5em; margin: auto;"><br />
На данный момент уже '''{{NUMBEROFPAGES}}''' {{plural: {{NUMBEROFPAGES}} |страница|страниц}} и '''{{NUMBEROFFILES}}''' {{plural: {{NUMBEROFFILES}} |файл|файлов}}.<br />
</div><br />
<br />
== VB.Net ==<br />
{| width="100%"<br />
|- valign="top" <br />
| style="width: 25%;"|<br />
* [[VB.Net/2D | 2D]]<br />
* [[VB.Net/Application | Application]]<br />
* [[VB.Net/Class | Class]]<br />
* [[VB.Net/Data Structure | Data Structure]]<br />
* [[VB.Net/Database ADO.net | Database ADO.net]]<br />
| style="width: 25%;"|<br />
* [[VB.Net/Development | Development]]<br />
* [[VB.Net/Event | Event]]<br />
* [[VB.Net/File Directory | File Directory]]<br />
* [[VB.Net/GUI | GUI]]<br />
* [[VB.Net/Generics | Generics]]<br />
| style="width: 25%;"|<br />
* [[VB.Net/LINQ | LINQ]]<br />
* [[VB.Net/Language Basics | Language Basics]]<br />
* [[VB.Net/Network Remote | Network Remote]]<br />
* [[VB.Net/Thread | Thread]]<br />
* [[VB.Net/Windows System | Windows System]]<br />
| style="width: 25%;"|<br />
* [[VB.Net/XML | XML]]<br />
* [[VB.Net/XML LINQ | XML LINQ]]<br />
|}<br />
<br />
== VB.Net API == <br />
{| width="100%"<br />
|- valign="top" <br />
| style="width: 25%;"|<br />
* [[VB.Net by API/Microsoft.VisualBasic | Microsoft.VisualBasic]]<br />
* [[VB.Net by API/Microsoft.Win32 | Microsoft.Win32]]<br />
* [[VB.Net by API/System | System]]<br />
* [[VB.Net by API/System.Collections | System.Collections]]<br />
* [[VB.Net by API/System.Collections.Generic | System.Collections.Generic]]<br />
* [[VB.Net by API/System.Collections.Specialized | System.Collections.Specialized]]<br />
* [[VB.Net by API/System.ComponentModel | System.ComponentModel]]<br />
* [[VB.Net by API/System.Configuration.ConfigurationSettings | System.Configuration.ConfigurationSettings]]<br />
* [[VB.Net by API/System.Data | System.Data]]<br />
* [[VB.Net by API/System.Data.Odbc | System.Data.Odbc]]<br />
* [[VB.Net by API/System.Data.OleDb | System.Data.OleDb]]<br />
* [[VB.Net by API/System.Data.OracleClient | System.Data.OracleClient]]<br />
| style="width: 25%;"|<br />
* [[VB.Net by API/System.Data.SqlClient | System.Data.SqlClient]]<br />
* [[VB.Net by API/System.Diagnostics | System.Diagnostics]]<br />
* [[VB.Net by API/System.Drawing | System.Drawing]]<br />
* [[VB.Net by API/System.Drawing.Drawing2D | System.Drawing.Drawing2D]]<br />
* [[VB.Net by API/System.Drawing.Imaging | System.Drawing.Imaging]]<br />
* [[VB.Net by API/System.Drawing.Printing | System.Drawing.Printing]]<br />
* [[VB.Net by API/System.Drawing.Text | System.Drawing.Text]]<br />
* [[VB.Net by API/System.Globalization | System.Globalization]]<br />
* [[VB.Net by API/System.IO | System.IO]]<br />
* [[VB.Net by API/System.IO.IsolatedStorage | System.IO.IsolatedStorage]]<br />
* [[VB.Net by API/System.IO.Ports | System.IO.Ports]]<br />
* [[VB.Net by API/System.Media | System.Media]]<br />
| style="width: 25%;"|<br />
* [[VB.Net by API/System.Messaging | System.Messaging]]<br />
* [[VB.Net by API/System.Net | System.Net]]<br />
* [[VB.Net by API/System.Net.Sockets | System.Net.Sockets]]<br />
* [[VB.Net by API/System.Reflection | System.Reflection]]<br />
* [[VB.Net by API/System.Runtime.InteropServices | System.Runtime.InteropServices]]<br />
* [[VB.Net by API/System.Runtime.Remoting.Channels | System.Runtime.Remoting.Channels]]<br />
* [[VB.Net by API/System.Runtime.Serialization | System.Runtime.Serialization]]<br />
* [[VB.Net by API/System.Runtime.Serialization.Formatters.Binary | System.Runtime.Serialization.Formatters.Binary]]<br />
* [[VB.Net by API/System.Runtime.Serialization.Formatters.Soap | System.Runtime.Serialization.Formatters.Soap]]<br />
* [[VB.Net by API/System.Security.Cryptography | System.Security.Cryptography]]<br />
* [[VB.Net by API/System.Security.Cryptography.X509Certificates | System.Security.Cryptography.X509Certificates]]<br />
* [[VB.Net by API/System.Security.Permissions | System.Security.Permissions]]<br />
| style="width: 25%;"|<br />
* [[VB.Net by API/System.Security.Principal | System.Security.Principal]]<br />
* [[VB.Net by API/System.ServiceProcess | System.ServiceProcess]]<br />
* [[VB.Net by API/System.Text | System.Text]]<br />
* [[VB.Net by API/System.Text.RegularExpressions | System.Text.RegularExpressions]]<br />
* [[VB.Net by API/System.Threading | System.Threading]]<br />
* [[VB.Net by API/System.Web | System.Web]]<br />
* [[VB.Net by API/System.Web.Mail | System.Web.Mail]]<br />
* [[VB.Net by API/System.Windows.Forms | System.Windows.Forms]]<br />
* [[VB.Net by API/System.Xml | System.Xml]]<br />
* [[VB.Net by API/System.Xml.Schema | System.Xml.Schema]]<br />
* [[VB.Net by API/System.Xml.Serialization | System.Xml.Serialization]]<br />
* [[VB.Net by API/System.Xml.Xsl | System.Xml.Xsl]]<br />
|}<br />
<br />
== VB.Net Tutorial ==<br />
{| width="100%"<br />
|- valign="top" <br />
| style="width: 25%;"|<br />
* [[VB.Net Tutorial/2D Graphics | 2D Graphics]]<br />
* [[VB.Net Tutorial/Attributes | Attributes]]<br />
* [[VB.Net Tutorial/Class Module | Class Module]]<br />
* [[VB.Net Tutorial/Collections | Collections]]<br />
* [[VB.Net Tutorial/Data Type | Data Type]]<br />
* [[VB.Net Tutorial/Database ADO.net | Database ADO.net]]<br />
* [[VB.Net Tutorial/Date Time | Date Time]]<br />
| style="width: 25%;"|<br />
* [[VB.Net Tutorial/Design Patterns | Design Patterns]]<br />
* [[VB.Net Tutorial/Development | Development]]<br />
* [[VB.Net Tutorial/Event | Event]]<br />
* [[VB.Net Tutorial/GUI | GUI]]<br />
* [[VB.Net Tutorial/GUI Applications | GUI Applications]]<br />
* [[VB.Net Tutorial/Generics | Generics]]<br />
* [[VB.Net Tutorial/I18N Internationlization | I18N Internationlization]]<br />
| style="width: 25%;"|<br />
* [[VB.Net Tutorial/Language Basics | Language Basics]]<br />
* [[VB.Net Tutorial/Operator | Operator]]<br />
* [[VB.Net Tutorial/Reflection | Reflection]]<br />
* [[VB.Net Tutorial/Regular Expressions | Regular Expressions]]<br />
* [[VB.Net Tutorial/Security | Security]]<br />
* [[VB.Net Tutorial/Socket Network | Socket Network]]<br />
* [[VB.Net Tutorial/Statements | Statements]]<br />
| style="width: 25%;"|<br />
* [[VB.Net Tutorial/Stream File | Stream File]]<br />
* [[VB.Net Tutorial/Thread | Thread]]<br />
* [[VB.Net Tutorial/Windows | Windows]]<br />
* [[VB.Net Tutorial/XML | XML]]<br />
|}<br />
== VBA/Excel/Access/Word ==<br />
{| width="100%"<br />
|- valign="top" <br />
| style="width: 25%;"|<br />
* [[VBA/Excel/Access/Word/Access | Access]]<br />
* [[VBA/Excel/Access/Word/Application | Application]]<br />
* [[VBA/Excel/Access/Word/Data Type | Data Type]]<br />
* [[VBA/Excel/Access/Word/Data Type Functions | Data Type Functions]]<br />
* [[VBA/Excel/Access/Word/Date Functions | Date Functions]]<br />
| style="width: 25%;"|<br />
* [[VBA/Excel/Access/Word/Excel | Excel]]<br />
* [[VBA/Excel/Access/Word/File Path | File Path]]<br />
* [[VBA/Excel/Access/Word/Forms | Forms]]<br />
* [[VBA/Excel/Access/Word/Language Basics | Language Basics]]<br />
* [[VBA/Excel/Access/Word/Math Functions | Math Functions]]<br />
| style="width: 25%;"|<br />
* [[VBA/Excel/Access/Word/Outlook | Outlook]]<br />
* [[VBA/Excel/Access/Word/PowerPoint | PowerPoint]]<br />
* [[VBA/Excel/Access/Word/String Functions | String Functions]]<br />
* [[VBA/Excel/Access/Word/Windows API | Windows API]]<br />
* [[VBA/Excel/Access/Word/Word | Word]]<br />
| style="width: 25%;"|<br />
* [[VBA/Excel/Access/Word/XML | XML]]<br />
|}</div>
Admin
http://vbex.ru/index.php?title=VB_%D0%AD%D0%BA%D1%81%D0%BF%D0%B5%D1%80%D1%82:%D0%9E%D1%82%D0%BA%D0%B0%D0%B7_%D0%BE%D1%82_%D0%BE%D1%82%D0%B2%D0%B5%D1%82%D1%81%D1%82%D0%B2%D0%B5%D0%BD%D0%BD%D0%BE%D1%81%D1%82%D0%B8&diff=3956
VB Эксперт:Отказ от ответственности
2010-06-01T16:07:03Z
<p>Admin: Защищена страница «VB Эксперт:Отказ от ответственности» ([edit=sysop] (бессрочно) [move=sysop] (бессрочно))</p>
<hr />
<div>VbEx.RU, Интернет-энциклопедия с открытым содержимым, является добровольным сообществом личностей и групп, создающих общее хранилище человеческих знаний. Её строение позволяет любому, кто имеет доступ к Интернету и браузер, изменять её содержание. Поэтому, пожалуйста, примите во внимание, что приведённые здесь сведения могут быть не проверенными профессионалами, обладающими знаниями в соответствующих областях, необходимыми для предоставления вам полной, точной или заслуживающей доверия информации о любом понятии в VbEx.RU.<br />
<br />
Нельзя сказать, что в VbEx.RU не так уж много полезной и точной информации, однако вы должны сознавать, что VbEx.RU не может никаким способом гарантировать правильность приведённых в ней данных. Во время прочтения они могли быть только что изменены, испорчены, либо написаны тем, чьё мнение отличается от общепринятого в области знаний, интересующей вас.<br />
<br />
Мы ищем пути проверки и отбора вызывающих наибольшее доверие версий статей, но мы не можем ничего гарантировать. Наше наибольшее достижение — это избранные участниками статьи, но даже они могли быть испорчены или искажены кем-то за несколько мгновений до прочтения вами.<br />
<br />
Никто из авторов, участников, спонсоров, администраторов, операторов и лиц, как-либо ещё связанных с VbEx.RU, не несёт ответственность за появление неточной или ложной информации, а также за использование вами данных, содержащихся на этих веб-страницах либо найденных по ссылкам с них.<br />
Пожалуйста, примите во внимание, что вся информация, находящаяся здесь, предоставлена свободно, как акт доброй воли, без заключения каких-либо договорённостей или договоров между вами и владельцами или пользователями данного сайта, владельцами серверов, на которых он размещён, авторами VbEx.RU, администраторами проекта, операторами либо кем-то ещё, любым образом связанными с этим или родственными ему проектами, которые [договора] могут стать предметом прямых претензий. Вам предоставляется ограниченное право копировать содержимое этого сайта — данное право не предусматривает и не подразумевает никакой договорной или иной ответственности за любую часть VbEx.RU или её агентов, участников, организаторов или других пользователей.<br />
<br />
Любые торговые марки, знаки и названия товаров, служб и организаций, права на дизайн, авторские и смежные права, которые упоминаются, используются или цитируются в статьях, принадлежат их законным владельцам. Их использование здесь не даёт вам право на любое другое использование, кроме предусмотренного авторами статей VbEx.RU в соответствии со схемой лицензирования GFDL. Если не указано иное, VbEx.RU никак не связан с правообладателями, и поэтому VbEx.RU не может распоряжаться правами на использование материалов, защищённых авторским правом. Вы несёте ответственность за использование этих и подобных материалов.<br />
<br />
Обратите внимание, что чтение, распространение или изменение информации, размещённой в VbEx.RU, может являться нарушением законов той страны, в которой вы просматриваете этот сайт. VbEx.RU не призывает к нарушению никаких законов. Законы вашей страны могут трактовать защиту свободы слова не так широко, как законы России — в этом случае VbEx.RU не несёт ответственности за любые потенциальные нарушения этих законов вами при создании ссылок на этот сайт или другом использовании любой содержащейся здесь информации.<br />
<br />
Несмотря на то, что пользователи могут исправлять ошибки или убирать ошибочные суждения, они не обязаны этого делать. Поэтому вся информация предоставляется без гарантии полезности для любой цели либо пригодности к какому-либо использованию.<br />
<br />
VbEx.RU не может нести ответственность за любой нанесённый ущерб, так как является добровольным сообществом, свободно организованным для создания открытых образовательных, культурных и информационных ресурсов. Информация предоставляется как акт доброй воли и не существует соглашения или акта о намерениях между вами и VbEx.RU относительно использования или изменения информации, не предусмотренного GNU Free Documentation License. Также никто в VbEx.RU не несёт ответственности за изменение, редактирование или удаление любой информации, добавленной вами в VbEx.RU или другие связанные с ней проекты.<br />
<br />
Спасибо, что потратили своё время на чтение этой страницы. Желаем вам получить только приятные впечатления от пользования VbEx.RU.</div>
Admin
http://vbex.ru/index.php?title=VB_%D0%AD%D0%BA%D1%81%D0%BF%D0%B5%D1%80%D1%82:%D0%9E%D1%82%D0%BA%D0%B0%D0%B7_%D0%BE%D1%82_%D0%BE%D1%82%D0%B2%D0%B5%D1%82%D1%81%D1%82%D0%B2%D0%B5%D0%BD%D0%BD%D0%BE%D1%81%D1%82%D0%B8&diff=3955
VB Эксперт:Отказ от ответственности
2010-06-01T16:06:55Z
<p>Admin: Новая страница: «VbEx.RU, Интернет-энциклопедия с открытым содержимым, является добровольным сообществом лич…»</p>
<hr />
<div>VbEx.RU, Интернет-энциклопедия с открытым содержимым, является добровольным сообществом личностей и групп, создающих общее хранилище человеческих знаний. Её строение позволяет любому, кто имеет доступ к Интернету и браузер, изменять её содержание. Поэтому, пожалуйста, примите во внимание, что приведённые здесь сведения могут быть не проверенными профессионалами, обладающими знаниями в соответствующих областях, необходимыми для предоставления вам полной, точной или заслуживающей доверия информации о любом понятии в VbEx.RU.<br />
<br />
Нельзя сказать, что в VbEx.RU не так уж много полезной и точной информации, однако вы должны сознавать, что VbEx.RU не может никаким способом гарантировать правильность приведённых в ней данных. Во время прочтения они могли быть только что изменены, испорчены, либо написаны тем, чьё мнение отличается от общепринятого в области знаний, интересующей вас.<br />
<br />
Мы ищем пути проверки и отбора вызывающих наибольшее доверие версий статей, но мы не можем ничего гарантировать. Наше наибольшее достижение — это избранные участниками статьи, но даже они могли быть испорчены или искажены кем-то за несколько мгновений до прочтения вами.<br />
<br />
Никто из авторов, участников, спонсоров, администраторов, операторов и лиц, как-либо ещё связанных с VbEx.RU, не несёт ответственность за появление неточной или ложной информации, а также за использование вами данных, содержащихся на этих веб-страницах либо найденных по ссылкам с них.<br />
Пожалуйста, примите во внимание, что вся информация, находящаяся здесь, предоставлена свободно, как акт доброй воли, без заключения каких-либо договорённостей или договоров между вами и владельцами или пользователями данного сайта, владельцами серверов, на которых он размещён, авторами VbEx.RU, администраторами проекта, операторами либо кем-то ещё, любым образом связанными с этим или родственными ему проектами, которые [договора] могут стать предметом прямых претензий. Вам предоставляется ограниченное право копировать содержимое этого сайта — данное право не предусматривает и не подразумевает никакой договорной или иной ответственности за любую часть VbEx.RU или её агентов, участников, организаторов или других пользователей.<br />
<br />
Любые торговые марки, знаки и названия товаров, служб и организаций, права на дизайн, авторские и смежные права, которые упоминаются, используются или цитируются в статьях, принадлежат их законным владельцам. Их использование здесь не даёт вам право на любое другое использование, кроме предусмотренного авторами статей VbEx.RU в соответствии со схемой лицензирования GFDL. Если не указано иное, VbEx.RU никак не связан с правообладателями, и поэтому VbEx.RU не может распоряжаться правами на использование материалов, защищённых авторским правом. Вы несёте ответственность за использование этих и подобных материалов.<br />
<br />
Обратите внимание, что чтение, распространение или изменение информации, размещённой в VbEx.RU, может являться нарушением законов той страны, в которой вы просматриваете этот сайт. VbEx.RU не призывает к нарушению никаких законов. Законы вашей страны могут трактовать защиту свободы слова не так широко, как законы России — в этом случае VbEx.RU не несёт ответственности за любые потенциальные нарушения этих законов вами при создании ссылок на этот сайт или другом использовании любой содержащейся здесь информации.<br />
<br />
Несмотря на то, что пользователи могут исправлять ошибки или убирать ошибочные суждения, они не обязаны этого делать. Поэтому вся информация предоставляется без гарантии полезности для любой цели либо пригодности к какому-либо использованию.<br />
<br />
VbEx.RU не может нести ответственность за любой нанесённый ущерб, так как является добровольным сообществом, свободно организованным для создания открытых образовательных, культурных и информационных ресурсов. Информация предоставляется как акт доброй воли и не существует соглашения или акта о намерениях между вами и VbEx.RU относительно использования или изменения информации, не предусмотренного GNU Free Documentation License. Также никто в VbEx.RU не несёт ответственности за изменение, редактирование или удаление любой информации, добавленной вами в VbEx.RU или другие связанные с ней проекты.<br />
<br />
Спасибо, что потратили своё время на чтение этой страницы. Желаем вам получить только приятные впечатления от пользования VbEx.RU.</div>
Admin
http://vbex.ru/index.php?title=MediaWiki:Sidebar&diff=3952
MediaWiki:Sidebar
2010-05-26T13:01:42Z
<p>Admin: Новая страница: «* Разделы ** VB.Net | VB.Net ** VB.Net by API | VB.Net API ** VB.Net Tutorial | VB.Net Учебник ** VBA/Excel/Access/Word/Access | VBA/Excel/Access/Word …»</p>
<hr />
<div>* Разделы<br />
** VB.Net | VB.Net<br />
** VB.Net by API | VB.Net API<br />
** VB.Net Tutorial | VB.Net Учебник<br />
** VBA/Excel/Access/Word/Access | VBA/Excel/Access/Word<br />
<br />
* navigation<br />
** mainpage|mainpage-description<br />
** portal-url|portal<br />
** currentevents-url|currentevents<br />
** recentchanges-url|recentchanges<br />
** randompage-url|randompage<br />
** helppage|help<br />
* SEARCH<br />
* TOOLBOX<br />
* LANGUAGES</div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/Regular_Expressions/Post_Code&diff=3947
VB.Net Tutorial/Regular Expressions/Post Code
2010-05-26T12:57:35Z
<p>Admin: 1 версия</p>
<hr />
<div>==Validate for Canada postal code format==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Text.RegularExpressions<br />
Public Class Tester<br />
Public Shared Sub Main<br />
Dim sPostalCode As String = "A1A 1A1"<br />
Dim sPattern As String<br />
Dim objRegEx As Regex<br />
sPattern = "[ABCEGHJKLMNPRSTVXY]\d[A-Z]\d[A-Z]\d" <br />
<br />
Console.WriteLine(objRegEx.IsMatch(sPostalCode, sPattern))<br />
<br />
<br />
End Sub<br />
End Class</source><br />
<pre class=codeResult>False</pre><br />
<br />
==Validate for US postal code format==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Text.RegularExpressions<br />
Public Class Tester<br />
Public Shared Sub Main<br />
Dim sPostalCode As String = "12345-1111"<br />
Dim sPattern As String<br />
Dim objRegEx As Regex<br />
sPattern = "\d\d\d\d\d-\d\d\d\d"<br />
<br />
Console.WriteLine(objRegEx.IsMatch(sPostalCode, sPattern))<br />
End Sub<br />
End Class</source><br />
<pre class=codeResult>True</pre></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/Regular_Expressions&diff=3949
VB.Net Tutorial/Regular Expressions
2010-05-26T12:57:35Z
<p>Admin: 1 версия</p>
<hr />
<div>* [[VB.Net Tutorial/Regular Expressions/Match Email | Match Email]]<br />
* [[VB.Net Tutorial/Regular Expressions/Match Number | Match Number]]<br />
* [[VB.Net Tutorial/Regular Expressions/MatchCollection | MatchCollection]]<br />
* [[VB.Net Tutorial/Regular Expressions/Post Code | Post Code]]<br />
* [[VB.Net Tutorial/Regular Expressions/Regular Expressions | Regular Expressions]]</div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial&diff=3951
VB.Net Tutorial
2010-05-26T12:57:35Z
<p>Admin: 1 версия</p>
<hr />
<div>* [[VB.Net Tutorial/2D Graphics | 2D Graphics]]<br />
* [[VB.Net Tutorial/Attributes | Attributes]]<br />
* [[VB.Net Tutorial/Class Module | Class Module]]<br />
* [[VB.Net Tutorial/Collections | Collections]]<br />
* [[VB.Net Tutorial/Data Type | Data Type]]<br />
* [[VB.Net Tutorial/Database ADO.net | Database ADO.net]]<br />
* [[VB.Net Tutorial/Date Time | Date Time]]<br />
* [[VB.Net Tutorial/Design Patterns | Design Patterns]]<br />
* [[VB.Net Tutorial/Development | Development]]<br />
* [[VB.Net Tutorial/Event | Event]]<br />
* [[VB.Net Tutorial/GUI | GUI]]<br />
* [[VB.Net Tutorial/GUI Applications | GUI Applications]]<br />
* [[VB.Net Tutorial/Generics | Generics]]<br />
* [[VB.Net Tutorial/I18N Internationlization | I18N Internationlization]]<br />
* [[VB.Net Tutorial/Language Basics | Language Basics]]<br />
* [[VB.Net Tutorial/Operator | Operator]]<br />
* [[VB.Net Tutorial/Reflection | Reflection]]<br />
* [[VB.Net Tutorial/Regular Expressions | Regular Expressions]]<br />
* [[VB.Net Tutorial/Security | Security]]<br />
* [[VB.Net Tutorial/Socket Network | Socket Network]]<br />
* [[VB.Net Tutorial/Statements | Statements]]<br />
* [[VB.Net Tutorial/Stream File | Stream File]]<br />
* [[VB.Net Tutorial/Thread | Thread]]<br />
* [[VB.Net Tutorial/Windows | Windows]]<br />
* [[VB.Net Tutorial/XML | XML]]</div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/Regular_Expressions/Match_Number&diff=3943
VB.Net Tutorial/Regular Expressions/Match Number
2010-05-26T12:57:34Z
<p>Admin: 1 версия</p>
<hr />
<div>==Match and extract numbers==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Text.RegularExpressions<br />
Public Class Tester<br />
Public Shared Sub Main<br />
Dim source As String = _<br />
"This 321.0 string -0.020 contains " & _<br />
"3.0E-17 several 1 2. 34 numbers"<br />
Dim parser As New _<br />
Regex("[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?")<br />
Dim sourceMatches As MatchCollection = parser.Matches(source)<br />
Dim counter As Integer<br />
Console.WriteLine(sourceMatches.Count.ToString() & vbNewLine)<br />
For counter = 0 To sourceMatches.Count - 1<br />
Console.WriteLine(sourceMatches(counter).Value.ToString())<br />
Console.WriteLine(CDbl(sourceMatches(counter).Value).ToString())<br />
Next counter<br />
<br />
End Sub<br />
<br />
End Class</source><br />
<pre class=codeResult>6<br />
321.0<br />
321<br />
-0.020<br />
-0.02<br />
3.0E-17<br />
3E-17<br />
1<br />
1<br />
2<br />
2<br />
34<br />
34</pre></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/Regular_Expressions/Match_Email&diff=3945
VB.Net Tutorial/Regular Expressions/Match Email
2010-05-26T12:57:34Z
<p>Admin: 1 версия</p>
<hr />
<div>==Match Email==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Text.RegularExpressions<br />
Public Class Tester<br />
Public Shared Sub Main<br />
Dim testString As String<br />
Dim emailPattern As String = _<br />
"^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@" & _<br />
"([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$"<br />
testString = "a@nowhere.ru"<br />
Console.WriteLine(testString & Space(3) & _<br />
Regex.IsMatch(testString, emailPattern))<br />
testString = "a@doe@mybad.ru"<br />
Console.WriteLine(testString & Space(3) & _<br />
Regex.IsMatch(testString, emailPattern))<br />
End Sub<br />
<br />
End Class</source><br />
<pre class=codeResult>a@nowhere.ru True<br />
a@doe@mybad.ru False</pre></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/Regular_Expressions/Regular_Expressions&diff=3941
VB.Net Tutorial/Regular Expressions/Regular Expressions
2010-05-26T12:57:34Z
<p>Admin: 1 версия</p>
<hr />
<div>==Count chars: Regex.Matches(quote, .)==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Text.RegularExpressions<br />
Public Class Tester<br />
Public Shared Sub Main<br />
Dim quote As String = _<br />
"The important thing" & vbNewLine & _<br />
"is not to stop questioning." & vbNewLine & _<br />
"--Albert Einstein" & vbNewLine<br />
Dim numChars As Integer = Regex.Matches(quote, ".").Count<br />
Console.WriteLine(numChars)<br />
End Sub<br />
<br />
End Class</source><br />
<pre class=codeResult>66</pre><br />
<br />
==Count line: Regex.Matches(quote, ".+\n*")==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Text.RegularExpressions<br />
Public Class Tester<br />
Public Shared Sub Main<br />
Dim quote As String = _<br />
"The important thing" & vbNewLine & _<br />
"is not to stop questioning." & vbNewLine & _<br />
"--Albert Einstein" & vbNewLine<br />
Dim numLines As Integer = Regex.Matches(quote, ".+\n*").Count<br />
Console.WriteLine(numLines)<br />
End Sub<br />
<br />
End Class</source><br />
<pre class=codeResult>3</pre><br />
<br />
==Every word replaced by another word==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Text.RegularExpressions<br />
Public Class Tester<br />
Public Shared Sub Main<br />
<br />
Console.WriteLine(Regex.Replace("This sentence ends in 5 stars *****", "\w+", "word"))<br />
End Sub<br />
End Class</source><br />
<pre class=codeResult>word word word word word word *****</pre><br />
<br />
==Match regular expression to string and print out all matches==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Text.RegularExpressions<br />
Module Tester<br />
Sub Main()<br />
Dim myMatch As Match<br />
Dim expression As Regex = New Regex("J.*\d[0-35-9]-\d\d-\d\d")<br />
Dim string1 As String = "11-11-75" & _<br />
vbCrLf & "is 11-05-68" & vbCrLf & _<br />
"asdf 04-18-73" & vbCrLf & _<br />
"fdsa 12-27-77"<br />
<br />
For Each myMatch In expression.Matches(string1)<br />
Console.WriteLine(myMatch.ToString())<br />
Next<br />
End Sub <br />
End Module</source><br />
<br />
==Regex.CompileToAssembly==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Text.RegularExpressions<br />
Public Class Tester<br />
Public Shared Sub Main<br />
Dim numPattern As String = _<br />
"[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?"<br />
Dim wordPattern As String = "\w+"<br />
Dim whichNamespace As String = "NumbersRegex"<br />
Dim isPublic As Boolean = True<br />
Dim compNumbers As New RegexCompilationInfo(numPattern, _<br />
RegexOptions.rupiled, "RgxNumbers", _<br />
whichNamespace, isPublic)<br />
Dim compWords As New RegexCompilationInfo(wordPattern, _<br />
RegexOptions.rupiled, "RgxWords", whichNamespace, _<br />
isPublic)<br />
Dim compAll() As RegexCompilationInfo = _<br />
{compNumbers, compWords}<br />
Dim whichAssembly As New _<br />
System.Reflection.AssemblyName("RgxNumbersWords")<br />
Regex.rupileToAssembly(compAll, whichAssembly)<br />
End Sub<br />
<br />
End Class</source><br />
<br />
==Regex Matches==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Text.RegularExpressions<br />
Public Class Tester<br />
Public Shared Sub Main<br />
Dim quote As String = "AA BB in"<br />
Dim count1 As Integer<br />
Dim count2 As Integer<br />
Dim count3 As Integer<br />
count1 = Regex.Matches(quote, "(in)+").Count<br />
count2 = Split(quote, "in").Length - 1<br />
Dim content As String = "in"<br />
Dim position As Integer = -content.Length<br />
Do<br />
position = quote.IndexOf(content, position + content.Length)<br />
If (position < 0) Then Exit Do<br />
count3 += 1<br />
Loop<br />
Console.WriteLine(String.Format( _<br />
"{0}{3}{1}{3}{2}", count1, count2, count3, vbNewLine)) <br />
<br />
End Sub<br />
End Class</source><br />
<pre class=codeResult>1<br />
1<br />
1</pre><br />
<br />
==Regex("\w+")==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Text.RegularExpressions<br />
Public Class Tester<br />
Public Shared Sub Main<br />
Dim quote As String = "The important thing is not to " & _<br />
"stop questioning. --Albert Einstein"<br />
Dim parser As New Regex("\w+")<br />
Dim totalMatches As Integer = parser.Matches(quote).Count<br />
Console.WriteLine(quote & vbNewLine & "Number words: " & _<br />
totalMatches.ToString)<br />
End Sub<br />
<br />
End Class</source><br />
<pre class=codeResult>The important thing is not to stop questioning. --Albert Einstein<br />
Number words: 10</pre><br />
<br />
==Replace first 3 digits==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Text.RegularExpressions<br />
Public Class Tester<br />
Public Shared Sub Main<br />
<br />
Console.WriteLine(New Regex("\d").Replace("1, 2, 3, 4, 5, 6, 7, 8", "digit", 3))<br />
End Sub<br />
End Class</source><br />
<pre class=codeResult>digit, digit, digit, 4, 5, 6, 7, 8</pre><br />
<br />
==String split at commas==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Text.RegularExpressions<br />
Public Class Tester<br />
Public Shared Sub Main<br />
<br />
Console.WriteLine(Regex.Split("1, 2, 3, 4, 5, 6, 7, 8", ",\s*"))<br />
End Sub<br />
End Class</source><br />
<pre class=codeResult>System.String[]</pre><br />
<br />
==Using Regex method Replace: Replace one string with another==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Text.RegularExpressions<br />
Public Class Tester<br />
Public Shared Sub Main<br />
<br />
Console.WriteLine(New Regex("stars").Replace("This sentence ends in 5 stars *****", "carets<br />
))<br />
End Sub<br />
End Class</source><br />
<pre class=codeResult>This sentence ends in 5 carets *****</pre><br />
<br />
==Using Regex method Replace: substituted for *==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Text.RegularExpressions<br />
Public Class Tester<br />
Public Shared Sub Main<br />
Console.WriteLine(Regex.Replace("This sentence ends in 5 stars *****", "\*", ""))<br />
End Sub<br />
End Class</source><br />
<pre class=codeResult>This sentence ends in 5 stars ^^^^^</pre><br />
<br />
==Word count==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Text.RegularExpressions<br />
Public Class Tester<br />
Public Shared Sub Main<br />
Dim quote As String = "q d e w "<br />
Do While (quote.IndexOf(Space(2)) >= 0)<br />
quote = quote.Replace(Space(2), Space(1))<br />
Loop<br />
Dim wordCount As Integer = Split(quote, Space(1)).Length<br />
Console.WriteLine(quote & vbNewLine & "Number of words: " & wordCount.ToString) <br />
<br />
End Sub<br />
End Class</source><br />
<pre class=codeResult>q d e w<br />
Number of words: 5</pre><br />
<br />
==Word count: Regex.Matches(quote, "\w+")==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Text.RegularExpressions<br />
Public Class Tester<br />
Public Shared Sub Main<br />
Dim quote As String = _<br />
"The important thing" & vbNewLine & _<br />
"is not to stop questioning." & vbNewLine & _<br />
"--Albert Einstein" & vbNewLine<br />
Dim numWords As Integer = Regex.Matches(quote, "\w+").Count<br />
<br />
Console.WriteLine(numWords)<br />
End Sub<br />
<br />
End Class</source><br />
<pre class=codeResult>10</pre></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI&diff=3937
VB.Net Tutorial/GUI
2010-05-26T12:57:33Z
<p>Admin: 1 версия</p>
<hr />
<div>* [[VB.Net Tutorial/GUI/Anchor Dock | Anchor Dock]]<br />
* [[VB.Net Tutorial/GUI/AnchorStyles | AnchorStyles]]<br />
* [[VB.Net Tutorial/GUI/BackgroundWorker | BackgroundWorker]]<br />
* [[VB.Net Tutorial/GUI/Browser | Browser]]<br />
* [[VB.Net Tutorial/GUI/Button | Button]]<br />
* [[VB.Net Tutorial/GUI/CheckBox | CheckBox]]<br />
* [[VB.Net Tutorial/GUI/CheckBox MenuItem | CheckBox MenuItem]]<br />
* [[VB.Net Tutorial/GUI/CheckedListBox | CheckedListBox]]<br />
* [[VB.Net Tutorial/GUI/ColorDialog | ColorDialog]]<br />
* [[VB.Net Tutorial/GUI/ComboBox | ComboBox]]<br />
* [[VB.Net Tutorial/GUI/Control Event | Control Event]]<br />
* [[VB.Net Tutorial/GUI/Control Properties | Control Properties]]<br />
* [[VB.Net Tutorial/GUI/Control Size Location | Control Size Location]]<br />
* [[VB.Net Tutorial/GUI/Controls | Controls]]<br />
* [[VB.Net Tutorial/GUI/Controls on Form | Controls on Form]]<br />
* [[VB.Net Tutorial/GUI/Cursor | Cursor]]<br />
* [[VB.Net Tutorial/GUI/Custom Control | Custom Control]]<br />
* [[VB.Net Tutorial/GUI/Custom Dialog | Custom Dialog]]<br />
* [[VB.Net Tutorial/GUI/DateTimePicker | DateTimePicker]]<br />
* [[VB.Net Tutorial/GUI/DialogResult | DialogResult]]<br />
* [[VB.Net Tutorial/GUI/DomainUpDowns | DomainUpDowns]]<br />
* [[VB.Net Tutorial/GUI/Drag Drop | Drag Drop]]<br />
* [[VB.Net Tutorial/GUI/ErrorProvider | ErrorProvider]]<br />
* [[VB.Net Tutorial/GUI/FlowLayoutPanel | FlowLayoutPanel]]<br />
* [[VB.Net Tutorial/GUI/FolderBrowserDialog | FolderBrowserDialog]]<br />
* [[VB.Net Tutorial/GUI/Form | Form]]<br />
* [[VB.Net Tutorial/GUI/Form Action Event | Form Action Event]]<br />
* [[VB.Net Tutorial/GUI/Form Paint | Form Paint]]<br />
* [[VB.Net Tutorial/GUI/Form Properties | Form Properties]]<br />
* [[VB.Net Tutorial/GUI/Form owner | Form owner]]<br />
* [[VB.Net Tutorial/GUI/FormBorderStyle | FormBorderStyle]]<br />
* [[VB.Net Tutorial/GUI/GUI Thread | GUI Thread]]<br />
* [[VB.Net Tutorial/GUI/GroupBox | GroupBox]]<br />
* [[VB.Net Tutorial/GUI/HelpProvider | HelpProvider]]<br />
* [[VB.Net Tutorial/GUI/InputBox | InputBox]]<br />
* [[VB.Net Tutorial/GUI/Introduction | Introduction]]<br />
* [[VB.Net Tutorial/GUI/Irregular Window | Irregular Window]]<br />
* [[VB.Net Tutorial/GUI/Label | Label]]<br />
* [[VB.Net Tutorial/GUI/Label Drag Drop | Label Drag Drop]]<br />
* [[VB.Net Tutorial/GUI/LinkLabel | LinkLabel]]<br />
* [[VB.Net Tutorial/GUI/ListBox | ListBox]]<br />
* [[VB.Net Tutorial/GUI/ListBox Drag Drop | ListBox Drag Drop]]<br />
* [[VB.Net Tutorial/GUI/ListView | ListView]]<br />
* [[VB.Net Tutorial/GUI/ListView Sort | ListView Sort]]<br />
* [[VB.Net Tutorial/GUI/MDI | MDI]]<br />
* [[VB.Net Tutorial/GUI/Menu | Menu]]<br />
* [[VB.Net Tutorial/GUI/MenuItem | MenuItem]]<br />
* [[VB.Net Tutorial/GUI/MenuStrip | MenuStrip]]<br />
* [[VB.Net Tutorial/GUI/MessageBox | MessageBox]]<br />
* [[VB.Net Tutorial/GUI/MonthCalendar | MonthCalendar]]<br />
* [[VB.Net Tutorial/GUI/MsgBox | MsgBox]]<br />
* [[VB.Net Tutorial/GUI/NotifyIcon | NotifyIcon]]<br />
* [[VB.Net Tutorial/GUI/NumericUpDown | NumericUpDown]]<br />
* [[VB.Net Tutorial/GUI/OpenFileDialog | OpenFileDialog]]<br />
* [[VB.Net Tutorial/GUI/PageSetupDialog | PageSetupDialog]]<br />
* [[VB.Net Tutorial/GUI/Panel | Panel]]<br />
* [[VB.Net Tutorial/GUI/Password Field | Password Field]]<br />
* [[VB.Net Tutorial/GUI/PictureBox | PictureBox]]<br />
* [[VB.Net Tutorial/GUI/PopupMenu | PopupMenu]]<br />
* [[VB.Net Tutorial/GUI/Print | Print]]<br />
* [[VB.Net Tutorial/GUI/Print Dialog | Print Dialog]]<br />
* [[VB.Net Tutorial/GUI/PrintDocument | PrintDocument]]<br />
* [[VB.Net Tutorial/GUI/PrintPreview Dialog | PrintPreview Dialog]]<br />
* [[VB.Net Tutorial/GUI/Printers | Printers]]<br />
* [[VB.Net Tutorial/GUI/ProgressBar | ProgressBar]]<br />
* [[VB.Net Tutorial/GUI/PropertyGrid | PropertyGrid]]<br />
* [[VB.Net Tutorial/GUI/RadioButton | RadioButton]]<br />
* [[VB.Net Tutorial/GUI/RadioButton MenuItem | RadioButton MenuItem]]<br />
* [[VB.Net Tutorial/GUI/RichTextBox | RichTextBox]]<br />
* [[VB.Net Tutorial/GUI/SaveFileDialog | SaveFileDialog]]<br />
* [[VB.Net Tutorial/GUI/ScrollBar | ScrollBar]]<br />
* [[VB.Net Tutorial/GUI/Splash Screen | Splash Screen]]<br />
* [[VB.Net Tutorial/GUI/SplitContainer | SplitContainer]]<br />
* [[VB.Net Tutorial/GUI/Splitter | Splitter]]<br />
* [[VB.Net Tutorial/GUI/StatusBar | StatusBar]]<br />
* [[VB.Net Tutorial/GUI/StatusStrip | StatusStrip]]<br />
* [[VB.Net Tutorial/GUI/SystemIcons | SystemIcons]]<br />
* [[VB.Net Tutorial/GUI/TabControl | TabControl]]<br />
* [[VB.Net Tutorial/GUI/TableLayoutPanel | TableLayoutPanel]]<br />
* [[VB.Net Tutorial/GUI/Text File Print | Text File Print]]<br />
* [[VB.Net Tutorial/GUI/TextBox | TextBox]]<br />
* [[VB.Net Tutorial/GUI/TextBox Validation | TextBox Validation]]<br />
* [[VB.Net Tutorial/GUI/Timer | Timer]]<br />
* [[VB.Net Tutorial/GUI/ToolBar | ToolBar]]<br />
* [[VB.Net Tutorial/GUI/ToolStrip | ToolStrip]]<br />
* [[VB.Net Tutorial/GUI/Tooltips | Tooltips]]<br />
* [[VB.Net Tutorial/GUI/TrackBar | TrackBar]]<br />
* [[VB.Net Tutorial/GUI/TreeView | TreeView]]<br />
* [[VB.Net Tutorial/GUI/Visual Inheritance | Visual Inheritance]]<br />
* [[VB.Net Tutorial/GUI/Wizard | Wizard]]<br />
<br />
==Font dialog apply action==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Windows.Forms<br />
public class FontDialogApplyAction<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Private Sub btnSetFont_Click(ByVal sender As System.Object, _<br />
ByVal e As System.EventArgs) Handles btnSetFont.Click<br />
Dim old_font As Font = Me.Font<br />
Dim old_color As Color = Me.ForeColor<br />
dlgFont.ShowColor = True " Let the user select font color. <br />
dlgFont.ShowEffects = True " Let the user select Strikeout and Underline.<br />
dlgFont.ShowApply = True " Display the Apply button.<br />
dlgFont.Font = Me.Font " Set the initial font.<br />
If dlgFont.ShowDialog() = DialogResult.OK Then<br />
SetFormFont(dlgFont.Font, dlgFont.Color)<br />
Else<br />
SetFormFont(old_font, old_color)<br />
End If<br />
End Sub<br />
Private Sub dlgFont_Apply(ByVal sender As Object, _<br />
ByVal e As System.EventArgs) Handles dlgFont.Apply<br />
Dim dlg As FontDialog = DirectCast(sender, FontDialog)<br />
SetFormFont(dlg.Font, dlg.Color)<br />
End Sub<br />
Private Sub SetFormFont(ByVal new_font As Font, ByVal new_color As Color)<br />
Me.Font = new_font<br />
Me.ForeColor = new_color<br />
End Sub<br />
End Class<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.btnSetFont = New System.Windows.Forms.Button<br />
Me.Label1 = New System.Windows.Forms.Label<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.dlgFont = New System.Windows.Forms.FontDialog<br />
Me.SuspendLayout()<br />
"<br />
"btnSetFont<br />
"<br />
Me.btnSetFont.Location = New System.Drawing.Point(8, 8)<br />
Me.btnSetFont.Name = "btnSetFont"<br />
Me.btnSetFont.Size = New System.Drawing.Size(96, 32)<br />
Me.btnSetFont.TabIndex = 0<br />
Me.btnSetFont.Text = "Set Font"<br />
"<br />
"Label1<br />
"<br />
Me.Label1.AutoSize = True<br />
Me.Label1.Location = New System.Drawing.Point(8, 48)<br />
Me.Label1.Name = "Label1"<br />
Me.Label1.Size = New System.Drawing.Size(35, 13)<br />
Me.Label1.TabIndex = 1<br />
Me.Label1.Text = "Label1"<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(8, 80)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(160, 20)<br />
Me.TextBox1.TabIndex = 2<br />
Me.TextBox1.Text = "Here"s a TextBox"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None<br />
Me.ClientSize = New System.Drawing.Size(325, 273)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.Controls.Add(Me.Label1)<br />
Me.Controls.Add(Me.btnSetFont)<br />
Me.Name = "Form1"<br />
Me.Text = "UseFontDialogWithShowEffects"<br />
Me.ResumeLayout(False)<br />
Me.PerformLayout()<br />
End Sub<br />
Friend WithEvents btnSetFont As System.Windows.Forms.Button<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
Friend WithEvents dlgFont As System.Windows.Forms.FontDialog<br />
End Class</source><br />
<br />
==Font dialog showing effects==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Windows.Forms<br />
public class FontDialogApplyAction<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Private Sub btnSetFont_Click(ByVal sender As System.Object, _<br />
ByVal e As System.EventArgs) Handles btnSetFont.Click<br />
Dim old_font As Font = Me.Font<br />
Dim old_color As Color = Me.ForeColor<br />
dlgFont.ShowColor = True " Let the user select font color. <br />
dlgFont.ShowEffects = True " Let the user select Strikeout and Underline.<br />
dlgFont.ShowApply = True " Display the Apply button.<br />
dlgFont.Font = Me.Font " Set the initial font.<br />
If dlgFont.ShowDialog() = DialogResult.OK Then<br />
SetFormFont(dlgFont.Font, dlgFont.Color)<br />
Else<br />
SetFormFont(old_font, old_color)<br />
End If<br />
End Sub<br />
Private Sub dlgFont_Apply(ByVal sender As Object, _<br />
ByVal e As System.EventArgs) Handles dlgFont.Apply<br />
Dim dlg As FontDialog = DirectCast(sender, FontDialog)<br />
SetFormFont(dlg.Font, dlg.Color)<br />
End Sub<br />
Private Sub SetFormFont(ByVal new_font As Font, ByVal new_color As Color)<br />
Me.Font = new_font<br />
Me.ForeColor = new_color<br />
End Sub<br />
End Class<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.btnSetFont = New System.Windows.Forms.Button<br />
Me.Label1 = New System.Windows.Forms.Label<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.dlgFont = New System.Windows.Forms.FontDialog<br />
Me.SuspendLayout()<br />
"<br />
"btnSetFont<br />
"<br />
Me.btnSetFont.Location = New System.Drawing.Point(8, 8)<br />
Me.btnSetFont.Name = "btnSetFont"<br />
Me.btnSetFont.Size = New System.Drawing.Size(96, 32)<br />
Me.btnSetFont.TabIndex = 0<br />
Me.btnSetFont.Text = "Set Font"<br />
"<br />
"Label1<br />
"<br />
Me.Label1.AutoSize = True<br />
Me.Label1.Location = New System.Drawing.Point(8, 48)<br />
Me.Label1.Name = "Label1"<br />
Me.Label1.Size = New System.Drawing.Size(35, 13)<br />
Me.Label1.TabIndex = 1<br />
Me.Label1.Text = "Label1"<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(8, 80)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(160, 20)<br />
Me.TextBox1.TabIndex = 2<br />
Me.TextBox1.Text = "Here"s a TextBox"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None<br />
Me.ClientSize = New System.Drawing.Size(325, 273)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.Controls.Add(Me.Label1)<br />
Me.Controls.Add(Me.btnSetFont)<br />
Me.Name = "Form1"<br />
Me.Text = "UseFontDialogWithShowEffects"<br />
Me.ResumeLayout(False)<br />
Me.PerformLayout()<br />
End Sub<br />
Friend WithEvents btnSetFont As System.Windows.Forms.Button<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
Friend WithEvents dlgFont As System.Windows.Forms.FontDialog<br />
End Class</source><br />
<br />
==Get selected font from FontDialog==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.IO<br />
Imports System.Windows.Forms<br />
public class FontDialogSelectedFont<br />
public Shared Sub Main<br />
Dim FontDB As New FontDialog()<br />
If (FontDB.ShowDialog() = DialogResult.OK) Then<br />
Console.WriteLine(FontDB.Font)<br />
End If<br />
End Sub<br />
End class</source><br />
<br />
==Installed Font Collection==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Globalization<br />
Imports System.Text<br />
Imports System.Collections<br />
Imports System.ruponentModel<br />
Imports System.Windows.Forms<br />
Imports System.Data<br />
Imports System.Drawing<br />
Imports System.Drawing.Text<br />
Imports System<br />
<br />
public class Tester<br />
public Shared Sub Main<br />
Dim family As FontFamily<br />
Dim installedFonts As InstalledFontCollection = New InstalledFontCollection()<br />
For Each family In installedFonts.Families<br />
Console.WriteLine(family.Name)<br />
Next family<br />
End Sub<br />
End class</source><br />
<br />
==List all font family name==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System<br />
Imports System.Drawing<br />
Imports System.Collections<br />
Imports System.ruponentModel<br />
Imports System.Windows.Forms<br />
Imports System.Globalization<br />
<br />
public class Tester<br />
public Shared Sub Main<br />
Dim family As FontFamily<br />
For Each family In FontFamily.Families<br />
If family.IsStyleAvailable(FontStyle.Bold) = False Then Exit For<br />
Console.WriteLine(family.Name)<br />
Next family<br />
<br />
End Sub<br />
End class</source><br />
<pre class=codeResult>Aharoni<br />
Andalus<br />
Angsana New<br />
AngsanaUPC<br />
Arabic Transparent<br />
Arial<br />
Arial Black<br />
Arial Narrow<br />
Batang<br />
BatangChe<br />
Book Antiqua<br />
Bookman Old Style<br />
Browallia New<br />
BrowalliaUPC<br />
Comic Sans MS<br />
Cordia New<br />
CordiaUPC<br />
Courier New<br />
David<br />
David Transparent<br />
DilleniaUPC<br />
Dotum<br />
DotumChe<br />
Estrangelo Edessa<br />
EucrosiaUPC<br />
Fixed Miriam Transparent<br />
Franklin Gothic Medium<br />
FrankRuehl<br />
FreesiaUPC<br />
Garamond<br />
Gautami<br />
Georgia<br />
Gulim<br />
GulimChe<br />
Gungsuh<br />
GungsuhChe<br />
Haettenschweiler<br />
Impact<br />
IrisUPC<br />
JasmineUPC<br />
Kartika<br />
KodchiangUPC<br />
Latha<br />
Levenim MT<br />
LilyUPC<br />
Lucida Console<br />
Lucida Sans Unicode<br />
Mangal<br />
Marlett<br />
Microsoft Sans Serif<br />
MingLiU<br />
Miriam<br />
Miriam Fixed<br />
Miriam Transparent</pre><br />
<br />
==Paint all available font families==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System<br />
Imports System.Drawing<br />
Imports System.Collections<br />
Imports System.ruponentModel<br />
Imports System.Windows.Forms<br />
Imports System.Data<br />
Imports System.Drawing.Text<br />
public class PaintAllAvailableFonts<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
public class Form1<br />
Inherits System.Windows.Forms.Form<br />
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)<br />
Dim g As Graphics = e.Graphics<br />
g.Clear(Me.BackColor)<br />
Dim families As FontFamily() = FontFamily.GetFamilies(g)<br />
Dim familiesFont As Font<br />
Dim familyString As String<br />
Dim spacing As Single = 0<br />
Dim family As FontFamily<br />
For Each family In families<br />
familiesFont = New Font(family, 16, FontStyle.Bold)<br />
familyString = "This is the " + family.Name + "family."<br />
g.DrawString(familyString, familiesFont, Brushes.Black, New PointF(0, spacing))<br />
spacing += familiesFont.Height<br />
Next family<br />
g.Dispose()<br />
End Sub<br />
Public Sub New()<br />
<br />
MyBase.New()<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(292, 273)<br />
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen<br />
End Sub<br />
End Class</source><br />
<br />
==Set Properties for a FontDialog==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Windows.Forms<br />
public class FontDialogProperty<br />
public Shared Sub Main<br />
<br />
Dim FontDialog1 As FontDialog = New System.Windows.Forms.FontDialog<br />
<br />
Dim objNewFont As Font<br />
objNewFont = New Font("Verdana", 12, FontStyle.Underline)<br />
With FontDialog1<br />
.Font = objNewFont<br />
.AllowScriptChange = False<br />
.ShowColor = True<br />
.Color = Color.Blue<br />
.ShowApply = True<br />
".ShowEffects = False<br />
End With<br />
If FontDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then<br />
Console.WriteLine(FontDialog1.Font)<br />
Console.WriteLine(FontDialog1.Color)<br />
End If<br />
End Sub<br />
End class</source><br />
<br />
==Use Font dialog to set Label font==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing.Text<br />
Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class UseFontDialogToSetLabelFont<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
<br />
Public Sub New()<br />
MyBase.New()<br />
InitializeComponent()<br />
End Sub<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
Private components As System.ruponentModel.IContainer<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents FontDialog1 As System.Windows.Forms.FontDialog<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.Label1 = New System.Windows.Forms.Label<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.FontDialog1 = New System.Windows.Forms.FontDialog<br />
Me.SuspendLayout()<br />
"<br />
"Label1<br />
"<br />
Me.Label1.Location = New System.Drawing.Point(48, 16)<br />
Me.Label1.Name = "Label1"<br />
Me.Label1.Size = New System.Drawing.Size(168, 96)<br />
Me.Label1.TabIndex = 0<br />
Me.Label1.Text = "Font Setting"<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(88, 136)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.Size = New System.Drawing.Size(88, 24)<br />
Me.Button1.TabIndex = 1<br />
Me.Button1.Text = "Change Font"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(272, 190)<br />
Me.Controls.Add(Me.Button1)<br />
Me.Controls.Add(Me.Label1)<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
FontDialog1.ShowDialog()<br />
Label1.Font = FontDialog1.Font<br />
End Sub<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/Regular_Expressions/MatchCollection&diff=3939
VB.Net Tutorial/Regular Expressions/MatchCollection
2010-05-26T12:57:33Z
<p>Admin: 1 версия</p>
<hr />
<div>==Use MatchCollection==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Text.RegularExpressions<br />
Public Class Tester<br />
Public Shared Sub Main<br />
Dim source As String = "This 7. several 0.9 numbers"<br />
Dim parser As New Regex( _<br />
"[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?")<br />
Dim sourceMatches As MatchCollection = _<br />
parser.Matches(source)<br />
Dim result As Double = CDbl(sourceMatches(1).Value)<br />
Console.WriteLine(result.ToString())<br />
End Sub<br />
<br />
End Class</source><br />
<pre class=codeResult>0.9</pre></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/FlowLayoutPanel&diff=3933
VB.Net Tutorial/GUI/FlowLayoutPanel
2010-05-26T12:57:32Z
<p>Admin: 1 версия</p>
<hr />
<div>==FlowLayoutPanel==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class FlowLayoutPanelTableLayoutPanel<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.TableLayoutPanel1 = New System.Windows.Forms.TableLayoutPanel<br />
Me.FlowLayoutPanel1 = New System.Windows.Forms.FlowLayoutPanel<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.Label1 = New System.Windows.Forms.Label<br />
Me.Label2 = New System.Windows.Forms.Label<br />
Me.Button2 = New System.Windows.Forms.Button<br />
Me.Button3 = New System.Windows.Forms.Button<br />
Me.Button4 = New System.Windows.Forms.Button<br />
Me.Button5 = New System.Windows.Forms.Button<br />
Me.Button6 = New System.Windows.Forms.Button<br />
Me.Button7 = New System.Windows.Forms.Button<br />
Me.Button8 = New System.Windows.Forms.Button<br />
Me.Button9 = New System.Windows.Forms.Button<br />
Me.Button10 = New System.Windows.Forms.Button<br />
Me.Button11 = New System.Windows.Forms.Button<br />
Me.Button12 = New System.Windows.Forms.Button<br />
Me.Button13 = New System.Windows.Forms.Button<br />
Me.Button14 = New System.Windows.Forms.Button<br />
Me.Button15 = New System.Windows.Forms.Button<br />
Me.Button16 = New System.Windows.Forms.Button<br />
Me.Button17 = New System.Windows.Forms.Button<br />
Me.Button18 = New System.Windows.Forms.Button<br />
Me.TableLayoutPanel1.SuspendLayout()<br />
Me.FlowLayoutPanel1.SuspendLayout()<br />
Me.SuspendLayout()<br />
"<br />
"TableLayoutPanel1<br />
"<br />
Me.TableLayoutPanel1.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _<br />
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)<br />
Me.TableLayoutPanel1.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.OutsetDouble<br />
Me.TableLayoutPanel1.ColumnCount = 2<br />
Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50.0!))<br />
Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50.0!))<br />
Me.TableLayoutPanel1.Controls.Add(Me.Button10, 0, 0)<br />
Me.TableLayoutPanel1.Controls.Add(Me.Button11, 1, 0)<br />
Me.TableLayoutPanel1.Controls.Add(Me.Button12, 0, 1)<br />
Me.TableLayoutPanel1.Controls.Add(Me.Button13, 1, 1)<br />
Me.TableLayoutPanel1.Controls.Add(Me.Button14, 0, 2)<br />
Me.TableLayoutPanel1.Controls.Add(Me.Button15, 1, 2)<br />
Me.TableLayoutPanel1.Controls.Add(Me.Button16, 0, 3)<br />
Me.TableLayoutPanel1.Controls.Add(Me.Button17, 1, 3)<br />
Me.TableLayoutPanel1.Controls.Add(Me.Button18, 0, 4)<br />
Me.TableLayoutPanel1.Location = New System.Drawing.Point(264, 16)<br />
Me.TableLayoutPanel1.Name = "TableLayoutPanel1"<br />
Me.TableLayoutPanel1.RowCount = 5<br />
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20.0!))<br />
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20.0!))<br />
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20.0!))<br />
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20.0!))<br />
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20.0!))<br />
Me.TableLayoutPanel1.Size = New System.Drawing.Size(248, 173)<br />
Me.TableLayoutPanel1.TabIndex = 0<br />
"<br />
"FlowLayoutPanel1<br />
"<br />
Me.FlowLayoutPanel1.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _<br />
Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)<br />
Me.FlowLayoutPanel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D<br />
Me.FlowLayoutPanel1.Controls.Add(Me.Button1)<br />
Me.FlowLayoutPanel1.Controls.Add(Me.Button2)<br />
Me.FlowLayoutPanel1.Controls.Add(Me.Button3)<br />
Me.FlowLayoutPanel1.Controls.Add(Me.Button4)<br />
Me.FlowLayoutPanel1.Controls.Add(Me.Button5)<br />
Me.FlowLayoutPanel1.Controls.Add(Me.Button6)<br />
Me.FlowLayoutPanel1.Controls.Add(Me.Button7)<br />
Me.FlowLayoutPanel1.Controls.Add(Me.Button8)<br />
Me.FlowLayoutPanel1.Controls.Add(Me.Button9)<br />
Me.FlowLayoutPanel1.Location = New System.Drawing.Point(0, 16)<br />
Me.FlowLayoutPanel1.Name = "FlowLayoutPanel1"<br />
Me.FlowLayoutPanel1.Size = New System.Drawing.Size(256, 173)<br />
Me.FlowLayoutPanel1.TabIndex = 1<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(3, 3)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.Size = New System.Drawing.Size(72, 24)<br />
Me.Button1.TabIndex = 0<br />
Me.Button1.Text = "Button1"<br />
"<br />
"Label1<br />
"<br />
Me.Label1.AutoSize = True<br />
Me.Label1.Location = New System.Drawing.Point(0, 0)<br />
Me.Label1.Name = "Label1"<br />
Me.Label1.Size = New System.Drawing.Size(84, 13)<br />
Me.Label1.TabIndex = 2<br />
Me.Label1.Text = "FlowLayoutPanel"<br />
"<br />
"Label2<br />
"<br />
Me.Label2.AutoSize = True<br />
Me.Label2.Location = New System.Drawing.Point(264, 0)<br />
Me.Label2.Name = "Label2"<br />
Me.Label2.Size = New System.Drawing.Size(89, 13)<br />
Me.Label2.TabIndex = 3<br />
Me.Label2.Text = "TableLayoutPanel"<br />
"<br />
"Button2<br />
"<br />
Me.Button2.Location = New System.Drawing.Point(81, 3)<br />
Me.Button2.Name = "Button2"<br />
Me.Button2.Size = New System.Drawing.Size(72, 24)<br />
Me.Button2.TabIndex = 1<br />
Me.Button2.Text = "Button2"<br />
"<br />
"Button3<br />
"<br />
Me.Button3.Location = New System.Drawing.Point(159, 3)<br />
Me.Button3.Name = "Button3"<br />
Me.Button3.Size = New System.Drawing.Size(72, 24)<br />
Me.Button3.TabIndex = 2<br />
Me.Button3.Text = "Button3"<br />
"<br />
"Button4<br />
"<br />
Me.Button4.Location = New System.Drawing.Point(3, 33)<br />
Me.Button4.Name = "Button4"<br />
Me.Button4.Size = New System.Drawing.Size(72, 24)<br />
Me.Button4.TabIndex = 3<br />
Me.Button4.Text = "Button4"<br />
"<br />
"Button5<br />
"<br />
Me.Button5.Location = New System.Drawing.Point(81, 33)<br />
Me.Button5.Name = "Button5"<br />
Me.Button5.Size = New System.Drawing.Size(72, 24)<br />
Me.Button5.TabIndex = 4<br />
Me.Button5.Text = "Button5"<br />
"<br />
"Button6<br />
"<br />
Me.Button6.Location = New System.Drawing.Point(159, 33)<br />
Me.Button6.Name = "Button6"<br />
Me.Button6.Size = New System.Drawing.Size(72, 24)<br />
Me.Button6.TabIndex = 5<br />
Me.Button6.Text = "Button6"<br />
"<br />
"Button7<br />
"<br />
Me.Button7.Location = New System.Drawing.Point(3, 63)<br />
Me.Button7.Name = "Button7"<br />
Me.Button7.Size = New System.Drawing.Size(72, 24)<br />
Me.Button7.TabIndex = 6<br />
Me.Button7.Text = "Button7"<br />
"<br />
"Button8<br />
"<br />
Me.Button8.Location = New System.Drawing.Point(81, 63)<br />
Me.Button8.Name = "Button8"<br />
Me.Button8.Size = New System.Drawing.Size(72, 24)<br />
Me.Button8.TabIndex = 7<br />
Me.Button8.Text = "Button8"<br />
"<br />
"Button9<br />
"<br />
Me.Button9.Location = New System.Drawing.Point(159, 63)<br />
Me.Button9.Name = "Button9"<br />
Me.Button9.Size = New System.Drawing.Size(72, 24)<br />
Me.Button9.TabIndex = 8<br />
Me.Button9.Text = "Button9"<br />
"<br />
"Button10<br />
"<br />
Me.Button10.Anchor = System.Windows.Forms.AnchorStyles.None<br />
Me.Button10.Location = New System.Drawing.Point(26, 6)<br />
Me.Button10.Name = "Button10"<br />
Me.Button10.Size = New System.Drawing.Size(72, 24)<br />
Me.Button10.TabIndex = 9<br />
Me.Button10.Text = "Button10"<br />
"<br />
"Button11<br />
"<br />
Me.Button11.Anchor = System.Windows.Forms.AnchorStyles.None<br />
Me.Button11.Location = New System.Drawing.Point(149, 6)<br />
Me.Button11.Name = "Button11"<br />
Me.Button11.Size = New System.Drawing.Size(72, 24)<br />
Me.Button11.TabIndex = 10<br />
Me.Button11.Text = "Button11"<br />
"<br />
"Button12<br />
"<br />
Me.Button12.Anchor = System.Windows.Forms.AnchorStyles.None<br />
Me.Button12.Location = New System.Drawing.Point(26, 40)<br />
Me.Button12.Name = "Button12"<br />
Me.Button12.Size = New System.Drawing.Size(72, 24)<br />
Me.Button12.TabIndex = 11<br />
Me.Button12.Text = "Button12"<br />
"<br />
"Button13<br />
"<br />
Me.Button13.Anchor = System.Windows.Forms.AnchorStyles.None<br />
Me.Button13.Location = New System.Drawing.Point(149, 40)<br />
Me.Button13.Name = "Button13"<br />
Me.Button13.Size = New System.Drawing.Size(72, 24)<br />
Me.Button13.TabIndex = 12<br />
Me.Button13.Text = "Button13"<br />
"<br />
"Button14<br />
"<br />
Me.Button14.Anchor = System.Windows.Forms.AnchorStyles.None<br />
Me.Button14.Location = New System.Drawing.Point(26, 74)<br />
Me.Button14.Name = "Button14"<br />
Me.Button14.Size = New System.Drawing.Size(72, 24)<br />
Me.Button14.TabIndex = 13<br />
Me.Button14.Text = "Button14"<br />
"<br />
"Button15<br />
"<br />
Me.Button15.Anchor = System.Windows.Forms.AnchorStyles.None<br />
Me.Button15.Location = New System.Drawing.Point(149, 74)<br />
Me.Button15.Name = "Button15"<br />
Me.Button15.Size = New System.Drawing.Size(72, 24)<br />
Me.Button15.TabIndex = 14<br />
Me.Button15.Text = "Button15"<br />
"<br />
"Button16<br />
"<br />
Me.Button16.Anchor = System.Windows.Forms.AnchorStyles.None<br />
Me.Button16.Location = New System.Drawing.Point(26, 108)<br />
Me.Button16.Name = "Button16"<br />
Me.Button16.Size = New System.Drawing.Size(72, 24)<br />
Me.Button16.TabIndex = 15<br />
Me.Button16.Text = "Button16"<br />
"<br />
"Button17<br />
"<br />
Me.Button17.Anchor = System.Windows.Forms.AnchorStyles.None<br />
Me.Button17.Location = New System.Drawing.Point(149, 108)<br />
Me.Button17.Name = "Button17"<br />
Me.Button17.Size = New System.Drawing.Size(72, 24)<br />
Me.Button17.TabIndex = 16<br />
Me.Button17.Text = "Button17"<br />
"<br />
"Button18<br />
"<br />
Me.Button18.Anchor = System.Windows.Forms.AnchorStyles.None<br />
Me.Button18.Location = New System.Drawing.Point(26, 142)<br />
Me.Button18.Name = "Button18"<br />
Me.Button18.Size = New System.Drawing.Size(72, 24)<br />
Me.Button18.TabIndex = 17<br />
Me.Button18.Text = "Button18"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(514, 190)<br />
Me.Controls.Add(Me.Label2)<br />
Me.Controls.Add(Me.Label1)<br />
Me.Controls.Add(Me.FlowLayoutPanel1)<br />
Me.Controls.Add(Me.TableLayoutPanel1)<br />
Me.Name = "Form1"<br />
Me.Text = "FlowAndTableLayoutPanel"<br />
Me.TableLayoutPanel1.ResumeLayout(False)<br />
Me.FlowLayoutPanel1.ResumeLayout(False)<br />
Me.ResumeLayout(False)<br />
Me.PerformLayout()<br />
End Sub<br />
Friend WithEvents TableLayoutPanel1 As System.Windows.Forms.TableLayoutPanel<br />
Friend WithEvents FlowLayoutPanel1 As System.Windows.Forms.FlowLayoutPanel<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
Friend WithEvents Label2 As System.Windows.Forms.Label<br />
Friend WithEvents Button10 As System.Windows.Forms.Button<br />
Friend WithEvents Button11 As System.Windows.Forms.Button<br />
Friend WithEvents Button12 As System.Windows.Forms.Button<br />
Friend WithEvents Button13 As System.Windows.Forms.Button<br />
Friend WithEvents Button14 As System.Windows.Forms.Button<br />
Friend WithEvents Button15 As System.Windows.Forms.Button<br />
Friend WithEvents Button16 As System.Windows.Forms.Button<br />
Friend WithEvents Button17 As System.Windows.Forms.Button<br />
Friend WithEvents Button18 As System.Windows.Forms.Button<br />
Friend WithEvents Button2 As System.Windows.Forms.Button<br />
Friend WithEvents Button3 As System.Windows.Forms.Button<br />
Friend WithEvents Button4 As System.Windows.Forms.Button<br />
Friend WithEvents Button5 As System.Windows.Forms.Button<br />
Friend WithEvents Button6 As System.Windows.Forms.Button<br />
Friend WithEvents Button7 As System.Windows.Forms.Button<br />
Friend WithEvents Button8 As System.Windows.Forms.Button<br />
Friend WithEvents Button9 As System.Windows.Forms.Button<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/CheckedListBox&diff=3935
VB.Net Tutorial/GUI/CheckedListBox
2010-05-26T12:57:32Z
<p>Admin: 1 версия</p>
<hr />
<div>==Add value to Checked List Box==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class CheckBoxListAddValueSelectionEvent<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents CheckedListBox1 As System.Windows.Forms.CheckedListBox<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.CheckedListBox1 = New System.Windows.Forms.CheckedListBox<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.SuspendLayout()<br />
"<br />
"CheckedListBox1<br />
"<br />
Me.CheckedListBox1.CheckOnClick = True<br />
Me.CheckedListBox1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.CheckedListBox1.Location = New System.Drawing.Point(96, 6)<br />
Me.CheckedListBox1.Name = "CheckedListBox1"<br />
Me.CheckedListBox1.Size = New System.Drawing.Size(120, 150)<br />
Me.CheckedListBox1.TabIndex = 0<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.TextBox1.Location = New System.Drawing.Point(16, 184)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(296, 20)<br />
Me.TextBox1.TabIndex = 2<br />
Me.TextBox1.Text = "TextBox1"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(15, 37)<br />
Me.ClientSize = New System.Drawing.Size(336, 229)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.Controls.Add(Me.CheckedListBox1)<br />
Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 24.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
CheckedListBox1.Items.Add("Item 1", True)<br />
CheckedListBox1.Items.Add("Item 2", True)<br />
CheckedListBox1.Items.Add("Item 3", True)<br />
CheckedListBox1.Items.Add("Item 4", False)<br />
CheckedListBox1.Items.Add("Item 5", True)<br />
CheckedListBox1.Items.Add("Item 6", True)<br />
CheckedListBox1.Items.Add("Item 7", True)<br />
CheckedListBox1.Items.Add("Item 8", False)<br />
CheckedListBox1.Items.Add("Item 9", True)<br />
CheckedListBox1.Items.Add("Item 10", True)<br />
CheckedListBox1.Items.Add("Item 11", True)<br />
End Sub<br />
Private Sub CheckedListBox1_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck<br />
Select Case e.NewValue<br />
Case CheckState.Checked<br />
TextBox1.Text = "You checked Item " & e.Index<br />
Case CheckState.Unchecked<br />
TextBox1.Text = "You unchecked Item " & e.Index<br />
End Select<br />
End Sub<br />
End Class</source><br />
<br />
==CheckedListBox: Add Items, Get Selected Items and Get Selected Indices==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class CheckedListBoxAddItemGetSelected<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents btnAddItems As System.Windows.Forms.Button<br />
Friend WithEvents clb1 As System.Windows.Forms.CheckedListBox<br />
Friend WithEvents btnGetCheckedIndices As System.Windows.Forms.Button<br />
Friend WithEvents btnGetCheckedItems As System.Windows.Forms.Button<br />
Friend WithEvents ColorDialog1 As System.Windows.Forms.ColorDialog<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.btnAddItems = New System.Windows.Forms.Button()<br />
Me.clb1 = New System.Windows.Forms.CheckedListBox()<br />
Me.btnGetCheckedItems = New System.Windows.Forms.Button()<br />
Me.btnGetCheckedIndices = New System.Windows.Forms.Button()<br />
Me.ColorDialog1 = New System.Windows.Forms.ColorDialog()<br />
Me.SuspendLayout()<br />
"<br />
"btnAddItems<br />
"<br />
Me.btnAddItems.BackColor = System.Drawing.SystemColors.ControlLight<br />
Me.btnAddItems.Location = New System.Drawing.Point(176, 8)<br />
Me.btnAddItems.Name = "btnAddItems"<br />
Me.btnAddItems.Size = New System.Drawing.Size(104, 24)<br />
Me.btnAddItems.TabIndex = 3<br />
Me.btnAddItems.Text = "Add Items"<br />
"<br />
"clb1<br />
"<br />
Me.clb1.Location = New System.Drawing.Point(16, 8)<br />
Me.clb1.Name = "clb1"<br />
Me.clb1.Size = New System.Drawing.Size(144, 79)<br />
Me.clb1.TabIndex = 4<br />
"<br />
"btnGetCheckedItems<br />
"<br />
Me.btnGetCheckedItems.BackColor = System.Drawing.SystemColors.ControlLight<br />
Me.btnGetCheckedItems.Location = New System.Drawing.Point(176, 40)<br />
Me.btnGetCheckedItems.Name = "btnGetCheckedItems"<br />
Me.btnGetCheckedItems.Size = New System.Drawing.Size(104, 24)<br />
Me.btnGetCheckedItems.TabIndex = 5<br />
Me.btnGetCheckedItems.Text = "Checked by Item"<br />
"<br />
"btnGetCheckedIndices<br />
"<br />
Me.btnGetCheckedIndices.BackColor = System.Drawing.SystemColors.ControlLight<br />
Me.btnGetCheckedIndices.Location = New System.Drawing.Point(176, 72)<br />
Me.btnGetCheckedIndices.Name = "btnGetCheckedIndices"<br />
Me.btnGetCheckedIndices.Size = New System.Drawing.Size(104, 24)<br />
Me.btnGetCheckedIndices.TabIndex = 6<br />
Me.btnGetCheckedIndices.Text = "Checked by Index"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(296, 277)<br />
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnGetCheckedIndices, Me.btnGetCheckedItems, Me.clb1, Me.btnAddItems})<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub btnAddItems_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddItems.Click<br />
clb1.Items.Add("A", True)<br />
clb1.Items.Add("B", True)<br />
clb1.Items.Add("C", True)<br />
clb1.Items.Add("D", False)<br />
End Sub<br />
Private Sub btnGetCheckedItems_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetCheckedItems.Click<br />
Dim o As Object<br />
For Each o In clb1.CheckedItems<br />
Console.WriteLine(o.ToString)<br />
Next o<br />
<br />
End Sub<br />
Private Sub btnGetCheckedIndices_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetCheckedIndices.Click<br />
Dim o As Object<br />
For Each o In clb1.CheckedIndices<br />
Console.WriteLine(o)<br />
Next o<br />
End Sub<br />
End Class</source><br />
<br />
==Checked List Box selection event==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class CheckBoxListAddValueSelectionEvent<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents CheckedListBox1 As System.Windows.Forms.CheckedListBox<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.CheckedListBox1 = New System.Windows.Forms.CheckedListBox<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.SuspendLayout()<br />
"<br />
"CheckedListBox1<br />
"<br />
Me.CheckedListBox1.CheckOnClick = True<br />
Me.CheckedListBox1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.CheckedListBox1.Location = New System.Drawing.Point(96, 6)<br />
Me.CheckedListBox1.Name = "CheckedListBox1"<br />
Me.CheckedListBox1.Size = New System.Drawing.Size(120, 150)<br />
Me.CheckedListBox1.TabIndex = 0<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.TextBox1.Location = New System.Drawing.Point(16, 184)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(296, 20)<br />
Me.TextBox1.TabIndex = 2<br />
Me.TextBox1.Text = "TextBox1"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(15, 37)<br />
Me.ClientSize = New System.Drawing.Size(336, 229)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.Controls.Add(Me.CheckedListBox1)<br />
Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 24.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
CheckedListBox1.Items.Add("Item 1", True)<br />
CheckedListBox1.Items.Add("Item 2", True)<br />
CheckedListBox1.Items.Add("Item 3", True)<br />
CheckedListBox1.Items.Add("Item 4", False)<br />
CheckedListBox1.Items.Add("Item 5", True)<br />
CheckedListBox1.Items.Add("Item 6", True)<br />
CheckedListBox1.Items.Add("Item 7", True)<br />
CheckedListBox1.Items.Add("Item 8", False)<br />
CheckedListBox1.Items.Add("Item 9", True)<br />
CheckedListBox1.Items.Add("Item 10", True)<br />
CheckedListBox1.Items.Add("Item 11", True)<br />
End Sub<br />
Private Sub CheckedListBox1_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck<br />
Select Case e.NewValue<br />
Case CheckState.Checked<br />
TextBox1.Text = "You checked Item " & e.Index<br />
Case CheckState.Unchecked<br />
TextBox1.Text = "You unchecked Item " & e.Index<br />
End Select<br />
End Sub<br />
End Class</source><br />
<br />
==Using the checked list boxes to add items to a list box==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class CheckedListBoxAddRemove<br />
public Shared Sub Main<br />
Application.Run(New FrmCheckedListBox)<br />
End Sub<br />
End class<br />
Public Class FrmCheckedListBox<br />
Inherits Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
" list of available book titles<br />
Friend WithEvents chklstInput As CheckedListBox<br />
" user selection list<br />
Friend WithEvents lstDisplay As ListBox<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.Container<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.chklstInput = New System.Windows.Forms.CheckedListBox()<br />
Me.lstDisplay = New System.Windows.Forms.ListBox()<br />
Me.SuspendLayout()<br />
"<br />
"chklstInput<br />
"<br />
Me.chklstInput.HorizontalScrollbar = True<br />
Me.chklstInput.Items.AddRange(New Object() {"A", "B", "C", "D", "E", "F", "G", "H"})<br />
Me.chklstInput.Location = New System.Drawing.Point(16, 16)<br />
Me.chklstInput.Name = "chklstInput"<br />
Me.chklstInput.Size = New System.Drawing.Size(152, 124)<br />
Me.chklstInput.TabIndex = 1<br />
"<br />
"lstDisplay<br />
"<br />
Me.lstDisplay.Anchor = (System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right)<br />
Me.lstDisplay.HorizontalScrollbar = True<br />
Me.lstDisplay.Location = New System.Drawing.Point(184, 16)<br />
Me.lstDisplay.Name = "lstDisplay"<br />
Me.lstDisplay.Size = New System.Drawing.Size(128, 121)<br />
Me.lstDisplay.TabIndex = 2<br />
"<br />
"FrmCheckedListBox<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(328, 157)<br />
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lstDisplay, Me.chklstInput})<br />
Me.Name = "FrmCheckedListBox"<br />
Me.Text = "Checked List Box Test"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub chklstInput_ItemCheck _<br />
(ByVal sender As System.Object, _<br />
ByVal e As System.Windows.Forms.ItemCheckEventArgs) _<br />
Handles chklstInput.ItemCheck<br />
Dim item As String = chklstInput.SelectedItem<br />
If e.NewValue = CheckState.Checked Then<br />
lstDisplay.Items.Add(item)<br />
Else<br />
lstDisplay.Items.Remove(item)<br />
End If<br />
End Sub<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/TableLayoutPanel&diff=3927
VB.Net Tutorial/GUI/TableLayoutPanel
2010-05-26T12:57:31Z
<p>Admin: 1 версия</p>
<hr />
<div>==TableLayoutPanel==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class FlowLayoutPanelTableLayoutPanel<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.TableLayoutPanel1 = New System.Windows.Forms.TableLayoutPanel<br />
Me.FlowLayoutPanel1 = New System.Windows.Forms.FlowLayoutPanel<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.Label1 = New System.Windows.Forms.Label<br />
Me.Label2 = New System.Windows.Forms.Label<br />
Me.Button2 = New System.Windows.Forms.Button<br />
Me.Button3 = New System.Windows.Forms.Button<br />
Me.Button4 = New System.Windows.Forms.Button<br />
Me.Button5 = New System.Windows.Forms.Button<br />
Me.Button6 = New System.Windows.Forms.Button<br />
Me.Button7 = New System.Windows.Forms.Button<br />
Me.Button8 = New System.Windows.Forms.Button<br />
Me.Button9 = New System.Windows.Forms.Button<br />
Me.Button10 = New System.Windows.Forms.Button<br />
Me.Button11 = New System.Windows.Forms.Button<br />
Me.Button12 = New System.Windows.Forms.Button<br />
Me.Button13 = New System.Windows.Forms.Button<br />
Me.Button14 = New System.Windows.Forms.Button<br />
Me.Button15 = New System.Windows.Forms.Button<br />
Me.Button16 = New System.Windows.Forms.Button<br />
Me.Button17 = New System.Windows.Forms.Button<br />
Me.Button18 = New System.Windows.Forms.Button<br />
Me.TableLayoutPanel1.SuspendLayout()<br />
Me.FlowLayoutPanel1.SuspendLayout()<br />
Me.SuspendLayout()<br />
"<br />
"TableLayoutPanel1<br />
"<br />
Me.TableLayoutPanel1.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _<br />
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)<br />
Me.TableLayoutPanel1.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.OutsetDouble<br />
Me.TableLayoutPanel1.ColumnCount = 2<br />
Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50.0!))<br />
Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50.0!))<br />
Me.TableLayoutPanel1.Controls.Add(Me.Button10, 0, 0)<br />
Me.TableLayoutPanel1.Controls.Add(Me.Button11, 1, 0)<br />
Me.TableLayoutPanel1.Controls.Add(Me.Button12, 0, 1)<br />
Me.TableLayoutPanel1.Controls.Add(Me.Button13, 1, 1)<br />
Me.TableLayoutPanel1.Controls.Add(Me.Button14, 0, 2)<br />
Me.TableLayoutPanel1.Controls.Add(Me.Button15, 1, 2)<br />
Me.TableLayoutPanel1.Controls.Add(Me.Button16, 0, 3)<br />
Me.TableLayoutPanel1.Controls.Add(Me.Button17, 1, 3)<br />
Me.TableLayoutPanel1.Controls.Add(Me.Button18, 0, 4)<br />
Me.TableLayoutPanel1.Location = New System.Drawing.Point(264, 16)<br />
Me.TableLayoutPanel1.Name = "TableLayoutPanel1"<br />
Me.TableLayoutPanel1.RowCount = 5<br />
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20.0!))<br />
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20.0!))<br />
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20.0!))<br />
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20.0!))<br />
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 20.0!))<br />
Me.TableLayoutPanel1.Size = New System.Drawing.Size(248, 173)<br />
Me.TableLayoutPanel1.TabIndex = 0<br />
"<br />
"FlowLayoutPanel1<br />
"<br />
Me.FlowLayoutPanel1.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _<br />
Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)<br />
Me.FlowLayoutPanel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D<br />
Me.FlowLayoutPanel1.Controls.Add(Me.Button1)<br />
Me.FlowLayoutPanel1.Controls.Add(Me.Button2)<br />
Me.FlowLayoutPanel1.Controls.Add(Me.Button3)<br />
Me.FlowLayoutPanel1.Controls.Add(Me.Button4)<br />
Me.FlowLayoutPanel1.Controls.Add(Me.Button5)<br />
Me.FlowLayoutPanel1.Controls.Add(Me.Button6)<br />
Me.FlowLayoutPanel1.Controls.Add(Me.Button7)<br />
Me.FlowLayoutPanel1.Controls.Add(Me.Button8)<br />
Me.FlowLayoutPanel1.Controls.Add(Me.Button9)<br />
Me.FlowLayoutPanel1.Location = New System.Drawing.Point(0, 16)<br />
Me.FlowLayoutPanel1.Name = "FlowLayoutPanel1"<br />
Me.FlowLayoutPanel1.Size = New System.Drawing.Size(256, 173)<br />
Me.FlowLayoutPanel1.TabIndex = 1<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(3, 3)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.Size = New System.Drawing.Size(72, 24)<br />
Me.Button1.TabIndex = 0<br />
Me.Button1.Text = "Button1"<br />
"<br />
"Label1<br />
"<br />
Me.Label1.AutoSize = True<br />
Me.Label1.Location = New System.Drawing.Point(0, 0)<br />
Me.Label1.Name = "Label1"<br />
Me.Label1.Size = New System.Drawing.Size(84, 13)<br />
Me.Label1.TabIndex = 2<br />
Me.Label1.Text = "FlowLayoutPanel"<br />
"<br />
"Label2<br />
"<br />
Me.Label2.AutoSize = True<br />
Me.Label2.Location = New System.Drawing.Point(264, 0)<br />
Me.Label2.Name = "Label2"<br />
Me.Label2.Size = New System.Drawing.Size(89, 13)<br />
Me.Label2.TabIndex = 3<br />
Me.Label2.Text = "TableLayoutPanel"<br />
"<br />
"Button2<br />
"<br />
Me.Button2.Location = New System.Drawing.Point(81, 3)<br />
Me.Button2.Name = "Button2"<br />
Me.Button2.Size = New System.Drawing.Size(72, 24)<br />
Me.Button2.TabIndex = 1<br />
Me.Button2.Text = "Button2"<br />
"<br />
"Button3<br />
"<br />
Me.Button3.Location = New System.Drawing.Point(159, 3)<br />
Me.Button3.Name = "Button3"<br />
Me.Button3.Size = New System.Drawing.Size(72, 24)<br />
Me.Button3.TabIndex = 2<br />
Me.Button3.Text = "Button3"<br />
"<br />
"Button4<br />
"<br />
Me.Button4.Location = New System.Drawing.Point(3, 33)<br />
Me.Button4.Name = "Button4"<br />
Me.Button4.Size = New System.Drawing.Size(72, 24)<br />
Me.Button4.TabIndex = 3<br />
Me.Button4.Text = "Button4"<br />
"<br />
"Button5<br />
"<br />
Me.Button5.Location = New System.Drawing.Point(81, 33)<br />
Me.Button5.Name = "Button5"<br />
Me.Button5.Size = New System.Drawing.Size(72, 24)<br />
Me.Button5.TabIndex = 4<br />
Me.Button5.Text = "Button5"<br />
"<br />
"Button6<br />
"<br />
Me.Button6.Location = New System.Drawing.Point(159, 33)<br />
Me.Button6.Name = "Button6"<br />
Me.Button6.Size = New System.Drawing.Size(72, 24)<br />
Me.Button6.TabIndex = 5<br />
Me.Button6.Text = "Button6"<br />
"<br />
"Button7<br />
"<br />
Me.Button7.Location = New System.Drawing.Point(3, 63)<br />
Me.Button7.Name = "Button7"<br />
Me.Button7.Size = New System.Drawing.Size(72, 24)<br />
Me.Button7.TabIndex = 6<br />
Me.Button7.Text = "Button7"<br />
"<br />
"Button8<br />
"<br />
Me.Button8.Location = New System.Drawing.Point(81, 63)<br />
Me.Button8.Name = "Button8"<br />
Me.Button8.Size = New System.Drawing.Size(72, 24)<br />
Me.Button8.TabIndex = 7<br />
Me.Button8.Text = "Button8"<br />
"<br />
"Button9<br />
"<br />
Me.Button9.Location = New System.Drawing.Point(159, 63)<br />
Me.Button9.Name = "Button9"<br />
Me.Button9.Size = New System.Drawing.Size(72, 24)<br />
Me.Button9.TabIndex = 8<br />
Me.Button9.Text = "Button9"<br />
"<br />
"Button10<br />
"<br />
Me.Button10.Anchor = System.Windows.Forms.AnchorStyles.None<br />
Me.Button10.Location = New System.Drawing.Point(26, 6)<br />
Me.Button10.Name = "Button10"<br />
Me.Button10.Size = New System.Drawing.Size(72, 24)<br />
Me.Button10.TabIndex = 9<br />
Me.Button10.Text = "Button10"<br />
"<br />
"Button11<br />
"<br />
Me.Button11.Anchor = System.Windows.Forms.AnchorStyles.None<br />
Me.Button11.Location = New System.Drawing.Point(149, 6)<br />
Me.Button11.Name = "Button11"<br />
Me.Button11.Size = New System.Drawing.Size(72, 24)<br />
Me.Button11.TabIndex = 10<br />
Me.Button11.Text = "Button11"<br />
"<br />
"Button12<br />
"<br />
Me.Button12.Anchor = System.Windows.Forms.AnchorStyles.None<br />
Me.Button12.Location = New System.Drawing.Point(26, 40)<br />
Me.Button12.Name = "Button12"<br />
Me.Button12.Size = New System.Drawing.Size(72, 24)<br />
Me.Button12.TabIndex = 11<br />
Me.Button12.Text = "Button12"<br />
"<br />
"Button13<br />
"<br />
Me.Button13.Anchor = System.Windows.Forms.AnchorStyles.None<br />
Me.Button13.Location = New System.Drawing.Point(149, 40)<br />
Me.Button13.Name = "Button13"<br />
Me.Button13.Size = New System.Drawing.Size(72, 24)<br />
Me.Button13.TabIndex = 12<br />
Me.Button13.Text = "Button13"<br />
"<br />
"Button14<br />
"<br />
Me.Button14.Anchor = System.Windows.Forms.AnchorStyles.None<br />
Me.Button14.Location = New System.Drawing.Point(26, 74)<br />
Me.Button14.Name = "Button14"<br />
Me.Button14.Size = New System.Drawing.Size(72, 24)<br />
Me.Button14.TabIndex = 13<br />
Me.Button14.Text = "Button14"<br />
"<br />
"Button15<br />
"<br />
Me.Button15.Anchor = System.Windows.Forms.AnchorStyles.None<br />
Me.Button15.Location = New System.Drawing.Point(149, 74)<br />
Me.Button15.Name = "Button15"<br />
Me.Button15.Size = New System.Drawing.Size(72, 24)<br />
Me.Button15.TabIndex = 14<br />
Me.Button15.Text = "Button15"<br />
"<br />
"Button16<br />
"<br />
Me.Button16.Anchor = System.Windows.Forms.AnchorStyles.None<br />
Me.Button16.Location = New System.Drawing.Point(26, 108)<br />
Me.Button16.Name = "Button16"<br />
Me.Button16.Size = New System.Drawing.Size(72, 24)<br />
Me.Button16.TabIndex = 15<br />
Me.Button16.Text = "Button16"<br />
"<br />
"Button17<br />
"<br />
Me.Button17.Anchor = System.Windows.Forms.AnchorStyles.None<br />
Me.Button17.Location = New System.Drawing.Point(149, 108)<br />
Me.Button17.Name = "Button17"<br />
Me.Button17.Size = New System.Drawing.Size(72, 24)<br />
Me.Button17.TabIndex = 16<br />
Me.Button17.Text = "Button17"<br />
"<br />
"Button18<br />
"<br />
Me.Button18.Anchor = System.Windows.Forms.AnchorStyles.None<br />
Me.Button18.Location = New System.Drawing.Point(26, 142)<br />
Me.Button18.Name = "Button18"<br />
Me.Button18.Size = New System.Drawing.Size(72, 24)<br />
Me.Button18.TabIndex = 17<br />
Me.Button18.Text = "Button18"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(514, 190)<br />
Me.Controls.Add(Me.Label2)<br />
Me.Controls.Add(Me.Label1)<br />
Me.Controls.Add(Me.FlowLayoutPanel1)<br />
Me.Controls.Add(Me.TableLayoutPanel1)<br />
Me.Name = "Form1"<br />
Me.Text = "FlowAndTableLayoutPanel"<br />
Me.TableLayoutPanel1.ResumeLayout(False)<br />
Me.FlowLayoutPanel1.ResumeLayout(False)<br />
Me.ResumeLayout(False)<br />
Me.PerformLayout()<br />
End Sub<br />
Friend WithEvents TableLayoutPanel1 As System.Windows.Forms.TableLayoutPanel<br />
Friend WithEvents FlowLayoutPanel1 As System.Windows.Forms.FlowLayoutPanel<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
Friend WithEvents Label2 As System.Windows.Forms.Label<br />
Friend WithEvents Button10 As System.Windows.Forms.Button<br />
Friend WithEvents Button11 As System.Windows.Forms.Button<br />
Friend WithEvents Button12 As System.Windows.Forms.Button<br />
Friend WithEvents Button13 As System.Windows.Forms.Button<br />
Friend WithEvents Button14 As System.Windows.Forms.Button<br />
Friend WithEvents Button15 As System.Windows.Forms.Button<br />
Friend WithEvents Button16 As System.Windows.Forms.Button<br />
Friend WithEvents Button17 As System.Windows.Forms.Button<br />
Friend WithEvents Button18 As System.Windows.Forms.Button<br />
Friend WithEvents Button2 As System.Windows.Forms.Button<br />
Friend WithEvents Button3 As System.Windows.Forms.Button<br />
Friend WithEvents Button4 As System.Windows.Forms.Button<br />
Friend WithEvents Button5 As System.Windows.Forms.Button<br />
Friend WithEvents Button6 As System.Windows.Forms.Button<br />
Friend WithEvents Button7 As System.Windows.Forms.Button<br />
Friend WithEvents Button8 As System.Windows.Forms.Button<br />
Friend WithEvents Button9 As System.Windows.Forms.Button<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/Print&diff=3929
VB.Net Tutorial/GUI/Print
2010-05-26T12:57:31Z
<p>Admin: 1 версия</p>
<hr />
<div>==Print text in TextBox to printer and set up page==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
Imports System.Drawing.Printing<br />
public class PrintTextBox<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
Private PrtSetupDB As New PrintDialog()<br />
Private WithEvents PrtDocument As New System.Drawing.Printing.PrintDocument()<br />
Private PageSetupDB As New PageSetupDialog()<br />
Private PrintPreviewDB As New PrintPreviewDialog()<br />
Private PrinterSettings As New System.Drawing.Printing.PrinterSettings()<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents Button2 As System.Windows.Forms.Button<br />
Friend WithEvents Button3 As System.Windows.Forms.Button<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.Button1 = New System.Windows.Forms.Button()<br />
Me.Button2 = New System.Windows.Forms.Button()<br />
Me.Button3 = New System.Windows.Forms.Button()<br />
Me.TextBox1 = New System.Windows.Forms.TextBox()<br />
Me.SuspendLayout()<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(20, 20)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.TabIndex = 0<br />
Me.Button1.Text = "Page Setup"<br />
"<br />
"Button2<br />
"<br />
Me.Button2.Location = New System.Drawing.Point(110, 20)<br />
Me.Button2.Name = "Button2"<br />
Me.Button2.TabIndex = 1<br />
Me.Button2.Text = "Preview"<br />
"<br />
"Button3<br />
"<br />
Me.Button3.Location = New System.Drawing.Point(200, 20)<br />
Me.Button3.Name = "Button3"<br />
Me.Button3.TabIndex = 2<br />
Me.Button3.Text = "Print"<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(16, 64)<br />
Me.TextBox1.Multiline = True<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(264, 232)<br />
Me.TextBox1.TabIndex = 3<br />
Me.TextBox1.Text = ""<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(296, 325)<br />
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox1, Me.Button3, Me.Button2, Me.Button1})<br />
Me.Name = "Form1"<br />
Me.Text = "PrintFormText"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
PageSetupDB.Document = PrtDocument<br />
PageSetupDB.ShowDialog()<br />
End Sub<br />
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click<br />
PrintPreviewDB.Document = PrtDocument<br />
PrintPreviewDB.ShowDialog()<br />
End Sub<br />
Private Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click<br />
PrtSetupDB.Document = PrtDocument<br />
PrtSetupDB.PrinterSettings = PrinterSettings<br />
If (PrtSetupDB.ShowDialog() = DialogResult.OK) Then<br />
PrtDocument.Print()<br />
End If<br />
End Sub<br />
Private Sub PrtDocument_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs) Handles PrtDocument.PrintPage<br />
ev.Graphics.DrawString(TextBox1.Text, TextBox1.Font, Brushes.Black, 0, 0)<br />
End Sub<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/PropertyGrid&diff=3931
VB.Net Tutorial/GUI/PropertyGrid
2010-05-26T12:57:31Z
<p>Admin: 1 версия</p>
<hr />
<div>==PropertyGrid Demo==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.ruponentModel<br />
Imports System.Windows.Forms<br />
public class PropertyGridDemo<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<br />
Public Class Form1<br />
Private m_Employee As Employee<br />
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
m_Employee = New Employee("R", "S", 4, "A", 6, 4,"6789", 1)<br />
PropertyGrid1.rumandsVisibleIfAvailable = True<br />
PropertyGrid1.Text = "Employee"<br />
PropertyGrid1.SelectedObject = m_Employee<br />
End Sub<br />
End Class<br />
Public Class Employee<br />
Private m_FirstName As String<br />
Private m_LastName As String<br />
Private m_EmployeeId As Integer<br />
Private m_Department As String<br />
Private m_Office As Integer<br />
Private m_Extension As Integer<br />
Private m_SocialSecurityNumber As String<br />
Private m_Salary As Integer<br />
<Description("Extension"), Category("Contact Information")> _<br />
Public Property Extension() As Integer<br />
Get<br />
Return m_Extension<br />
End Get<br />
Set(ByVal value As Integer)<br />
m_Extension = value<br />
End Set<br />
End Property<br />
<Description("Office number"), Category("Contact Information")> _<br />
Public Property Office() As Integer<br />
Get<br />
Return m_Office<br />
End Get<br />
Set(ByVal value As Integer)<br />
m_Office = value<br />
End Set<br />
End Property<br />
<Description("Department"), Category("Organization")> _<br />
Public Property Department() As String<br />
Get<br />
Return m_Department<br />
End Get<br />
Set(ByVal value As String)<br />
m_Department = value<br />
End Set<br />
End Property<br />
<Description("ID"), Category("Personnel")> _<br />
Public Property EmployeeId() As Integer<br />
Get<br />
Return m_EmployeeId<br />
End Get<br />
Set(ByVal value As Integer)<br />
m_EmployeeId = value<br />
End Set<br />
End Property<br />
<Description("First name"), Category("Personnel")> _<br />
Public Property FirstName() As String<br />
Get<br />
Return m_FirstName<br />
End Get<br />
Set(ByVal value As String)<br />
m_FirstName = value<br />
End Set<br />
End Property<br />
<Description("Last name"), Category("Personnel")> _<br />
Public Property LastName() As String<br />
Get<br />
Return m_LastName<br />
End Get<br />
Set(ByVal value As String)<br />
m_LastName = value<br />
End Set<br />
End Property<br />
<Description("Social Security number"), Category("Personnel")> _<br />
Public Property SocialSecurityNumber() As String<br />
Get<br />
Return m_SocialSecurityNumber<br />
End Get<br />
Set(ByVal value As String)<br />
m_SocialSecurityNumber = value<br />
End Set<br />
End Property<br />
<Description("Annual salary"), Category("Personnel")> _<br />
Public Property Salary() As Integer<br />
Get<br />
Return m_Salary<br />
End Get<br />
Set(ByVal value As Integer)<br />
m_Salary = value<br />
End Set<br />
End Property<br />
Public Sub New(ByVal first_name As String, ByVal last_name As String, ByVal employee_id As Integer, ByVal new_department As String, ByVal new_office As Integer, ByVal new_extension As Integer, ByVal social_security_number As String, ByVal new_salary As Integer)<br />
m_FirstName = first_name<br />
m_LastName = last_name<br />
m_EmployeeId = employee_id<br />
m_Department = new_department<br />
m_Office = new_office<br />
m_Extension = new_extension<br />
m_SocialSecurityNumber = social_security_number<br />
m_Salary = new_salary<br />
End Sub<br />
End Class<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.PropertyGrid1 = New System.Windows.Forms.PropertyGrid<br />
Me.SuspendLayout()<br />
"<br />
"PropertyGrid1<br />
"<br />
Me.PropertyGrid1.Dock = System.Windows.Forms.DockStyle.Fill<br />
Me.PropertyGrid1.Location = New System.Drawing.Point(0, 0)<br />
Me.PropertyGrid1.Name = "PropertyGrid1"<br />
Me.PropertyGrid1.Size = New System.Drawing.Size(292, 273)<br />
Me.PropertyGrid1.TabIndex = 0<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(292, 273)<br />
Me.Controls.Add(Me.PropertyGrid1)<br />
Me.Name = "Form1"<br />
Me.Text = "Employee"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
Friend WithEvents PropertyGrid1 As System.Windows.Forms.PropertyGrid<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/ListView_Sort&diff=3923
VB.Net Tutorial/GUI/ListView Sort
2010-05-26T12:57:30Z
<p>Admin: 1 версия</p>
<hr />
<div>==ListView custom sort==<br />
<br />
<br />
<br />
<source lang="vbnet">"Visual Basic 2005 Programmer"s Reference<br />
"by Rod Stephens (Author) <br />
"# Publisher: Wrox (October 21, 2005)<br />
"# Language: English<br />
"# ISBN-10: 0764571982<br />
"# ISBN-13: 978-0764571985<br />
Imports System.Windows.Forms<br />
Imports System.Collections<br />
public class ListViewCustomSort<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
" The column currently used for sorting.<br />
Private m_SortingColumn As ColumnHeader<br />
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
" Make the ListView column headers.<br />
ListViewMakeColumnHeaders(lvwBooks, _<br />
"Title", HorizontalAlignment.Left, 120, _<br />
"URL", HorizontalAlignment.Left, 120, _<br />
"ISBN", HorizontalAlignment.Left, 90, _<br />
"Picture", HorizontalAlignment.Left, 120, _<br />
"Pages", HorizontalAlignment.Right, 50, _<br />
"Year", HorizontalAlignment.Right, 40)<br />
ListViewMakeRow(lvwBooks, 0, _<br />
"Visual Basic and XML", _<br />
"http://www.vb-helper.ru/xml.htm", _<br />
"0-471-12060-X", _<br />
"http://www.vb-helper.ru/xml.jpg", _<br />
"503", _<br />
"2002")<br />
ListViewMakeRow(lvwBooks, 0, _<br />
"Visual Basic Graphics Programming, 2e", _<br />
"http://www.vb-helper.ru/vbgp.htm", _<br />
"0-471-35599-2", _<br />
"http://www.vb-helper.ru/vbgp.jpg", _<br />
"712", _<br />
"2000")<br />
ListViewMakeRow(lvwBooks, 0, _<br />
"Ready-to-Run Visual Basic Algorithms", _<br />
"http://www.vb-helper.ru/vba.htm", _<br />
"0-471-24268-3", _<br />
"http://www.vb-helper.ru/vba.jpg", _<br />
"395", _<br />
"1998")<br />
ListViewSizeColumns(lvwBooks, True)<br />
Text = "RunTimeListView (" & lvwBooks.View.ToString & ")"<br />
End Sub<br />
" Make the ListView"s column headers.<br />
" The ParamArray entries should be triples holding<br />
" column title, HorizontalAlignment value, and width.<br />
Private Sub ListViewMakeColumnHeaders(ByVal lvw As ListView, ByVal ParamArray header_info() As Object)<br />
" Remove any existing headers.<br />
lvw.Columns.Clear()<br />
" Make the column headers.<br />
For i As Integer = header_info.GetLowerBound(0) To header_info.GetUpperBound(0) Step 3<br />
Dim col_header As ColumnHeader = lvw.Columns.Add( _<br />
DirectCast(header_info(i), String), _<br />
-1, _<br />
DirectCast(header_info(i + 1), HorizontalAlignment))<br />
col_header.Width = DirectCast(header_info(i + 2), Integer)<br />
Next i<br />
End Sub<br />
" Make a ListView row.<br />
Private Sub ListViewMakeRow(ByVal lvw As ListView, ByVal image_index As Integer, ByVal item_title As String, ByVal ParamArray subitem_titles() As String)<br />
" Make the item.<br />
Dim new_item As ListViewItem = lvw.Items.Add(item_title)<br />
new_item.ImageIndex = image_index<br />
" Make the sub-items.<br />
For i As Integer = subitem_titles.GetLowerBound(0) To subitem_titles.GetUpperBound(0)<br />
new_item.SubItems.Add(subitem_titles(i))<br />
Next i<br />
End Sub<br />
" Set column widths to -1 to fit data,<br />
" -2 to fit data and header.<br />
Private Sub ListViewSizeColumns(ByVal lvw As ListView, ByVal allow_room_for_header As Boolean)<br />
Dim new_wid As Integer = -1<br />
If allow_room_for_header Then new_wid = -2<br />
" Set the width for each column.<br />
For i As Integer = 0 To lvw.Columns.Count - 1<br />
lvw.Columns(i).Width = new_wid<br />
Next i<br />
End Sub<br />
Private Sub mnuViewDetails_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuViewDetails.Click<br />
lvwBooks.View = View.Details<br />
Text = "RunTimeListView (" & lvwBooks.View.ToString & ")"<br />
End Sub<br />
Private Sub mnuViewLargeIcons_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuViewLargeIcons.Click<br />
lvwBooks.View = View.LargeIcon<br />
Text = "RunTimeListView (" & lvwBooks.View.ToString & ")"<br />
End Sub<br />
Private Sub mnuViewList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuViewList.Click<br />
lvwBooks.View = View.List<br />
Text = "RunTimeListView (" & lvwBooks.View.ToString & ")"<br />
End Sub<br />
Private Sub mnuViewSmallIcons_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuViewSmallIcons.Click<br />
lvwBooks.View = View.SmallIcon<br />
Text = "RunTimeListView (" & lvwBooks.View.ToString & ")"<br />
End Sub<br />
Private Sub mnuViewTile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuViewTile.Click<br />
lvwBooks.View = View.Tile<br />
Text = "RunTimeListView (" & lvwBooks.View.ToString & ")"<br />
End Sub<br />
" Sort using the clicked column.<br />
Private Sub lvwBooks_ColumnClick(ByVal sender As System.Object, _<br />
ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles lvwBooks.ColumnClick<br />
" Get the new sorting column.<br />
Dim new_sorting_column As ColumnHeader = _<br />
lvwBooks.Columns(e.Column)<br />
" Figure out the new sorting order.<br />
Dim sort_order As System.Windows.Forms.SortOrder<br />
If m_SortingColumn Is Nothing Then<br />
" New column. Sort ascending.<br />
sort_order = SortOrder.Ascending<br />
Else<br />
" See if this is the same column.<br />
If new_sorting_column.Equals(m_SortingColumn) Then<br />
" Same column. Switch the sort order.<br />
If m_SortingColumn.Text.StartsWith("> ") Then<br />
sort_order = SortOrder.Descending<br />
Else<br />
sort_order = SortOrder.Ascending<br />
End If<br />
Else<br />
" New column. Sort ascending.<br />
sort_order = SortOrder.Ascending<br />
End If<br />
" Remove the old sort indicator.<br />
m_SortingColumn.Text = m_SortingColumn.Text.Substring(2)<br />
End If<br />
" Display the new sort order.<br />
m_SortingColumn = new_sorting_column<br />
If sort_order = SortOrder.Ascending Then<br />
m_SortingColumn.Text = "> " & m_SortingColumn.Text<br />
Else<br />
m_SortingColumn.Text = "< " & m_SortingColumn.Text<br />
End If<br />
" Create a comparer.<br />
lvwBooks.ListViewItemSorter = New ListViewComparer(e.Column, sort_order)<br />
" Sort.<br />
lvwBooks.Sort()<br />
End Sub<br />
End Class<br />
" Implements a comparer for ListView columns.<br />
Public Class ListViewComparer<br />
Implements IComparer<br />
Private m_ColumnNumber As Integer<br />
Private m_SortOrder As SortOrder<br />
Public Sub New(ByVal column_number As Integer, ByVal sort_order As SortOrder)<br />
m_ColumnNumber = column_number<br />
m_SortOrder = sort_order<br />
End Sub<br />
" Compare the items in the appropriate column<br />
" for objects x and y.<br />
Public Function Compare(ByVal x As Object, ByVal y As Object) _<br />
As Integer Implements System.Collections.IComparer.rupare<br />
Dim item_x As ListViewItem = DirectCast(x, ListViewItem)<br />
Dim item_y As ListViewItem = DirectCast(y, ListViewItem)<br />
" Get the sub-item values.<br />
Dim string_x As String<br />
If item_x.SubItems.Count <= m_ColumnNumber Then<br />
string_x = ""<br />
Else<br />
string_x = item_x.SubItems(m_ColumnNumber).Text<br />
End If<br />
Dim string_y As String<br />
If item_y.SubItems.Count <= m_ColumnNumber Then<br />
string_y = ""<br />
Else<br />
string_y = item_y.SubItems(m_ColumnNumber).Text<br />
End If<br />
" Compare them.<br />
If m_SortOrder = SortOrder.Ascending Then<br />
Return String.rupare(string_x, string_y)<br />
Else<br />
Return String.rupare(string_y, string_x)<br />
End If<br />
End Function<br />
End Class<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.ruponents = New System.ruponentModel.Container<br />
Me.MenuStrip1 = New System.Windows.Forms.MenuStrip<br />
Me.ViewToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem<br />
Me.mnuViewDetails = New System.Windows.Forms.ToolStripMenuItem<br />
Me.mnuViewLargeIcons = New System.Windows.Forms.ToolStripMenuItem<br />
Me.mnuViewList = New System.Windows.Forms.ToolStripMenuItem<br />
Me.mnuViewSmallIcons = New System.Windows.Forms.ToolStripMenuItem<br />
Me.mnuViewTile = New System.Windows.Forms.ToolStripMenuItem<br />
Me.imlSmall = New System.Windows.Forms.ImageList(Me.ruponents)<br />
Me.lvwBooks = New System.Windows.Forms.ListView<br />
Me.ColumnHeader3 = New System.Windows.Forms.ColumnHeader<br />
Me.ColumnHeader2 = New System.Windows.Forms.ColumnHeader<br />
Me.ColumnHeader1 = New System.Windows.Forms.ColumnHeader<br />
Me.MenuStrip1.SuspendLayout()<br />
Me.SuspendLayout()<br />
"<br />
"MenuStrip1<br />
"<br />
Me.MenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ViewToolStripMenuItem})<br />
Me.MenuStrip1.Location = New System.Drawing.Point(0, 0)<br />
Me.MenuStrip1.Name = "MenuStrip1"<br />
Me.MenuStrip1.Size = New System.Drawing.Size(772, 24)<br />
Me.MenuStrip1.TabIndex = 1<br />
Me.MenuStrip1.Text = "MenuStrip1"<br />
"<br />
"ViewToolStripMenuItem<br />
"<br />
Me.ViewToolStripMenuItem.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.mnuViewDetails, Me.mnuViewLargeIcons, Me.mnuViewList, Me.mnuViewSmallIcons, Me.mnuViewTile})<br />
Me.ViewToolStripMenuItem.Name = "ViewToolStripMenuItem"<br />
Me.ViewToolStripMenuItem.Text = "&View"<br />
"<br />
"mnuViewDetails<br />
"<br />
Me.mnuViewDetails.Name = "mnuViewDetails"<br />
Me.mnuViewDetails.Text = "&Details"<br />
"<br />
"mnuViewLargeIcons<br />
"<br />
Me.mnuViewLargeIcons.Name = "mnuViewLargeIcons"<br />
Me.mnuViewLargeIcons.Text = "Large Icons"<br />
"<br />
"mnuViewList<br />
"<br />
Me.mnuViewList.Name = "mnuViewList"<br />
Me.mnuViewList.Text = "&List"<br />
"<br />
"mnuViewSmallIcons<br />
"<br />
Me.mnuViewSmallIcons.Name = "mnuViewSmallIcons"<br />
Me.mnuViewSmallIcons.Text = "&Small Icons"<br />
"<br />
"mnuViewTile<br />
"<br />
Me.mnuViewTile.Name = "mnuViewTile"<br />
Me.mnuViewTile.Text = "Tile"<br />
"<br />
"lvwBooks<br />
"<br />
Me.lvwBooks.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2, Me.ColumnHeader3})<br />
Me.lvwBooks.Dock = System.Windows.Forms.DockStyle.Fill<br />
Me.lvwBooks.Location = New System.Drawing.Point(0, 24)<br />
Me.lvwBooks.Name = "lvwBooks"<br />
Me.lvwBooks.Size = New System.Drawing.Size(772, 249)<br />
Me.lvwBooks.SmallImageList = Me.imlSmall<br />
Me.lvwBooks.TabIndex = 2<br />
Me.lvwBooks.View = System.Windows.Forms.View.Details<br />
"<br />
"ColumnHeader2<br />
"<br />
Me.ColumnHeader2.Text = "URL"<br />
"<br />
"ColumnHeader1<br />
"<br />
Me.ColumnHeader1.Text = "Title"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(772, 273)<br />
Me.Controls.Add(Me.lvwBooks)<br />
Me.Controls.Add(Me.MenuStrip1)<br />
Me.Name = "Form1"<br />
Me.Text = "ListViewCustomSort"<br />
Me.MenuStrip1.ResumeLayout(False)<br />
Me.ResumeLayout(False)<br />
Me.PerformLayout()<br />
End Sub<br />
Friend WithEvents MenuStrip1 As System.Windows.Forms.MenuStrip<br />
Friend WithEvents ViewToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem<br />
Friend WithEvents mnuViewDetails As System.Windows.Forms.ToolStripMenuItem<br />
Friend WithEvents mnuViewLargeIcons As System.Windows.Forms.ToolStripMenuItem<br />
Friend WithEvents mnuViewList As System.Windows.Forms.ToolStripMenuItem<br />
Friend WithEvents mnuViewSmallIcons As System.Windows.Forms.ToolStripMenuItem<br />
Friend WithEvents mnuViewTile As System.Windows.Forms.ToolStripMenuItem<br />
Friend WithEvents imlSmall As System.Windows.Forms.ImageList<br />
Friend WithEvents lvwBooks As System.Windows.Forms.ListView<br />
Friend WithEvents ColumnHeader3 As System.Windows.Forms.ColumnHeader<br />
Friend WithEvents ColumnHeader2 As System.Windows.Forms.ColumnHeader<br />
Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader<br />
End Class</source><br />
<br />
==Sort a listview==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class ListViewSorting<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<br />
Public Class Form1<br />
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
Dim mycount As Integer<br />
mycount = listview1.Items.Count<br />
ToolStripStatusLabel1.Text = Str(mycount)<br />
End Sub<br />
Private Sub ListView1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.Click<br />
Dim i As Integer<br />
Dim mycount As Integer<br />
mycount = ListView1.Items.Count<br />
For i = 0 To mycount - 1<br />
If ListView1.Items(i).Selected = True Then<br />
ToolStripStatusLabel1.Text = ListView1.Items(i).Text + " selected"<br />
Exit For<br />
End If<br />
Next<br />
End Sub<br />
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged<br />
ListView1.Sorting = SortOrder.Ascending<br />
End Sub<br />
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged<br />
ListView1.Sorting = SortOrder.Descending<br />
End Sub<br />
Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged<br />
ListView1.Sorting = SortOrder.None<br />
End Sub<br />
<br />
End Class<br />
<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.ruponents = New System.ruponentModel.Container<br />
Dim ListViewItem1 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem("Item1", 0)<br />
Dim ListViewItem2 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem("Item2", 1)<br />
Dim ListViewItem3 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem("Item3", 2)<br />
Dim ListViewItem4 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem("Item4", 3)<br />
Dim ListViewItem5 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem("Item5", 4)<br />
Me.ListView1 = New System.Windows.Forms.ListView<br />
Me.RadioButton1 = New System.Windows.Forms.RadioButton<br />
Me.RadioButton2 = New System.Windows.Forms.RadioButton<br />
Me.RadioButton3 = New System.Windows.Forms.RadioButton<br />
Me.StatusStrip1 = New System.Windows.Forms.StatusStrip<br />
Me.ToolStripStatusLabel1 = New System.Windows.Forms.ToolStripStatusLabel<br />
Me.StatusStrip1.SuspendLayout()<br />
Me.SuspendLayout()<br />
"<br />
"ListView1<br />
"<br />
Me.ListView1.Items.AddRange(New System.Windows.Forms.ListViewItem() {ListViewItem1, ListViewItem2, ListViewItem3, ListViewItem4, ListViewItem5})<br />
Me.ListView1.LargeImageList = Me.ImageList1<br />
Me.ListView1.Location = New System.Drawing.Point(16, 15)<br />
Me.ListView1.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4)<br />
Me.ListView1.Name = "ListView1"<br />
Me.ListView1.Size = New System.Drawing.Size(317, 155)<br />
Me.ListView1.TabIndex = 0<br />
Me.ListView1.UseCompatibleStateImageBehavior = False<br />
"<br />
"RadioButton1<br />
"<br />
Me.RadioButton1.AutoSize = True<br />
Me.RadioButton1.Location = New System.Drawing.Point(391, 39)<br />
Me.RadioButton1.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4)<br />
Me.RadioButton1.Name = "RadioButton1"<br />
Me.RadioButton1.Size = New System.Drawing.Size(58, 19)<br />
Me.RadioButton1.TabIndex = 1<br />
Me.RadioButton1.TabStop = True<br />
Me.RadioButton1.Text = "ascending"<br />
Me.RadioButton1.UseVisualStyleBackColor = True<br />
"<br />
"RadioButton2<br />
"<br />
Me.RadioButton2.AutoSize = True<br />
Me.RadioButton2.Location = New System.Drawing.Point(391, 79)<br />
Me.RadioButton2.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4)<br />
Me.RadioButton2.Name = "RadioButton2"<br />
Me.RadioButton2.Size = New System.Drawing.Size(58, 19)<br />
Me.RadioButton2.TabIndex = 2<br />
Me.RadioButton2.TabStop = True<br />
Me.RadioButton2.Text = "descending"<br />
Me.RadioButton2.UseVisualStyleBackColor = True<br />
"<br />
"RadioButton3<br />
"<br />
Me.RadioButton3.AutoSize = True<br />
Me.RadioButton3.Location = New System.Drawing.Point(391, 124)<br />
Me.RadioButton3.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4)<br />
Me.RadioButton3.Name = "RadioButton3"<br />
Me.RadioButton3.Size = New System.Drawing.Size(73, 19)<br />
Me.RadioButton3.TabIndex = 3<br />
Me.RadioButton3.TabStop = True<br />
Me.RadioButton3.Text = "no order"<br />
Me.RadioButton3.UseVisualStyleBackColor = True<br />
"<br />
"StatusStrip1<br />
"<br />
Me.StatusStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ToolStripStatusLabel1})<br />
Me.StatusStrip1.Location = New System.Drawing.Point(0, 212)<br />
Me.StatusStrip1.Name = "StatusStrip1"<br />
Me.StatusStrip1.Padding = New System.Windows.Forms.Padding(1, 0, 19, 0)<br />
Me.StatusStrip1.Size = New System.Drawing.Size(536, 22)<br />
Me.StatusStrip1.TabIndex = 4<br />
Me.StatusStrip1.Text = "StatusStrip1"<br />
"<br />
"ToolStripStatusLabel1<br />
"<br />
Me.ToolStripStatusLabel1.Name = "ToolStripStatusLabel1"<br />
Me.ToolStripStatusLabel1.Size = New System.Drawing.Size(0, 17)<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 15.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(536, 234)<br />
Me.Controls.Add(Me.StatusStrip1)<br />
Me.Controls.Add(Me.RadioButton3)<br />
Me.Controls.Add(Me.RadioButton2)<br />
Me.Controls.Add(Me.RadioButton1)<br />
Me.Controls.Add(Me.ListView1)<br />
Me.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4)<br />
Me.StatusStrip1.ResumeLayout(False)<br />
Me.StatusStrip1.PerformLayout()<br />
Me.ResumeLayout(False)<br />
Me.PerformLayout()<br />
End Sub<br />
Friend WithEvents ListView1 As System.Windows.Forms.ListView<br />
Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton<br />
Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton<br />
Friend WithEvents RadioButton3 As System.Windows.Forms.RadioButton<br />
Friend WithEvents ImageList1 As System.Windows.Forms.ImageList<br />
Friend WithEvents StatusStrip1 As System.Windows.Forms.StatusStrip<br />
Friend WithEvents ToolStripStatusLabel1 As System.Windows.Forms.ToolStripStatusLabel<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/PrintPreview_Dialog&diff=3925
VB.Net Tutorial/GUI/PrintPreview Dialog
2010-05-26T12:57:30Z
<p>Admin: 1 версия</p>
<hr />
<div>==PrintPreview page count==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
Imports System.Drawing<br />
Imports System.Drawing.Printing<br />
public class PrintPreviewPagesOut<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Private currentPageNumber As Integer = 1<br />
Private Sub btnPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPreview.Click<br />
If ppvdlgShapes.ShowDialog() = Windows.Forms.DialogResult.OK Then<br />
ppvdlgShapes.Document.Print()<br />
End If<br />
End Sub<br />
Private Sub pdocShapes_PrintPage(ByVal sender As System.Object, _<br />
ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles pdocShapes.PrintPage<br />
Select Case currentPageNumber<br />
Case 1<br />
e.Graphics.DrawRectangle(Pens.Green, e.MarginBounds())<br />
e.HasMorePages = True<br />
currentPageNumber += 1<br />
Case 2<br />
e.Graphics.DrawRectangle(Pens.Green, e.MarginBounds())<br />
e.HasMorePages = True<br />
currentPageNumber += 1<br />
Case 3<br />
e.Graphics.DrawEllipse(Pens.Blue, e.MarginBounds())<br />
e.HasMorePages = False<br />
currentPageNumber = 1<br />
End Select<br />
End Sub<br />
End Class<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.btnPreview = New System.Windows.Forms.Button<br />
Me.pdocShapes = New System.Drawing.Printing.PrintDocument<br />
Me.ppvdlgShapes = New System.Windows.Forms.PrintPreviewDialog<br />
Me.SuspendLayout()<br />
"<br />
"btnPreview<br />
"<br />
Me.btnPreview.Location = New System.Drawing.Point(112, 48)<br />
Me.btnPreview.Name = "btnPreview"<br />
Me.btnPreview.Size = New System.Drawing.Size(64, 24)<br />
Me.btnPreview.TabIndex = 1<br />
Me.btnPreview.Text = "Preview"<br />
"<br />
"ppvdlgShapes<br />
"<br />
Me.ppvdlgShapes.AutoScrollMargin = New System.Drawing.Size(0, 0)<br />
Me.ppvdlgShapes.AutoScrollMinSize = New System.Drawing.Size(0, 0)<br />
Me.ppvdlgShapes.ClientSize = New System.Drawing.Size(400, 300)<br />
Me.ppvdlgShapes.Document = Me.pdocShapes<br />
Me.ppvdlgShapes.Enabled = True<br />
Me.ppvdlgShapes.Name = "ppvdlgShapes"<br />
Me.ppvdlgShapes.Visible = False<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(292, 142)<br />
Me.Controls.Add(Me.btnPreview)<br />
Me.Name = "Form1"<br />
Me.Text = "UsePrintPreviewDialog"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
Friend WithEvents btnPreview As System.Windows.Forms.Button<br />
Friend WithEvents pdocShapes As System.Drawing.Printing.PrintDocument<br />
Friend WithEvents ppvdlgShapes As System.Windows.Forms.PrintPreviewDialog<br />
End Class</source><br />
<br />
==Print, PrintPreview Dialog and Print Dialog==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
Imports System.Drawing.Printing<br />
public class PrintPreviewDemo<br />
public Shared Sub Main<br />
Application.Run(New MainForm)<br />
End Sub<br />
End class<br />
<br />
Public Class MainForm<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents printButton As System.Windows.Forms.Button<br />
Friend WithEvents previewButton As System.Windows.Forms.Button<br />
Friend WithEvents previewControlButton As System.Windows.Forms.Button<br />
Friend WithEvents pageSetupButton As System.Windows.Forms.Button<br />
Friend WithEvents pageSetupDialog1 As System.Windows.Forms.PageSetupDialog<br />
Friend WithEvents printDialog1 As System.Windows.Forms.PrintDialog<br />
Friend WithEvents printDocument1 As System.Drawing.Printing.PrintDocument<br />
Friend WithEvents printPreviewDialog1 As System.Windows.Forms.PrintPreviewDialog<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.printButton = New System.Windows.Forms.Button()<br />
Me.previewButton = New System.Windows.Forms.Button()<br />
Me.previewControlButton = New System.Windows.Forms.Button()<br />
Me.pageSetupButton = New System.Windows.Forms.Button()<br />
Me.pageSetupDialog1 = New System.Windows.Forms.PageSetupDialog()<br />
Me.printDialog1 = New System.Windows.Forms.PrintDialog()<br />
Me.printDocument1 = New System.Drawing.Printing.PrintDocument()<br />
Me.printPreviewDialog1 = New System.Windows.Forms.PrintPreviewDialog()<br />
Me.SuspendLayout()<br />
"<br />
"printButton<br />
"<br />
Me.printButton.Location = New System.Drawing.Point(24, 16)<br />
Me.printButton.Name = "printButton"<br />
Me.printButton.Size = New System.Drawing.Size(112, 23)<br />
Me.printButton.TabIndex = 3<br />
Me.printButton.Text = "Print"<br />
"<br />
"previewButton<br />
"<br />
Me.previewButton.Location = New System.Drawing.Point(24, 80)<br />
Me.previewButton.Name = "previewButton"<br />
Me.previewButton.Size = New System.Drawing.Size(112, 23)<br />
Me.previewButton.TabIndex = 6<br />
Me.previewButton.Text = "Preview Dialog"<br />
"<br />
"previewControlButton<br />
"<br />
Me.previewControlButton.Location = New System.Drawing.Point(24, 48)<br />
Me.previewControlButton.Name = "previewControlButton"<br />
Me.previewControlButton.Size = New System.Drawing.Size(112, 23)<br />
Me.previewControlButton.TabIndex = 4<br />
Me.previewControlButton.Text = "Preview Control"<br />
"<br />
"pageSetupButton<br />
"<br />
Me.pageSetupButton.Location = New System.Drawing.Point(24, 112)<br />
Me.pageSetupButton.Name = "pageSetupButton"<br />
Me.pageSetupButton.Size = New System.Drawing.Size(112, 23)<br />
Me.pageSetupButton.TabIndex = 5<br />
Me.pageSetupButton.Text = "Page Setup"<br />
"<br />
"pageSetupDialog1<br />
"<br />
Me.pageSetupDialog1.MinMargins = New System.Drawing.Printing.Margins(50, 50, 50, 50)<br />
Me.pageSetupDialog1.ShowHelp = True<br />
"<br />
"printDialog1<br />
"<br />
Me.printDialog1.Document = Me.printDocument1<br />
"<br />
"printDocument1<br />
"<br />
"<br />
"printPreviewDialog1<br />
"<br />
Me.printPreviewDialog1.AutoScrollMargin = New System.Drawing.Size(0, 0)<br />
Me.printPreviewDialog1.AutoScrollMinSize = New System.Drawing.Size(0, 0)<br />
Me.printPreviewDialog1.ClientSize = New System.Drawing.Size(400, 300)<br />
Me.printPreviewDialog1.Enabled = True<br />
Me.printPreviewDialog1.Location = New System.Drawing.Point(44, 58)<br />
Me.printPreviewDialog1.MaximumSize = New System.Drawing.Size(0, 0)<br />
Me.printPreviewDialog1.Name = "printPreviewDialog1"<br />
Me.printPreviewDialog1.Opacity = 1<br />
Me.printPreviewDialog1.TransparencyKey = System.Drawing.Color.Empty<br />
Me.printPreviewDialog1.Visible = False<br />
"<br />
"MainForm<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(160, 150)<br />
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.printButton, Me.previewButton, Me.previewControlButton, Me.pageSetupButton})<br />
Me.Name = "MainForm"<br />
Me.Text = "MainForm"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Dim totalPages As Integer = 13<br />
Dim page As Integer<br />
Dim maxPage As Integer<br />
Dim myFont As Font = Nothing<br />
Private Sub printButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles printButton.Click<br />
printDocument1.DocumentName = "myFile.txt"<br />
printDocument1.PrinterSettings.FromPage = 1<br />
printDocument1.PrinterSettings.ToPage = totalPages<br />
printDocument1.PrinterSettings.MinimumPage = 1<br />
printDocument1.PrinterSettings.MaximumPage = totalPages<br />
printDialog1.AllowSomePages = True<br />
If printDialog1.ShowDialog() = DialogResult.OK Then<br />
If printDialog1.PrinterSettings.PrintRange = Drawing.Printing.PrintRange.SomePages Then<br />
page = printDocument1.PrinterSettings.FromPage<br />
maxPage = printDocument1.PrinterSettings.ToPage<br />
Else<br />
page = 1<br />
maxPage = totalPages<br />
End If<br />
End If<br />
printDocument1.Print()<br />
End Sub<br />
Sub printDocument1_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Handles printDocument1.PrintPage<br />
Dim g As Graphics = e.Graphics<br />
g.DrawString("Hello, " & vbCrLf & "Printer" & vbCrLf & "Page: " & page, myFont, Brushes.Black, RectangleF.op_Implicit(e.MarginBounds))<br />
page = page + 1<br />
e.HasMorePages = (page <= maxPage)<br />
End Sub<br />
<br />
Private Sub previewControlButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles previewControlButton.Click<br />
page = 1<br />
maxPage = totalPages<br />
printPreviewDialog1.Document = printDocument1<br />
printPreviewDialog1.ShowDialog()<br />
End Sub<br />
Private Sub previewButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles previewButton.Click<br />
page = 1<br />
maxPage = totalPages<br />
Dim dlg As CustomPrintPreviewDialog = New CustomPrintPreviewDialog()<br />
dlg.Document = printDocument1<br />
dlg.ShowDialog()<br />
End Sub<br />
Private Sub pageSetupButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pageSetupButton.Click<br />
pageSetupDialog1.Document = printDocument1<br />
pageSetupDialog1.ShowDialog()<br />
End Sub<br />
Private Sub printDocument1_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles printDocument1.BeginPrint<br />
myFont = New Font("Lucide Console", 72)<br />
End Sub<br />
Private Sub printDocument1_EndPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles printDocument1.EndPrint<br />
myFont.Dispose()<br />
myFont = Nothing<br />
End Sub<br />
End Class<br />
<br />
<br />
Public Class CustomPrintPreviewDialog<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents printPreviewControl1 As System.Windows.Forms.PrintPreviewControl<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.printPreviewControl1 = New System.Windows.Forms.PrintPreviewControl()<br />
Me.SuspendLayout()<br />
"<br />
"printPreviewControl1<br />
"<br />
Me.printPreviewControl1.AutoZoom = False<br />
Me.printPreviewControl1.Dock = System.Windows.Forms.DockStyle.Fill<br />
Me.printPreviewControl1.Name = "printPreviewControl1"<br />
Me.printPreviewControl1.Size = New System.Drawing.Size(376, 398)<br />
Me.printPreviewControl1.TabIndex = 1<br />
Me.printPreviewControl1.UseAntiAlias = True<br />
Me.printPreviewControl1.Zoom = 0.30000001192092896<br />
"<br />
"CustomPrintPreviewDialog<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(376, 398)<br />
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.printPreviewControl1})<br />
Me.Name = "CustomPrintPreviewDialog"<br />
Me.Text = "CustomPrintPreviewDialog"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub printPreviewControl1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles printPreviewControl1.Click<br />
If (Control.ModifierKeys And Keys.Shift) = 0 Then<br />
printPreviewControl1.Zoom = printPreviewControl1.Zoom * 2.0<br />
Else<br />
printPreviewControl1.Zoom = printPreviewControl1.Zoom / 2.0<br />
End If<br />
End Sub<br />
Public Property Document() As PrintDocument<br />
Get<br />
Return printPreviewControl1.Document<br />
End Get<br />
Set(ByVal Value As PrintDocument)<br />
printPreviewControl1.Document = Value<br />
End Set<br />
End Property<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/AnchorStyles&diff=3921
VB.Net Tutorial/GUI/AnchorStyles
2010-05-26T12:57:29Z
<p>Admin: 1 версия</p>
<hr />
<div>==AnchorStyles.Bottom Or AnchorStyles.Left==<br />
<br />
<br />
<br />
<source lang="vbnet">imports System<br />
imports System.Drawing<br />
imports System.Windows.Forms<br />
public class ControlAnchorBottomLeft : inherits Form<br />
public sub New()<br />
Size = new Size(350,400)<br />
dim xButtonSize as integer = 120<br />
dim xMargin, yMargin as integer<br />
xMargin = Font.Height * 2<br />
yMargin = Font.Height * 2<br />
dim btn as new Button()<br />
btn.Parent = me<br />
btn.Text = "Upper Left"<br />
<br />
btn.Size = new Size(xButtonSize, 26)<br />
btn.Location = new Point(xMargin, yMargin)<br />
btn = new Button()<br />
btn.Parent = me<br />
btn.Text = "Lower Left"<br />
btn.Size = new Size(xButtonSize, 26)<br />
btn.Location = new Point(xMargin, me.ClientSize.Height - yMargin - 26)<br />
btn.Anchor = AnchorStyles.Bottom Or AnchorStyles.Left<br />
end sub<br />
public shared sub Main() <br />
Application.Run(new ControlAnchorBottomLeft())<br />
end sub<br />
end class</source><br />
<br />
==AnchorStyles.Bottom Or AnchorStyles.Right==<br />
<br />
<br />
<br />
<source lang="vbnet">imports System<br />
imports System.Drawing<br />
imports System.Windows.Forms<br />
public class ControlAnchorBottomRight : inherits Form<br />
public sub New()<br />
Size = new Size(350,400)<br />
dim xButtonSize as integer = 120<br />
dim xMargin, yMargin as integer<br />
xMargin = Font.Height * 2<br />
yMargin = Font.Height * 2<br />
dim btn as new Button()<br />
btn.Parent = me<br />
btn.Text = "Upper Left"<br />
<br />
btn.Size = new Size(xButtonSize, 26)<br />
btn.Location = new Point(xMargin, yMargin)<br />
btn = new Button()<br />
btn.Parent = me<br />
btn.Text = "Lower Right"<br />
btn.Size = new Size(xButtonSize, 26)<br />
btn.Location = new Point(me.ClientSize.Width - xMargin - xButtonSize, me.ClientSize.Height - yMargin - 26)<br />
btn.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right<br />
end sub<br />
public shared sub Main() <br />
Application.Run(new ControlAnchorBottomRight())<br />
end sub<br />
end class</source><br />
<br />
==AnchorStyles.Left Or AnchorStyles.Right==<br />
<br />
<br />
<br />
<source lang="vbnet">imports System<br />
imports System.Drawing<br />
imports System.Windows.Forms<br />
public class ControlAnchorLeftRight : inherits Form<br />
public sub New()<br />
Size = new Size(350,400)<br />
dim xButtonSize as integer = 120<br />
dim xMargin, yMargin as integer<br />
xMargin = Font.Height * 2<br />
yMargin = Font.Height * 2<br />
dim btn as new Button()<br />
btn.Parent = me<br />
btn.Text = "Upper Left"<br />
<br />
btn.Size = new Size(xButtonSize, 26)<br />
btn.Location = new Point(xMargin, yMargin)<br />
btn = new Button()<br />
btn.Parent = me<br />
btn.Text = "Middle Span"<br />
btn.Size = new Size(xButtonSize, 26)<br />
btn.Location = new Point(xMargin,Cint(me.ClientSize.Height / 2) - 26)<br />
btn.Anchor = AnchorStyles.Left Or AnchorStyles.Right<br />
end sub<br />
public shared sub Main() <br />
Application.Run(new ControlAnchorLeftRight())<br />
end sub<br />
end class</source><br />
<br />
==AnchorStyles.Top Or AnchorStyles.Right==<br />
<br />
<br />
<br />
<source lang="vbnet">imports System<br />
imports System.Drawing<br />
imports System.Windows.Forms<br />
public class ControlAnchorTopRight : inherits Form<br />
public sub New()<br />
Size = new Size(350,400)<br />
dim xButtonSize as integer = 120<br />
dim xMargin, yMargin as integer<br />
xMargin = Font.Height * 2<br />
yMargin = Font.Height * 2<br />
dim btn as new Button()<br />
btn.Parent = me<br />
btn.Text = "Upper Left"<br />
<br />
btn.Size = new Size(xButtonSize, 26)<br />
btn.Location = new Point(xMargin, yMargin)<br />
btn = new Button()<br />
btn.Parent = me<br />
btn.Text = "Upper Right"<br />
btn.Size = new Size(xButtonSize, 26)<br />
btn.Location = new Point(me.ClientSize.Width - xMargin - xButtonSize, yMargin)<br />
btn.Anchor = AnchorStyles.Top Or AnchorStyles.Right<br />
end sub<br />
public shared sub Main() <br />
Application.Run(new ControlAnchorTopRight())<br />
end sub<br />
end class</source><br />
<br />
==Get Control Anchoring Information==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class GetControlAnchoringInformation<br />
public Shared Sub Main<br />
Application.Run(New Anchoring)<br />
End Sub<br />
End class<br />
Public Class Anchoring<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
For Each ctrl As Control In Me.Controls<br />
Dim anchorText As New System.Text.StringBuilder<br />
If ctrl.Anchor And AnchorStyles.Top Then<br />
anchorText.Append("Top")<br />
End If<br />
If ctrl.Anchor And AnchorStyles.Left Then<br />
If anchorText.Length <> 0 Then<br />
anchorText.Append(", ")<br />
End If<br />
anchorText.Append("Left")<br />
End If<br />
If ctrl.Anchor And AnchorStyles.Bottom Then<br />
If anchorText.Length <> 0 Then<br />
anchorText.Append(", ")<br />
End If<br />
anchorText.Append("Bottom")<br />
End If<br />
If ctrl.Anchor And AnchorStyles.Right Then<br />
If anchorText.Length <> 0 Then<br />
anchorText.Append(", ")<br />
End If<br />
anchorText.Append("Right")<br />
End If<br />
ctrl.Text = anchorText.ToString()<br />
Next<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox<br />
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents TextBox4 As System.Windows.Forms.TextBox<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.TextBox2 = New System.Windows.Forms.TextBox<br />
Me.TextBox3 = New System.Windows.Forms.TextBox<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.TextBox4 = New System.Windows.Forms.TextBox<br />
Me.SuspendLayout()<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _<br />
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)<br />
Me.TextBox1.Location = New System.Drawing.Point(16, 16)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(248, 20)<br />
Me.TextBox1.TabIndex = 0<br />
Me.TextBox1.Text = "Anchored to Top, Left, Right"<br />
"<br />
"TextBox2<br />
"<br />
Me.TextBox2.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _<br />
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)<br />
Me.TextBox2.Location = New System.Drawing.Point(16, 72)<br />
Me.TextBox2.Name = "TextBox2"<br />
Me.TextBox2.Size = New System.Drawing.Size(248, 20)<br />
Me.TextBox2.TabIndex = 1<br />
Me.TextBox2.Text = "Anchored to Top, Left, Right"<br />
"<br />
"TextBox3<br />
"<br />
Me.TextBox3.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _<br />
Or System.Windows.Forms.AnchorStyles.Left) _<br />
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)<br />
Me.TextBox3.Location = New System.Drawing.Point(16, 96)<br />
Me.TextBox3.Multiline = True<br />
Me.TextBox3.Name = "TextBox3"<br />
Me.TextBox3.Size = New System.Drawing.Size(248, 136)<br />
Me.TextBox3.TabIndex = 2<br />
Me.TextBox3.Text = "Anchored to Top, Bottom, Left, Right"<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)<br />
Me.Button1.Location = New System.Drawing.Point(168, 240)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.Size = New System.Drawing.Size(96, 23)<br />
Me.Button1.TabIndex = 3<br />
Me.Button1.Text = "bottom,right"<br />
"<br />
"TextBox4<br />
"<br />
Me.TextBox4.Location = New System.Drawing.Point(16, 44)<br />
Me.TextBox4.Name = "TextBox4"<br />
Me.TextBox4.Size = New System.Drawing.Size(248, 20)<br />
Me.TextBox4.TabIndex = 4<br />
Me.TextBox4.Text = "Anchored to Top, Left (default)"<br />
"<br />
"Anchoring<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(280, 270)<br />
Me.Controls.Add(Me.TextBox4)<br />
Me.Controls.Add(Me.Button1)<br />
Me.Controls.Add(Me.TextBox3)<br />
Me.Controls.Add(Me.TextBox2)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.Name = "Anchoring"<br />
Me.Text = "Anchoring"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/MessageBox&diff=3919
VB.Net Tutorial/GUI/MessageBox
2010-05-26T12:57:28Z
<p>Admin: 1 версия</p>
<hr />
<div>==Create MessageBox dynamically==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class MessageBoxCreateDy<br />
public Shared Sub Main<br />
Application.Run(New frmMessageBox)<br />
End Sub<br />
End class<br />
Public Class frmMessageBox<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
Friend WithEvents grpPromptandTitle As System.Windows.Forms.GroupBox<br />
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox<br />
Friend WithEvents btnShow As System.Windows.Forms.Button<br />
Friend WithEvents Panel1 As System.Windows.Forms.Panel<br />
Friend WithEvents Splitter1 As System.Windows.Forms.Splitter<br />
Friend WithEvents Panel2 As System.Windows.Forms.Panel<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
Friend WithEvents txtText As System.Windows.Forms.TextBox<br />
Friend WithEvents txtCaption As System.Windows.Forms.TextBox<br />
Friend WithEvents Label2 As System.Windows.Forms.Label<br />
Friend WithEvents rdoOKOnly As System.Windows.Forms.RadioButton<br />
Friend WithEvents Label3 As System.Windows.Forms.Label<br />
Friend WithEvents rdoAbRetry As System.Windows.Forms.RadioButton<br />
Friend WithEvents rdoError As System.Windows.Forms.RadioButton<br />
Friend WithEvents rdoExclamation As System.Windows.Forms.RadioButton<br />
Friend WithEvents rdoRetryCancel As System.Windows.Forms.RadioButton<br />
Friend WithEvents rdoInformation As System.Windows.Forms.RadioButton<br />
Friend WithEvents rdoYesNo As System.Windows.Forms.RadioButton<br />
Friend WithEvents rdoYesNoCancel As System.Windows.Forms.RadioButton<br />
Friend WithEvents rdoOKCancel As System.Windows.Forms.RadioButton<br />
Friend WithEvents Label4 As System.Windows.Forms.Label<br />
Friend WithEvents rdoNoIcon As System.Windows.Forms.RadioButton<br />
Friend WithEvents rdoQuestion As System.Windows.Forms.RadioButton<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.grpPromptandTitle = New System.Windows.Forms.GroupBox()<br />
Me.GroupBox1 = New System.Windows.Forms.GroupBox()<br />
Me.btnShow = New System.Windows.Forms.Button()<br />
Me.Panel1 = New System.Windows.Forms.Panel()<br />
Me.Splitter1 = New System.Windows.Forms.Splitter()<br />
Me.Panel2 = New System.Windows.Forms.Panel()<br />
Me.Label1 = New System.Windows.Forms.Label()<br />
Me.txtText = New System.Windows.Forms.TextBox()<br />
Me.txtCaption = New System.Windows.Forms.TextBox()<br />
Me.Label2 = New System.Windows.Forms.Label()<br />
Me.rdoOKOnly = New System.Windows.Forms.RadioButton()<br />
Me.Label3 = New System.Windows.Forms.Label()<br />
Me.rdoAbRetry = New System.Windows.Forms.RadioButton()<br />
Me.rdoError = New System.Windows.Forms.RadioButton()<br />
Me.rdoExclamation = New System.Windows.Forms.RadioButton()<br />
Me.rdoRetryCancel = New System.Windows.Forms.RadioButton()<br />
Me.rdoInformation = New System.Windows.Forms.RadioButton()<br />
Me.rdoYesNo = New System.Windows.Forms.RadioButton()<br />
Me.rdoYesNoCancel = New System.Windows.Forms.RadioButton()<br />
Me.rdoOKCancel = New System.Windows.Forms.RadioButton()<br />
Me.Label4 = New System.Windows.Forms.Label()<br />
Me.rdoNoIcon = New System.Windows.Forms.RadioButton()<br />
Me.rdoQuestion = New System.Windows.Forms.RadioButton()<br />
Me.grpPromptandTitle.SuspendLayout()<br />
Me.GroupBox1.SuspendLayout()<br />
Me.Panel1.SuspendLayout()<br />
Me.Panel2.SuspendLayout()<br />
Me.SuspendLayout()<br />
"<br />
"grpPromptandTitle<br />
"<br />
Me.grpPromptandTitle.Controls.AddRange(New System.Windows.Forms.Control() {Me.txtCaption, Me.Label2, Me.txtText, Me.Label1})<br />
Me.grpPromptandTitle.Dock = System.Windows.Forms.DockStyle.Top<br />
Me.grpPromptandTitle.Name = "grpPromptandTitle"<br />
Me.grpPromptandTitle.Size = New System.Drawing.Size(456, 112)<br />
Me.grpPromptandTitle.TabIndex = 0<br />
Me.grpPromptandTitle.TabStop = False<br />
Me.grpPromptandTitle.Text = "Enter your text and caption:"<br />
"<br />
"GroupBox1<br />
"<br />
Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnShow})<br />
Me.GroupBox1.Dock = System.Windows.Forms.DockStyle.Bottom<br />
Me.GroupBox1.Location = New System.Drawing.Point(0, 350)<br />
Me.GroupBox1.Name = "GroupBox1"<br />
Me.GroupBox1.Size = New System.Drawing.Size(456, 48)<br />
Me.GroupBox1.TabIndex = 3<br />
Me.GroupBox1.TabStop = False<br />
"<br />
"btnShow<br />
"<br />
Me.btnShow.Location = New System.Drawing.Point(328, 16)<br />
Me.btnShow.Name = "btnShow"<br />
Me.btnShow.Size = New System.Drawing.Size(96, 24)<br />
Me.btnShow.TabIndex = 0<br />
Me.btnShow.Text = "SHOW"<br />
"<br />
"Panel1<br />
"<br />
Me.Panel1.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label3, Me.rdoRetryCancel, Me.rdoYesNo, Me.rdoYesNoCancel, Me.rdoAbRetry, Me.rdoOKCancel, Me.rdoOKOnly})<br />
Me.Panel1.Dock = System.Windows.Forms.DockStyle.Left<br />
Me.Panel1.Location = New System.Drawing.Point(0, 112)<br />
Me.Panel1.Name = "Panel1"<br />
Me.Panel1.Size = New System.Drawing.Size(200, 238)<br />
Me.Panel1.TabIndex = 1<br />
"<br />
"Splitter1<br />
"<br />
Me.Splitter1.Location = New System.Drawing.Point(200, 112)<br />
Me.Splitter1.Name = "Splitter1"<br />
Me.Splitter1.Size = New System.Drawing.Size(3, 238)<br />
Me.Splitter1.TabIndex = 3<br />
Me.Splitter1.TabStop = False<br />
"<br />
"Panel2<br />
"<br />
Me.Panel2.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label4, Me.rdoExclamation, Me.rdoNoIcon, Me.rdoInformation, Me.rdoQuestion, Me.rdoError})<br />
Me.Panel2.Dock = System.Windows.Forms.DockStyle.Fill<br />
Me.Panel2.Location = New System.Drawing.Point(203, 112)<br />
Me.Panel2.Name = "Panel2"<br />
Me.Panel2.Size = New System.Drawing.Size(253, 238)<br />
Me.Panel2.TabIndex = 2<br />
"<br />
"Label1<br />
"<br />
Me.Label1.Location = New System.Drawing.Point(16, 24)<br />
Me.Label1.Name = "Label1"<br />
Me.Label1.Size = New System.Drawing.Size(64, 24)<br />
Me.Label1.TabIndex = 0<br />
Me.Label1.Text = "Text:"<br />
"<br />
"txtText<br />
"<br />
Me.txtText.Location = New System.Drawing.Point(104, 24)<br />
Me.txtText.Name = "txtText"<br />
Me.txtText.Size = New System.Drawing.Size(320, 20)<br />
Me.txtText.TabIndex = 0<br />
Me.txtText.Text = ""<br />
"<br />
"txtCaption<br />
"<br />
Me.txtCaption.Location = New System.Drawing.Point(104, 64)<br />
Me.txtCaption.Name = "txtCaption"<br />
Me.txtCaption.Size = New System.Drawing.Size(320, 20)<br />
Me.txtCaption.TabIndex = 1<br />
Me.txtCaption.Text = ""<br />
"<br />
"Label2<br />
"<br />
Me.Label2.Location = New System.Drawing.Point(16, 64)<br />
Me.Label2.Name = "Label2"<br />
Me.Label2.Size = New System.Drawing.Size(64, 24)<br />
Me.Label2.TabIndex = 0<br />
Me.Label2.Text = "Caption:"<br />
"<br />
"rdoOKOnly<br />
"<br />
Me.rdoOKOnly.Checked = True<br />
Me.rdoOKOnly.Location = New System.Drawing.Point(8, 40)<br />
Me.rdoOKOnly.Name = "rdoOKOnly"<br />
Me.rdoOKOnly.Size = New System.Drawing.Size(160, 24)<br />
Me.rdoOKOnly.TabIndex = 2<br />
Me.rdoOKOnly.TabStop = True<br />
Me.rdoOKOnly.Text = "Ok Only"<br />
"<br />
"Label3<br />
"<br />
Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.Label3.Location = New System.Drawing.Point(24, 8)<br />
Me.Label3.Name = "Label3"<br />
Me.Label3.Size = New System.Drawing.Size(104, 24)<br />
Me.Label3.TabIndex = 0<br />
Me.Label3.Text = "Buttons"<br />
"<br />
"rdoAbRetry<br />
"<br />
Me.rdoAbRetry.Location = New System.Drawing.Point(8, 104)<br />
Me.rdoAbRetry.Name = "rdoAbRetry"<br />
Me.rdoAbRetry.Size = New System.Drawing.Size(160, 24)<br />
Me.rdoAbRetry.TabIndex = 4<br />
Me.rdoAbRetry.Text = "Abort, Retry, Ignore"<br />
"<br />
"rdoError<br />
"<br />
Me.rdoError.Checked = True<br />
Me.rdoError.Location = New System.Drawing.Point(24, 40)<br />
Me.rdoError.Name = "rdoError"<br />
Me.rdoError.Size = New System.Drawing.Size(88, 32)<br />
Me.rdoError.TabIndex = 1<br />
Me.rdoError.TabStop = True<br />
Me.rdoError.Text = "Error"<br />
"<br />
"rdoExclamation<br />
"<br />
Me.rdoExclamation.Location = New System.Drawing.Point(24, 112)<br />
Me.rdoExclamation.Name = "rdoExclamation"<br />
Me.rdoExclamation.Size = New System.Drawing.Size(88, 32)<br />
Me.rdoExclamation.TabIndex = 3<br />
Me.rdoExclamation.Text = "Exclamation"<br />
"<br />
"rdoRetryCancel<br />
"<br />
Me.rdoRetryCancel.Location = New System.Drawing.Point(8, 200)<br />
Me.rdoRetryCancel.Name = "rdoRetryCancel"<br />
Me.rdoRetryCancel.Size = New System.Drawing.Size(160, 24)<br />
Me.rdoRetryCancel.TabIndex = 0<br />
Me.rdoRetryCancel.Text = "Retry and Cancel"<br />
"<br />
"rdoInformation<br />
"<br />
Me.rdoInformation.Location = New System.Drawing.Point(136, 40)<br />
Me.rdoInformation.Name = "rdoInformation"<br />
Me.rdoInformation.Size = New System.Drawing.Size(88, 32)<br />
Me.rdoInformation.TabIndex = 4<br />
Me.rdoInformation.Text = "Information"<br />
"<br />
"rdoYesNo<br />
"<br />
Me.rdoYesNo.Location = New System.Drawing.Point(8, 168)<br />
Me.rdoYesNo.Name = "rdoYesNo"<br />
Me.rdoYesNo.Size = New System.Drawing.Size(160, 24)<br />
Me.rdoYesNo.TabIndex = 6<br />
Me.rdoYesNo.Text = "Yes and No"<br />
"<br />
"rdoYesNoCancel<br />
"<br />
Me.rdoYesNoCancel.Location = New System.Drawing.Point(8, 136)<br />
Me.rdoYesNoCancel.Name = "rdoYesNoCancel"<br />
Me.rdoYesNoCancel.Size = New System.Drawing.Size(160, 24)<br />
Me.rdoYesNoCancel.TabIndex = 5<br />
Me.rdoYesNoCancel.Text = "Yes, No, Cancel"<br />
"<br />
"rdoOKCancel<br />
"<br />
Me.rdoOKCancel.Location = New System.Drawing.Point(8, 72)<br />
Me.rdoOKCancel.Name = "rdoOKCancel"<br />
Me.rdoOKCancel.Size = New System.Drawing.Size(160, 24)<br />
Me.rdoOKCancel.TabIndex = 3<br />
Me.rdoOKCancel.Text = "Ok and Cancel"<br />
"<br />
"Label4<br />
"<br />
Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.Label4.Location = New System.Drawing.Point(24, 8)<br />
Me.Label4.Name = "Label4"<br />
Me.Label4.Size = New System.Drawing.Size(80, 24)<br />
Me.Label4.TabIndex = 0<br />
Me.Label4.Text = "Icon"<br />
"<br />
"rdoNoIcon<br />
"<br />
Me.rdoNoIcon.Location = New System.Drawing.Point(136, 80)<br />
Me.rdoNoIcon.Name = "rdoNoIcon"<br />
Me.rdoNoIcon.Size = New System.Drawing.Size(88, 32)<br />
Me.rdoNoIcon.TabIndex = 5<br />
Me.rdoNoIcon.Text = "No Icon"<br />
"<br />
"rdoQuestion<br />
"<br />
Me.rdoQuestion.Location = New System.Drawing.Point(24, 80)<br />
Me.rdoQuestion.Name = "rdoQuestion"<br />
Me.rdoQuestion.Size = New System.Drawing.Size(88, 32)<br />
Me.rdoQuestion.TabIndex = 2<br />
Me.rdoQuestion.Text = "Question"<br />
"<br />
"frmMessageBox<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(456, 398)<br />
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Panel2, Me.Splitter1, Me.Panel1, Me.GroupBox1, Me.grpPromptandTitle})<br />
Me.Name = "frmMessageBox"<br />
Me.Text = "Do the Message Box thing!"<br />
Me.grpPromptandTitle.ResumeLayout(False)<br />
Me.GroupBox1.ResumeLayout(False)<br />
Me.Panel1.ResumeLayout(False)<br />
Me.Panel2.ResumeLayout(False)<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
<br />
Private Sub btnShow_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnShow.Click<br />
Dim buttonchoice As MessageBoxButtons<br />
Dim iconchoice As MessageBoxIcon<br />
Dim answer As DialogResult<br />
If rdoOKOnly.Checked = True Then<br />
buttonchoice = MessageBoxButtons.OK <br />
ElseIf rdoOKCancel.Checked = True Then<br />
buttonchoice = MessageBoxButtons.OKCancel <br />
ElseIf rdoAbRetry.Checked = True Then<br />
buttonchoice = MessageBoxButtons.AbortRetryIgnore<br />
ElseIf rdoYesNoCancel.Checked = True Then<br />
buttonchoice = MessageBoxButtons.YesNoCancel <br />
ElseIf rdoYesNo.Checked = True Then<br />
buttonchoice = MessageBoxButtons.YesNo <br />
ElseIf rdoRetryCancel.Checked = True Then<br />
buttonchoice = MessageBoxButtons.RetryCancel <br />
Else<br />
MessageBox.Show("Unexpected error in button selection!")<br />
End If<br />
If rdoError.Checked = True Then<br />
iconchoice = MessageBoxIcon.Error <br />
ElseIf rdoQuestion.Checked = True Then<br />
iconchoice = MessageBoxIcon.Question<br />
ElseIf rdoExclamation.Checked = True Then<br />
iconchoice = MessageBoxIcon.Exclamation <br />
ElseIf rdoInformation.Checked = True Then<br />
iconchoice = MessageBoxIcon.Information <br />
ElseIf rdoNoIcon.Checked = True Then<br />
iconchoice = MessageBoxIcon.None<br />
Else<br />
MessageBox.Show("Unexpected error in icon selection!")<br />
End If<br />
answer = MessageBox.Show(txtText.Text, txtCaption.Text, _<br />
buttonchoice, iconchoice)<br />
Dim evaluate As String<br />
If answer = DialogResult.OK Then<br />
evaluate = "You clicked OK!"<br />
ElseIf answer = DialogResult.Cancel Then<br />
evaluate = "You clicked Cancel!"<br />
ElseIf answer = DialogResult.Abort Then<br />
evaluate = "You clicked Abort!"<br />
ElseIf answer = DialogResult.Retry Then<br />
evaluate = "You clicked Retry!"<br />
ElseIf answer = DialogResult.Ignore Then<br />
evaluate = "You clicked Ignore!"<br />
ElseIf answer = DialogResult.Yes Then<br />
evaluate = "You clicked Yes!"<br />
ElseIf answer = DialogResult.No Then<br />
evaluate = "You clicked No!"<br />
Else<br />
evaluate = "Nothing was clicked!"<br />
End If<br />
MessageBox.Show(evaluate, "Message Box Evaluation", _<br />
MessageBoxButtons.OK, MessageBoxIcon.Information)<br />
End Sub<br />
End Class</source><br />
<br />
==Custom your MessageBox==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.IO<br />
Imports System.Text.Encoding<br />
Imports System.Drawing<br />
Imports System.Drawing.Printing<br />
Imports System.Windows.Forms<br />
public class CustomMessageBox<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
Public Sub New()<br />
MyBase.New()<br />
InitializeComponent()<br />
End Sub<br />
Private components As System.ruponentModel.IContainer<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
Friend WithEvents btnShow As System.Windows.Forms.Button<br />
Friend WithEvents txtMsg As System.Windows.Forms.TextBox<br />
Friend WithEvents txtCaption As System.Windows.Forms.TextBox<br />
Friend WithEvents Label2 As System.Windows.Forms.Label<br />
Friend WithEvents grpDefaultButton As System.Windows.Forms.GroupBox<br />
Friend WithEvents DefaultButton3 As System.Windows.Forms.RadioButton<br />
Friend WithEvents DefaultButton2 As System.Windows.Forms.RadioButton<br />
Friend WithEvents DefaultButton1 As System.Windows.Forms.RadioButton<br />
Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox<br />
Friend WithEvents Button6 As System.Windows.Forms.RadioButton<br />
Friend WithEvents Button5 As System.Windows.Forms.RadioButton<br />
Friend WithEvents Button4 As System.Windows.Forms.RadioButton<br />
Friend WithEvents Button3 As System.Windows.Forms.RadioButton<br />
Friend WithEvents Button2 As System.Windows.Forms.RadioButton<br />
Friend WithEvents Button1 As System.Windows.Forms.RadioButton<br />
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox<br />
Friend WithEvents txtResult As System.Windows.Forms.TextBox<br />
Friend WithEvents lblResult As System.Windows.Forms.Label<br />
Friend WithEvents Icon8 As System.Windows.Forms.RadioButton<br />
Friend WithEvents Icon7 As System.Windows.Forms.RadioButton<br />
Friend WithEvents Icon6 As System.Windows.Forms.RadioButton<br />
Friend WithEvents Icon5 As System.Windows.Forms.RadioButton<br />
Friend WithEvents Icon4 As System.Windows.Forms.RadioButton<br />
Friend WithEvents Icon3 As System.Windows.Forms.RadioButton<br />
Friend WithEvents Icon2 As System.Windows.Forms.RadioButton<br />
Friend WithEvents Icon1 As System.Windows.Forms.RadioButton<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.txtMsg = New System.Windows.Forms.TextBox()<br />
Me.Label1 = New System.Windows.Forms.Label()<br />
Me.btnShow = New System.Windows.Forms.Button()<br />
Me.txtCaption = New System.Windows.Forms.TextBox()<br />
Me.Label2 = New System.Windows.Forms.Label()<br />
Me.grpDefaultButton = New System.Windows.Forms.GroupBox()<br />
Me.DefaultButton3 = New System.Windows.Forms.RadioButton()<br />
Me.DefaultButton2 = New System.Windows.Forms.RadioButton()<br />
Me.DefaultButton1 = New System.Windows.Forms.RadioButton()<br />
Me.GroupBox2 = New System.Windows.Forms.GroupBox()<br />
Me.Button6 = New System.Windows.Forms.RadioButton()<br />
Me.Button5 = New System.Windows.Forms.RadioButton()<br />
Me.Button4 = New System.Windows.Forms.RadioButton()<br />
Me.Button3 = New System.Windows.Forms.RadioButton()<br />
Me.Button2 = New System.Windows.Forms.RadioButton()<br />
Me.Button1 = New System.Windows.Forms.RadioButton()<br />
Me.GroupBox1 = New System.Windows.Forms.GroupBox()<br />
Me.Icon8 = New System.Windows.Forms.RadioButton()<br />
Me.Icon7 = New System.Windows.Forms.RadioButton()<br />
Me.Icon6 = New System.Windows.Forms.RadioButton()<br />
Me.Icon5 = New System.Windows.Forms.RadioButton()<br />
Me.Icon4 = New System.Windows.Forms.RadioButton()<br />
Me.Icon3 = New System.Windows.Forms.RadioButton()<br />
Me.Icon2 = New System.Windows.Forms.RadioButton()<br />
Me.Icon1 = New System.Windows.Forms.RadioButton()<br />
Me.txtResult = New System.Windows.Forms.TextBox()<br />
Me.lblResult = New System.Windows.Forms.Label()<br />
Me.grpDefaultButton.SuspendLayout()<br />
Me.GroupBox2.SuspendLayout()<br />
Me.GroupBox1.SuspendLayout()<br />
Me.SuspendLayout()<br />
"<br />
"txtMsg<br />
"<br />
Me.txtMsg.Location = New System.Drawing.Point(68, 8)<br />
Me.txtMsg.Name = "txtMsg"<br />
Me.txtMsg.Size = New System.Drawing.Size(200, 22)<br />
Me.txtMsg.TabIndex = 0<br />
Me.txtMsg.Text = ""<br />
"<br />
"Label1<br />
"<br />
Me.Label1.Location = New System.Drawing.Point(12, 12)<br />
Me.Label1.Name = "Label1"<br />
Me.Label1.Size = New System.Drawing.Size(60, 16)<br />
Me.Label1.TabIndex = 13<br />
Me.Label1.Text = "Message:"<br />
"<br />
"btnShow<br />
"<br />
Me.btnShow.Location = New System.Drawing.Point(280, 8)<br />
Me.btnShow.Name = "btnShow"<br />
Me.btnShow.Size = New System.Drawing.Size(76, 24)<br />
Me.btnShow.TabIndex = 5<br />
Me.btnShow.Text = "Show"<br />
"<br />
"txtCaption<br />
"<br />
Me.txtCaption.Location = New System.Drawing.Point(68, 36)<br />
Me.txtCaption.Name = "txtCaption"<br />
Me.txtCaption.Size = New System.Drawing.Size(200, 22)<br />
Me.txtCaption.TabIndex = 1<br />
Me.txtCaption.Text = ""<br />
"<br />
"Label2<br />
"<br />
Me.Label2.Location = New System.Drawing.Point(12, 40)<br />
Me.Label2.Name = "Label2"<br />
Me.Label2.Size = New System.Drawing.Size(60, 16)<br />
Me.Label2.TabIndex = 16<br />
Me.Label2.Text = "Caption:"<br />
"<br />
"grpDefaultButton<br />
"<br />
Me.grpDefaultButton.Controls.AddRange(New System.Windows.Forms.Control() {Me.DefaultButton3, Me.DefaultButton2, Me.DefaultButton1})<br />
Me.grpDefaultButton.Location = New System.Drawing.Point(208, 72)<br />
Me.grpDefaultButton.Name = "grpDefaultButton"<br />
Me.grpDefaultButton.Size = New System.Drawing.Size(144, 124)<br />
Me.grpDefaultButton.TabIndex = 4<br />
Me.grpDefaultButton.TabStop = False<br />
Me.grpDefaultButton.Text = "Default Button"<br />
"<br />
"DefaultButton3<br />
"<br />
Me.DefaultButton3.Location = New System.Drawing.Point(12, 68)<br />
Me.DefaultButton3.Name = "DefaultButton3"<br />
Me.DefaultButton3.Size = New System.Drawing.Size(100, 20)<br />
Me.DefaultButton3.TabIndex = 2<br />
Me.DefaultButton3.Text = "DefaultButton3"<br />
"<br />
"DefaultButton2<br />
"<br />
Me.DefaultButton2.Location = New System.Drawing.Point(12, 44)<br />
Me.DefaultButton2.Name = "DefaultButton2"<br />
Me.DefaultButton2.Size = New System.Drawing.Size(100, 20)<br />
Me.DefaultButton2.TabIndex = 1<br />
Me.DefaultButton2.Text = "DefaultButton2"<br />
"<br />
"DefaultButton1<br />
"<br />
Me.DefaultButton1.Checked = True<br />
Me.DefaultButton1.Location = New System.Drawing.Point(12, 20)<br />
Me.DefaultButton1.Name = "DefaultButton1"<br />
Me.DefaultButton1.Size = New System.Drawing.Size(100, 20)<br />
Me.DefaultButton1.TabIndex = 0<br />
Me.DefaultButton1.TabStop = True<br />
Me.DefaultButton1.Text = "DefaultButton1"<br />
"<br />
"GroupBox2<br />
"<br />
Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button6, Me.Button5, Me.Button4, Me.Button3, Me.Button2, Me.Button1})<br />
Me.GroupBox2.Location = New System.Drawing.Point(12, 200)<br />
Me.GroupBox2.Name = "GroupBox2"<br />
Me.GroupBox2.Size = New System.Drawing.Size(188, 160)<br />
Me.GroupBox2.TabIndex = 3<br />
Me.GroupBox2.TabStop = False<br />
Me.GroupBox2.Text = "Buttons"<br />
"<br />
"Button6<br />
"<br />
Me.Button6.Location = New System.Drawing.Point(12, 133)<br />
Me.Button6.Name = "Button6"<br />
Me.Button6.Size = New System.Drawing.Size(100, 19)<br />
Me.Button6.TabIndex = 5<br />
Me.Button6.Text = "YesNoCancel"<br />
"<br />
"Button5<br />
"<br />
Me.Button5.Checked = True<br />
Me.Button5.Location = New System.Drawing.Point(12, 110)<br />
Me.Button5.Name = "Button5"<br />
Me.Button5.Size = New System.Drawing.Size(100, 20)<br />
Me.Button5.TabIndex = 4<br />
Me.Button5.TabStop = True<br />
Me.Button5.Text = "YesNo"<br />
"<br />
"Button4<br />
"<br />
Me.Button4.Location = New System.Drawing.Point(12, 86)<br />
Me.Button4.Name = "Button4"<br />
Me.Button4.Size = New System.Drawing.Size(100, 21)<br />
Me.Button4.TabIndex = 3<br />
Me.Button4.Text = "RetryCancel"<br />
"<br />
"Button3<br />
"<br />
Me.Button3.Location = New System.Drawing.Point(12, 65)<br />
Me.Button3.Name = "Button3"<br />
Me.Button3.Size = New System.Drawing.Size(100, 18)<br />
Me.Button3.TabIndex = 2<br />
Me.Button3.Text = "OKCancel"<br />
"<br />
"Button2<br />
"<br />
Me.Button2.Location = New System.Drawing.Point(12, 43)<br />
Me.Button2.Name = "Button2"<br />
Me.Button2.Size = New System.Drawing.Size(100, 19)<br />
Me.Button2.TabIndex = 1<br />
Me.Button2.Text = "OK"<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(12, 20)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.Size = New System.Drawing.Size(112, 20)<br />
Me.Button1.TabIndex = 0<br />
Me.Button1.Text = "AbortRetryIgnore"<br />
"<br />
"GroupBox1<br />
"<br />
Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.Icon8, Me.Icon7, Me.Icon6, Me.Icon5, Me.Icon4, Me.Icon3, Me.Icon2, Me.Icon1})<br />
Me.GroupBox1.Location = New System.Drawing.Point(12, 72)<br />
Me.GroupBox1.Name = "GroupBox1"<br />
Me.GroupBox1.Size = New System.Drawing.Size(188, 124)<br />
Me.GroupBox1.TabIndex = 2<br />
Me.GroupBox1.TabStop = False<br />
Me.GroupBox1.Text = "Icon"<br />
"<br />
"Icon8<br />
"<br />
Me.Icon8.Location = New System.Drawing.Point(100, 92)<br />
Me.Icon8.Name = "Icon8"<br />
Me.Icon8.Size = New System.Drawing.Size(64, 20)<br />
Me.Icon8.TabIndex = 7<br />
Me.Icon8.Text = "Warning"<br />
"<br />
"Icon7<br />
"<br />
Me.Icon7.Location = New System.Drawing.Point(12, 92)<br />
Me.Icon7.Name = "Icon7"<br />
Me.Icon7.Size = New System.Drawing.Size(84, 20)<br />
Me.Icon7.TabIndex = 6<br />
Me.Icon7.Text = "Stop"<br />
"<br />
"Icon6<br />
"<br />
Me.Icon6.Location = New System.Drawing.Point(100, 68)<br />
Me.Icon6.Name = "Icon6"<br />
Me.Icon6.Size = New System.Drawing.Size(64, 20)<br />
Me.Icon6.TabIndex = 5<br />
Me.Icon6.Text = "Question"<br />
"<br />
"Icon5<br />
"<br />
Me.Icon5.Checked = True<br />
Me.Icon5.Location = New System.Drawing.Point(12, 68)<br />
Me.Icon5.Name = "Icon5"<br />
Me.Icon5.Size = New System.Drawing.Size(84, 20)<br />
Me.Icon5.TabIndex = 4<br />
Me.Icon5.TabStop = True<br />
Me.Icon5.Text = "Information"<br />
"<br />
"Icon4<br />
"<br />
Me.Icon4.Location = New System.Drawing.Point(100, 44)<br />
Me.Icon4.Name = "Icon4"<br />
Me.Icon4.Size = New System.Drawing.Size(64, 20)<br />
Me.Icon4.TabIndex = 3<br />
Me.Icon4.Text = "Hand"<br />
"<br />
"Icon3<br />
"<br />
Me.Icon3.Location = New System.Drawing.Point(12, 44)<br />
Me.Icon3.Name = "Icon3"<br />
Me.Icon3.Size = New System.Drawing.Size(84, 20)<br />
Me.Icon3.TabIndex = 2<br />
Me.Icon3.Text = "Exclamation"<br />
"<br />
"Icon2<br />
"<br />
Me.Icon2.Location = New System.Drawing.Point(100, 20)<br />
Me.Icon2.Name = "Icon2"<br />
Me.Icon2.Size = New System.Drawing.Size(64, 20)<br />
Me.Icon2.TabIndex = 1<br />
Me.Icon2.Text = "Error"<br />
"<br />
"Icon1<br />
"<br />
Me.Icon1.Location = New System.Drawing.Point(12, 20)<br />
Me.Icon1.Name = "Icon1"<br />
Me.Icon1.Size = New System.Drawing.Size(84, 20)<br />
Me.Icon1.TabIndex = 0<br />
Me.Icon1.Text = "Asterisk"<br />
"<br />
"txtResult<br />
"<br />
Me.txtResult.Enabled = False<br />
Me.txtResult.Location = New System.Drawing.Point(212, 232)<br />
Me.txtResult.Name = "txtResult"<br />
Me.txtResult.Size = New System.Drawing.Size(136, 22)<br />
Me.txtResult.TabIndex = 18<br />
Me.txtResult.Text = ""<br />
"<br />
"lblResult<br />
"<br />
Me.lblResult.Location = New System.Drawing.Point(212, 208)<br />
Me.lblResult.Name = "lblResult"<br />
Me.lblResult.Size = New System.Drawing.Size(56, 20)<br />
Me.lblResult.TabIndex = 17<br />
Me.lblResult.Text = "Result"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 15)<br />
Me.ClientSize = New System.Drawing.Size(368, 369)<br />
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.grpDefaultButton, Me.GroupBox2, Me.GroupBox1, Me.txtResult, Me.lblResult, Me.txtCaption, Me.Label2, Me.btnShow, Me.txtMsg, Me.Label1})<br />
Me.Name = "Form1"<br />
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen<br />
Me.Text = "MessageBox Application"<br />
Me.grpDefaultButton.ResumeLayout(False)<br />
Me.GroupBox2.ResumeLayout(False)<br />
Me.GroupBox1.ResumeLayout(False)<br />
Me.ResumeLayout(False)<br />
End Sub<br />
<br />
Private iIcon As Integer<br />
Private iButton As Integer<br />
Private iDefaultButton As Integer<br />
Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShow.Click<br />
Dim iResult As Integer<br />
iResult = MessageBox.Show(Me,txtMsg.Text, txtCaption.Text, iButton, iIcon, iDefaultButton)<br />
Select Case iResult<br />
Case DialogResult.Abort<br />
txtResult.Text = "DialogResult.Abort"<br />
Case DialogResult.Retry<br />
txtResult.Text = "DialogResult.Retry"<br />
Case DialogResult.Ignore<br />
txtResult.Text = "DialogResult.Ignore"<br />
Case DialogResult.OK<br />
txtResult.Text = "DialogResult.OK"<br />
Case DialogResult.Cancel<br />
txtResult.Text = "DialogResult.Cancel"<br />
Case DialogResult.Yes<br />
txtResult.Text = "DialogResult.Yes"<br />
Case DialogResult.No<br />
txtResult.Text = "DialogResult.No"<br />
End Select<br />
End Sub<br />
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
AddHandler Icon1.Click, AddressOf Icon_Click<br />
AddHandler Icon2.Click, AddressOf Icon_Click<br />
AddHandler Icon3.Click, AddressOf Icon_Click<br />
AddHandler Icon4.Click, AddressOf Icon_Click<br />
AddHandler Icon5.Click, AddressOf Icon_Click<br />
AddHandler Icon6.Click, AddressOf Icon_Click<br />
AddHandler Icon7.Click, AddressOf Icon_Click<br />
AddHandler Icon8.Click, AddressOf Icon_Click<br />
AddHandler Button1.Click, AddressOf Button_Click<br />
AddHandler Button2.Click, AddressOf Button_Click<br />
AddHandler Button3.Click, AddressOf Button_Click<br />
AddHandler Button4.Click, AddressOf Button_Click<br />
AddHandler Button5.Click, AddressOf Button_Click<br />
AddHandler Button6.Click, AddressOf Button_Click<br />
AddHandler DefaultButton1.Click, AddressOf DefaultButton_Click<br />
AddHandler DefaultButton2.Click, AddressOf DefaultButton_Click<br />
AddHandler DefaultButton3.Click, AddressOf DefaultButton_Click<br />
iIcon = MessageBoxIcon.Information<br />
iButton = MessageBoxButtons.YesNo<br />
iDefaultButton = MessageBoxDefaultButton.Button1<br />
End Sub<br />
Public Sub Icon_Click(ByVal sender As Object, ByVal e As System.EventArgs)<br />
Select Case sender.Name<br />
Case "Icon1"<br />
iIcon = MessageBoxIcon.Asterisk<br />
Case "Icon2"<br />
iIcon = MessageBoxIcon.Error<br />
Case "Icon3"<br />
iIcon = MessageBoxIcon.Exclamation<br />
Case "Icon4"<br />
iIcon = MessageBoxIcon.Hand<br />
Case "Icon5"<br />
iIcon = MessageBoxIcon.Information<br />
Case "Icon6"<br />
iIcon = MessageBoxIcon.Question<br />
Case "Icon7"<br />
iIcon = MessageBoxIcon.Stop<br />
Case "Icon8"<br />
iIcon = MessageBoxIcon.Warning<br />
End Select<br />
End Sub<br />
Public Sub Button_Click(ByVal sender As Object, ByVal e As System.EventArgs)<br />
Select Case sender.Name<br />
Case "Button1"<br />
iButton = MessageBoxButtons.AbortRetryIgnore<br />
Case "Button2"<br />
iButton = MessageBoxButtons.OK<br />
Case "Button3"<br />
iButton = MessageBoxButtons.OKCancel<br />
Case "Button4"<br />
iButton = MessageBoxButtons.RetryCancel<br />
Case "Button5"<br />
iButton = MessageBoxButtons.YesNo<br />
Case "Button6"<br />
iButton = MessageBoxButtons.YesNoCancel<br />
End Select<br />
End Sub<br />
Public Sub DefaultButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)<br />
Select Case sender.Name<br />
Case "DefaultButton1"<br />
iDefaultButton = MessageBoxDefaultButton.Button1<br />
Case "DefaultButton2"<br />
iDefaultButton = MessageBoxDefaultButton.Button2<br />
Case "DefaultButton3"<br />
iDefaultButton = MessageBoxDefaultButton.Button3<br />
End Select<br />
End Sub<br />
End Class</source><br />
<br />
==Displaying square root of 2 in dialog.==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms " Namespace containing MessageBox<br />
Module modSquareRoot<br />
Sub Main()<br />
Dim root As Double = Math.Sqrt(2)<br />
MessageBox.Show("The square root of 2 is " & root, _<br />
"The Square Root of 2")<br />
End Sub <br />
End Module</source><br />
<br />
==MessageBox: Abort, Retry, Ignore buttons and Warning icon==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class MessageBoxWithMessageAndTile<br />
public Shared Sub Main<br />
MessageBox.Show("Message", "Title", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Warn<br />
ing)<br />
End Sub<br />
End class</source><br />
<br />
==MessageBox Icon and Button==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class RadioButtonAction<br />
public Shared Sub Main<br />
Application.Run(New FrmRadioButton)<br />
End Sub<br />
End class<br />
Public Class FrmRadioButton<br />
Inherits System.Windows.Forms.Form<br />
Private iconType As MessageBoxIcon<br />
Private buttonType As MessageBoxButtons<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
Friend WithEvents iconGroupBox As System.Windows.Forms.GroupBox<br />
Friend WithEvents buttonTypeGroupBox As System.Windows.Forms.GroupBox<br />
Friend WithEvents radRetryCancel As System.Windows.Forms.RadioButton<br />
Friend WithEvents radYesNo As System.Windows.Forms.RadioButton<br />
Friend WithEvents radAbortRetryIgnore As System.Windows.Forms.RadioButton<br />
Friend WithEvents radOk As System.Windows.Forms.RadioButton<br />
Friend WithEvents radWarning As System.Windows.Forms.RadioButton<br />
Friend WithEvents radStop As System.Windows.Forms.RadioButton<br />
Friend WithEvents radQuestion As System.Windows.Forms.RadioButton<br />
Friend WithEvents radInformation As System.Windows.Forms.RadioButton<br />
Friend WithEvents radHand As System.Windows.Forms.RadioButton<br />
Friend WithEvents radExclamation As System.Windows.Forms.RadioButton<br />
Friend WithEvents radError As System.Windows.Forms.RadioButton<br />
Friend WithEvents radAsterisk As System.Windows.Forms.RadioButton<br />
Friend WithEvents cmdDisplay As System.Windows.Forms.Button<br />
Friend WithEvents lblDisplay As System.Windows.Forms.Label<br />
Friend WithEvents radOkCancel As System.Windows.Forms.RadioButton<br />
Friend WithEvents radYesNoCancel As System.Windows.Forms.RadioButton<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.Container<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.radAbortRetryIgnore = New System.Windows.Forms.RadioButton()<br />
Me.radStop = New System.Windows.Forms.RadioButton()<br />
Me.radYesNo = New System.Windows.Forms.RadioButton()<br />
Me.iconGroupBox = New System.Windows.Forms.GroupBox()<br />
Me.radWarning = New System.Windows.Forms.RadioButton()<br />
Me.radQuestion = New System.Windows.Forms.RadioButton()<br />
Me.radInformation = New System.Windows.Forms.RadioButton()<br />
Me.radHand = New System.Windows.Forms.RadioButton()<br />
Me.radExclamation = New System.Windows.Forms.RadioButton()<br />
Me.radError = New System.Windows.Forms.RadioButton()<br />
Me.radAsterisk = New System.Windows.Forms.RadioButton()<br />
Me.radYesNoCancel = New System.Windows.Forms.RadioButton()<br />
Me.radOk = New System.Windows.Forms.RadioButton()<br />
Me.cmdDisplay = New System.Windows.Forms.Button()<br />
Me.lblDisplay = New System.Windows.Forms.Label()<br />
Me.buttonTypeGroupBox = New System.Windows.Forms.GroupBox()<br />
Me.radRetryCancel = New System.Windows.Forms.RadioButton()<br />
Me.radOkCancel = New System.Windows.Forms.RadioButton()<br />
Me.iconGroupBox.SuspendLayout()<br />
Me.buttonTypeGroupBox.SuspendLayout()<br />
Me.SuspendLayout()<br />
"<br />
"radAbortRetryIgnore<br />
"<br />
Me.radAbortRetryIgnore.Location = New System.Drawing.Point(16, 88)<br />
Me.radAbortRetryIgnore.Name = "radAbortRetryIgnore"<br />
Me.radAbortRetryIgnore.Size = New System.Drawing.Size(120, 24)<br />
Me.radAbortRetryIgnore.TabIndex = 2<br />
Me.radAbortRetryIgnore.Text = "AbortRetryIgnore"<br />
"<br />
"radStop<br />
"<br />
Me.radStop.Location = New System.Drawing.Point(16, 240)<br />
Me.radStop.Name = "radStop"<br />
Me.radStop.Size = New System.Drawing.Size(128, 24)<br />
Me.radStop.TabIndex = 6<br />
Me.radStop.Text = "Stop"<br />
"<br />
"radYesNo<br />
"<br />
Me.radYesNo.Location = New System.Drawing.Point(16, 160)<br />
Me.radYesNo.Name = "radYesNo"<br />
Me.radYesNo.Size = New System.Drawing.Size(120, 16)<br />
Me.radYesNo.TabIndex = 4<br />
Me.radYesNo.Text = "YesNo"<br />
"<br />
"iconGroupBox<br />
"<br />
Me.iconGroupBox.Controls.AddRange(New System.Windows.Forms.Control() {Me.radWarning, Me.radStop, Me.radQuestion, Me.radInformation, Me.radHand, Me.radExclamation, Me.radError, Me.radAsterisk})<br />
Me.iconGroupBox.Location = New System.Drawing.Point(200, 16)<br />
Me.iconGroupBox.Name = "iconGroupBox"<br />
Me.iconGroupBox.Size = New System.Drawing.Size(160, 304)<br />
Me.iconGroupBox.TabIndex = 3<br />
Me.iconGroupBox.TabStop = False<br />
Me.iconGroupBox.Text = "Icon"<br />
"<br />
"radWarning<br />
"<br />
Me.radWarning.Location = New System.Drawing.Point(16, 272)<br />
Me.radWarning.Name = "radWarning"<br />
Me.radWarning.Size = New System.Drawing.Size(128, 24)<br />
Me.radWarning.TabIndex = 7<br />
Me.radWarning.Text = "Warning"<br />
"<br />
"radQuestion<br />
"<br />
Me.radQuestion.Location = New System.Drawing.Point(16, 208)<br />
Me.radQuestion.Name = "radQuestion"<br />
Me.radQuestion.Size = New System.Drawing.Size(128, 24)<br />
Me.radQuestion.TabIndex = 5<br />
Me.radQuestion.Text = "Question"<br />
"<br />
"radInformation<br />
"<br />
Me.radInformation.Location = New System.Drawing.Point(16, 168)<br />
Me.radInformation.Name = "radInformation"<br />
Me.radInformation.Size = New System.Drawing.Size(128, 24)<br />
Me.radInformation.TabIndex = 4<br />
Me.radInformation.Text = "Information"<br />
"<br />
"radHand<br />
"<br />
Me.radHand.Location = New System.Drawing.Point(16, 128)<br />
Me.radHand.Name = "radHand"<br />
Me.radHand.Size = New System.Drawing.Size(128, 24)<br />
Me.radHand.TabIndex = 3<br />
Me.radHand.Text = "Hand"<br />
"<br />
"radExclamation<br />
"<br />
Me.radExclamation.Location = New System.Drawing.Point(16, 88)<br />
Me.radExclamation.Name = "radExclamation"<br />
Me.radExclamation.Size = New System.Drawing.Size(136, 24)<br />
Me.radExclamation.TabIndex = 2<br />
Me.radExclamation.Text = "Exclamation"<br />
"<br />
"radError<br />
"<br />
Me.radError.Location = New System.Drawing.Point(16, 48)<br />
Me.radError.Name = "radError"<br />
Me.radError.Size = New System.Drawing.Size(136, 24)<br />
Me.radError.TabIndex = 1<br />
Me.radError.Text = "Error"<br />
"<br />
"radAsterisk<br />
"<br />
Me.radAsterisk.Location = New System.Drawing.Point(16, 16)<br />
Me.radAsterisk.Name = "radAsterisk"<br />
Me.radAsterisk.Size = New System.Drawing.Size(136, 24)<br />
Me.radAsterisk.TabIndex = 0<br />
Me.radAsterisk.Text = "Asterisk"<br />
"<br />
"radYesNoCancel<br />
"<br />
Me.radYesNoCancel.Location = New System.Drawing.Point(16, 120)<br />
Me.radYesNoCancel.Name = "radYesNoCancel"<br />
Me.radYesNoCancel.Size = New System.Drawing.Size(120, 24)<br />
Me.radYesNoCancel.TabIndex = 3<br />
Me.radYesNoCancel.Text = "YesNoCancel"<br />
"<br />
"radOk<br />
"<br />
Me.radOk.Location = New System.Drawing.Point(16, 24)<br />
Me.radOk.Name = "radOk"<br />
Me.radOk.Size = New System.Drawing.Size(112, 16)<br />
Me.radOk.TabIndex = 0<br />
Me.radOk.Text = "OK"<br />
"<br />
"cmdDisplay<br />
"<br />
Me.cmdDisplay.Location = New System.Drawing.Point(32, 240)<br />
Me.cmdDisplay.Name = "cmdDisplay"<br />
Me.cmdDisplay.Size = New System.Drawing.Size(112, 40)<br />
Me.cmdDisplay.TabIndex = 1<br />
Me.cmdDisplay.Text = "Display"<br />
"<br />
"lblDisplay<br />
"<br />
Me.lblDisplay.Location = New System.Drawing.Point(24, 296)<br />
Me.lblDisplay.Name = "lblDisplay"<br />
Me.lblDisplay.Size = New System.Drawing.Size(144, 24)<br />
Me.lblDisplay.TabIndex = 5<br />
"<br />
"buttonTypeGroupBox<br />
"<br />
Me.buttonTypeGroupBox.Controls.AddRange(New System.Windows.Forms.Control() {Me.radRetryCancel, Me.radYesNo, Me.radYesNoCancel, Me.radAbortRetryIgnore, Me.radOkCancel, Me.radOk})<br />
Me.buttonTypeGroupBox.Location = New System.Drawing.Point(16, 16)<br />
Me.buttonTypeGroupBox.Name = "buttonTypeGroupBox"<br />
Me.buttonTypeGroupBox.Size = New System.Drawing.Size(144, 216)<br />
Me.buttonTypeGroupBox.TabIndex = 2<br />
Me.buttonTypeGroupBox.TabStop = False<br />
Me.buttonTypeGroupBox.Text = "Button Type"<br />
"<br />
"radRetryCancel<br />
"<br />
Me.radRetryCancel.Location = New System.Drawing.Point(16, 192)<br />
Me.radRetryCancel.Name = "radRetryCancel"<br />
Me.radRetryCancel.Size = New System.Drawing.Size(104, 16)<br />
Me.radRetryCancel.TabIndex = 5<br />
Me.radRetryCancel.Text = "RetryCancel"<br />
"<br />
"radOkCancel<br />
"<br />
Me.radOkCancel.Location = New System.Drawing.Point(16, 56)<br />
Me.radOkCancel.Name = "radOkCancel"<br />
Me.radOkCancel.Size = New System.Drawing.Size(120, 24)<br />
Me.radOkCancel.TabIndex = 1<br />
Me.radOkCancel.Text = "OKCancel"<br />
"<br />
"FrmRadioButton<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(384, 333)<br />
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblDisplay, Me.iconGroupBox, Me.buttonTypeGroupBox, Me.cmdDisplay})<br />
Me.Name = "FrmRadioButton"<br />
Me.Text = "RadioButtonTest"<br />
Me.iconGroupBox.ResumeLayout(False)<br />
Me.buttonTypeGroupBox.ResumeLayout(False)<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub cmdDisplay_Click(ByVal sender _<br />
As System.Object, ByVal e As System.EventArgs) _<br />
Handles cmdDisplay.Click<br />
Dim dialog As DialogResult = MessageBox.Show( _<br />
"Your message", "Title", _<br />
buttonType, iconType)<br />
Select Case dialog<br />
Case DialogResult.OK<br />
lblDisplay.Text = "OK was pressed"<br />
Case DialogResult.Cancel<br />
lblDisplay.Text = "Cancel was pressed"<br />
Case DialogResult.Abort<br />
lblDisplay.Text = "Abort was pressed"<br />
Case DialogResult.Retry<br />
lblDisplay.Text = "Retry was pressed"<br />
Case DialogResult.Ignore<br />
lblDisplay.Text = "Ignore was pressed"<br />
Case DialogResult.Yes<br />
lblDisplay.Text = "Yes was pressed"<br />
Case DialogResult.No<br />
lblDisplay.Text = "No was pressed"<br />
End Select<br />
End Sub " cmdDisplay_Click<br />
Private Sub radOk_CheckedChanged(ByVal sender _<br />
As System.Object, ByVal e As System.EventArgs) _<br />
Handles radOk.CheckedChanged<br />
buttonType = MessageBoxButtons.OK<br />
End Sub <br />
<br />
Private Sub radOkCancel_CheckedChanged(ByVal sender _<br />
As System.Object, ByVal e As System.EventArgs) _<br />
Handles radOkCancel.CheckedChanged<br />
buttonType = MessageBoxButtons.OKCancel<br />
End Sub <br />
<br />
Private Sub radAbortRetryIgnore_CheckedChanged(ByVal sender _<br />
As System.Object, ByVal e As System.EventArgs) _<br />
Handles radAbortRetryIgnore.CheckedChanged<br />
buttonType = MessageBoxButtons.AbortRetryIgnore<br />
End Sub <br />
<br />
Private Sub radYesNoCancel_CheckedChanged(ByVal sender _<br />
As System.Object, ByVal e As System.EventArgs) _<br />
Handles radYesNoCancel.CheckedChanged<br />
buttonType = MessageBoxButtons.YesNoCancel<br />
End Sub<br />
<br />
Private Sub radYesNo_CheckedChanged(ByVal sender _<br />
As System.Object, ByVal e As System.EventArgs) _<br />
Handles radYesNo.CheckedChanged<br />
buttonType = MessageBoxButtons.YesNo<br />
End Sub<br />
<br />
Private Sub radRetryCancel_CheckedChanged(ByVal sender _<br />
As System.Object, ByVal e As System.EventArgs) _<br />
Handles radRetryCancel.CheckedChanged<br />
buttonType = MessageBoxButtons.RetryCancel<br />
End Sub<br />
<br />
Private Sub radAsterisk_CheckedChanged(ByVal sender _<br />
As System.Object, ByVal e As System.EventArgs) _<br />
Handles radAsterisk.CheckedChanged<br />
iconType = MessageBoxIcon.Asterisk<br />
End Sub<br />
<br />
Private Sub radError_CheckedChanged(ByVal sender _<br />
As System.Object, ByVal e As System.EventArgs) _<br />
Handles radError.CheckedChanged<br />
iconType = MessageBoxIcon.Error<br />
End Sub <br />
<br />
Private Sub radExclamation_CheckedChanged(ByVal sender _<br />
As System.Object, ByVal e As System.EventArgs) _<br />
Handles radExclamation.CheckedChanged<br />
iconType = MessageBoxIcon.Exclamation<br />
End Sub <br />
<br />
Private Sub radHand_CheckedChanged(ByVal sender _<br />
As System.Object, ByVal e As System.EventArgs) _<br />
Handles radHand.CheckedChanged<br />
iconType = MessageBoxIcon.Hand<br />
End Sub <br />
<br />
Private Sub radInformation_CheckedChanged(ByVal sender _<br />
As System.Object, ByVal e As System.EventArgs) _<br />
Handles radInformation.CheckedChanged<br />
iconType = MessageBoxIcon.Information<br />
End Sub <br />
<br />
Private Sub radQuestion_CheckedChanged(ByVal sender _<br />
As System.Object, ByVal e As System.EventArgs) _<br />
Handles radQuestion.CheckedChanged<br />
iconType = MessageBoxIcon.Question<br />
End Sub <br />
<br />
Private Sub radStop_CheckedChanged(ByVal sender _<br />
As System.Object, ByVal e As System.EventArgs) _<br />
Handles radStop.CheckedChanged<br />
iconType = MessageBoxIcon.Stop<br />
End Sub <br />
<br />
Private Sub radWarning_CheckedChanged(ByVal sender _<br />
As System.Object, ByVal e As System.EventArgs) _<br />
Handles radWarning.CheckedChanged<br />
iconType = MessageBoxIcon.Warning<br />
End Sub <br />
End Class</source><br />
<br />
==MessageBox OK and Cancel Button==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class MessageBoxWithMessageAndTile<br />
public Shared Sub Main<br />
MessageBox.Show("Message", "Title", MessageBoxButtons.OKCancel)<br />
End Sub<br />
End class</source><br />
<br />
==MessageBox with Message and Title==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class MessageBoxWithMessageAndTile<br />
public Shared Sub Main<br />
MessageBox.Show("Message", "Title")<br />
End Sub<br />
End class</source><br />
<br />
==MessageBox with Message only==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class MessageBoxWithMessageOnly<br />
public Shared Sub Main<br />
MessageBox.Show("Message")<br />
End Sub<br />
End class</source><br />
<br />
==MessageBox with OK, Cancel button and Information==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class MessageBoxOKCancelInformation<br />
public Shared Sub Main<br />
Dim answer As DialogResult<br />
answer = MessageBox.Show("A","B", MessageBoxButtons.OKCancel,MessageBoxIcon.Information)<br />
End Sub<br />
End class</source><br />
<br />
==MessageBox with Yes No Cancel button and Question icon==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class MessageBoxYesNoCancelQuestion<br />
public Shared Sub Main<br />
Dim answer As DialogResult<br />
answer = MessageBox.Show("A", "B", _<br />
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)<br />
End Sub<br />
End class</source><br />
<br />
==Return value from MessageBox==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class MessageBoxReturnValue<br />
public Shared Sub Main<br />
Dim intReturnValue As Integer<br />
intReturnValue = MessageBox.Show("This is also a message box!", "Message Box", _<br />
MessageBoxButtons.OKCancel, MessageBoxIcon.Information, _<br />
MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly)<br />
If (intReturnValue = DialogResult.OK) Then<br />
Console.WriteLine("You clicked the OK button.")<br />
End If<br />
End Sub<br />
End class</source><br />
<br />
==Set default button for MessageBox==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class MessageBoxDefaultButtonDemo<br />
public Shared Sub Main<br />
Dim answer As DialogResult<br />
answer = MessageBox.Show("A", "B",MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, _<br />
MessageBoxDefaultButton.Button2)<br />
End Sub<br />
End class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/DialogResult&diff=3915
VB.Net Tutorial/GUI/DialogResult
2010-05-26T12:57:27Z
<p>Admin: 1 версия</p>
<hr />
<div>==DialogResult.Retry, Abort, Cancel==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
Public Class Test<br />
Public Shared Sub Main<br />
Dim drResult As DialogResult<br />
drResult = MessageBox.Show("Q?", "Sample", MessageBoxButtons.RetryCancel)<br />
<br />
If drResult = DialogResult.Retry Then<br />
Console.WriteLine("Retry")<br />
Else<br />
Console.WriteLine("Cancel")<br />
End If<br />
<br />
Select Case MessageBox.Show("Bad stuff happened","Long Process", MessageBoxButtons.AbortRetryIgnore)<br />
Case DialogResult.Abort<br />
Console.WriteLine("abort")<br />
Case DialogResult.Retry<br />
Console.WriteLine("retry")<br />
Case DialogResult.Cancel<br />
Console.WriteLine("cancel")<br />
Case Else<br />
Console.WriteLine("Else")<br />
End Select<br />
End Sub<br />
End Class</source><br />
<br />
==Get DialogResult==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class GetDialogResult<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.SuspendLayout()<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(112, 40)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.Size = New System.Drawing.Size(88, 23)<br />
Me.Button1.TabIndex = 0<br />
Me.Button1.Text = "Show Dialog"<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(104, 96)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(112, 20)<br />
Me.TextBox1.TabIndex = 1<br />
Me.TextBox1.Text = ""<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(304, 181)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.Controls.Add(Me.Button1)<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
Dim frmDialog As New Form2<br />
If frmDialog.ShowDialog() = DialogResult.OK Then<br />
TextBox1.Text = "You typed: " & frmDialog.TextBox1.Text<br />
End If<br />
End Sub<br />
End Class<br />
<br />
Public Class Form2<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents Button2 As System.Windows.Forms.Button<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.Button2 = New System.Windows.Forms.Button<br />
Me.SuspendLayout()<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(16, 16)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(256, 20)<br />
Me.TextBox1.TabIndex = 0<br />
Me.TextBox1.Text = ""<br />
"<br />
"Button1<br />
"<br />
Me.Button1.DialogResult = System.Windows.Forms.DialogResult.OK<br />
Me.Button1.Location = New System.Drawing.Point(48, 72)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.TabIndex = 1<br />
Me.Button1.Text = "OK"<br />
"<br />
"Button2<br />
"<br />
Me.Button2.DialogResult = System.Windows.Forms.DialogResult.Cancel<br />
Me.Button2.Location = New System.Drawing.Point(168, 72)<br />
Me.Button2.Name = "Button2"<br />
Me.Button2.TabIndex = 2<br />
Me.Button2.Text = "Cancel"<br />
"<br />
"Form2<br />
"<br />
Me.AcceptButton = Me.Button1<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.CancelButton = Me.Button2<br />
Me.ClientSize = New System.Drawing.Size(288, 125)<br />
Me.ControlBox = False<br />
Me.Controls.Add(Me.Button2)<br />
Me.Controls.Add(Me.Button1)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog<br />
Me.Name = "Form2"<br />
Me.Text = "Dialog"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
Me.Close()<br />
End Sub<br />
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click<br />
Me.Close()<br />
End Sub<br />
End Class</source><br />
<br />
==Set DialogResult to Button==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class GetDialogResult<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.SuspendLayout()<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(112, 40)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.Size = New System.Drawing.Size(88, 23)<br />
Me.Button1.TabIndex = 0<br />
Me.Button1.Text = "Show Dialog"<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(104, 96)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(112, 20)<br />
Me.TextBox1.TabIndex = 1<br />
Me.TextBox1.Text = ""<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(304, 181)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.Controls.Add(Me.Button1)<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
Dim frmDialog As New Form2<br />
If frmDialog.ShowDialog() = DialogResult.OK Then<br />
TextBox1.Text = "You typed: " & frmDialog.TextBox1.Text<br />
End If<br />
End Sub<br />
End Class<br />
<br />
Public Class Form2<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents Button2 As System.Windows.Forms.Button<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.Button2 = New System.Windows.Forms.Button<br />
Me.SuspendLayout()<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(16, 16)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(256, 20)<br />
Me.TextBox1.TabIndex = 0<br />
Me.TextBox1.Text = ""<br />
"<br />
"Button1<br />
"<br />
Me.Button1.DialogResult = System.Windows.Forms.DialogResult.OK<br />
Me.Button1.Location = New System.Drawing.Point(48, 72)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.TabIndex = 1<br />
Me.Button1.Text = "OK"<br />
"<br />
"Button2<br />
"<br />
Me.Button2.DialogResult = System.Windows.Forms.DialogResult.Cancel<br />
Me.Button2.Location = New System.Drawing.Point(168, 72)<br />
Me.Button2.Name = "Button2"<br />
Me.Button2.TabIndex = 2<br />
Me.Button2.Text = "Cancel"<br />
"<br />
"Form2<br />
"<br />
Me.AcceptButton = Me.Button1<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.CancelButton = Me.Button2<br />
Me.ClientSize = New System.Drawing.Size(288, 125)<br />
Me.ControlBox = False<br />
Me.Controls.Add(Me.Button2)<br />
Me.Controls.Add(Me.Button1)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog<br />
Me.Name = "Form2"<br />
Me.Text = "Dialog"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
Me.Close()<br />
End Sub<br />
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click<br />
Me.Close()<br />
End Sub<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/SplitContainer&diff=3917
VB.Net Tutorial/GUI/SplitContainer
2010-05-26T12:57:27Z
<p>Admin: 1 версия</p>
<hr />
<div>==Use SplitContainer==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
<br />
public class UseSplitContainer<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.SplitContainer1 = New System.Windows.Forms.SplitContainer<br />
Me.PictureBox1 = New System.Windows.Forms.PictureBox<br />
Me.PictureBox2 = New System.Windows.Forms.PictureBox<br />
Me.SplitContainer1.Panel1.SuspendLayout()<br />
Me.SplitContainer1.Panel2.SuspendLayout()<br />
Me.SplitContainer1.SuspendLayout()<br />
CType(Me.PictureBox1, System.ruponentModel.ISupportInitialize).BeginInit()<br />
CType(Me.PictureBox2, System.ruponentModel.ISupportInitialize).BeginInit()<br />
Me.SuspendLayout()<br />
"<br />
"SplitContainer1<br />
"<br />
Me.SplitContainer1.Dock = System.Windows.Forms.DockStyle.Fill<br />
Me.SplitContainer1.Location = New System.Drawing.Point(0, 0)<br />
Me.SplitContainer1.Name = "SplitContainer1"<br />
Me.SplitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal<br />
"<br />
"SplitContainer1.Panel1<br />
"<br />
Me.SplitContainer1.Panel1.AutoScroll = True<br />
Me.SplitContainer1.Panel1.Controls.Add(Me.PictureBox1)<br />
"<br />
"SplitContainer1.Panel2<br />
"<br />
Me.SplitContainer1.Panel2.AutoScroll = True<br />
Me.SplitContainer1.Panel2.Controls.Add(Me.PictureBox2)<br />
Me.SplitContainer1.Size = New System.Drawing.Size(253, 292)<br />
Me.SplitContainer1.SplitterDistance = 105<br />
Me.SplitContainer1.TabIndex = 1<br />
Me.SplitContainer1.Text = "SplitContainer1"<br />
"<br />
"PictureBox1<br />
"<br />
Me.PictureBox1.AutoSize = True<br />
Me.PictureBox1.Location = New System.Drawing.Point(8, 8)<br />
Me.PictureBox1.Name = "PictureBox1"<br />
Me.PictureBox1.Size = New System.Drawing.Size(412, 270)<br />
Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize<br />
Me.PictureBox1.TabIndex = 0<br />
Me.PictureBox1.TabStop = False<br />
"<br />
"PictureBox2<br />
"<br />
Me.PictureBox2.AutoSize = True<br />
Me.PictureBox2.Location = New System.Drawing.Point(8, 8)<br />
Me.PictureBox2.Name = "PictureBox2"<br />
Me.PictureBox2.Size = New System.Drawing.Size(150, 138)<br />
Me.PictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize<br />
Me.PictureBox2.TabIndex = 0<br />
Me.PictureBox2.TabStop = False<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(253, 292)<br />
Me.Controls.Add(Me.SplitContainer1)<br />
Me.Name = "Form1"<br />
Me.Text = "UseSplitContainer"<br />
Me.SplitContainer1.Panel1.ResumeLayout(False)<br />
Me.SplitContainer1.Panel1.PerformLayout()<br />
Me.SplitContainer1.Panel2.ResumeLayout(False)<br />
Me.SplitContainer1.Panel2.PerformLayout()<br />
Me.SplitContainer1.ResumeLayout(False)<br />
CType(Me.PictureBox1, System.ruponentModel.ISupportInitialize).EndInit()<br />
CType(Me.PictureBox2, System.ruponentModel.ISupportInitialize).EndInit()<br />
Me.ResumeLayout(False)<br />
End Sub<br />
Friend WithEvents SplitContainer1 As System.Windows.Forms.SplitContainer<br />
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox<br />
Friend WithEvents PictureBox2 As System.Windows.Forms.PictureBox<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/SaveFileDialog&diff=3911
VB.Net Tutorial/GUI/SaveFileDialog
2010-05-26T12:57:26Z
<p>Admin: 1 версия</p>
<hr />
<div>==SaveFileDialog filter and selected file name,==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class FileOpenDialogFilter<br />
public Shared Sub Main<br />
Dim saveFileDialog1 As System.Windows.Forms.SaveFileDialog<br />
saveFileDialog1 = New System.Windows.Forms.SaveFileDialog()<br />
saveFileDialog1.CreatePrompt = True<br />
saveFileDialog1.FileName = "doc1"<br />
saveFileDialog1.Filter = "Word (*.doc) |*.doc;*.rtf|(*.txt) |*.txt|(*.*) |*.*"<br />
If saveFileDialog1.ShowDialog() = DialogResult.OK Then<br />
Console.WriteLine(saveFileDialog1.FileName)<br />
End If<br />
End Sub<br />
End class</source><br />
<br />
==Set InitialDirectory for SaveFileDialog==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class SaveFileDialogWith<br />
public Shared Sub Main<br />
Dim SaveFileDialog1 As SaveFileDialog = New System.Windows.Forms.SaveFileDialog<br />
With SaveFileDialog1<br />
.DefaultExt = ".txt"<br />
.Filter = "Text Files|*.txt"<br />
.InitialDirectory = "C:\My Documents"<br />
End With<br />
If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then<br />
Console.WriteLine(SaveFileDialog1.FileName)<br />
End If<br />
End Sub<br />
End class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/Tooltips&diff=3913
VB.Net Tutorial/GUI/Tooltips
2010-05-26T12:57:26Z
<p>Admin: 1 версия</p>
<hr />
<div>==Add ToolTip to TextBox==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class AddToolTipToTextBox<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.ruponents = New System.ruponentModel.Container<br />
Me.Label1 = New System.Windows.Forms.Label<br />
Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.ruponents)<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.SuspendLayout()<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(96, 120)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.TabIndex = 1<br />
Me.TextBox1.Text = ""<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(292, 273)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.Controls.Add(Me.Label1)<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
ToolTip1.SetToolTip(TextBox1, "This is a text box.")<br />
End Sub<br />
End Class</source><br />
<br />
==Add ToolTip to TextBox and ComboBox==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
<br />
public class SetToolTipForTextBoxAndComboBox<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
ttHint.SetToolTip(txtFirstName, "first name")<br />
ttHint.SetToolTip(txtLastName, "last name")<br />
ttHint.SetToolTip(txtStreet, "address street number and name")<br />
ttHint.SetToolTip(txtCity, "city")<br />
ttHint.SetToolTip(cboState, "state")<br />
ttHint.SetToolTip(txtZip, "ZIP code")<br />
End Sub<br />
End Class<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.ruponents = New System.ruponentModel.Container<br />
Me.ttHint = New System.Windows.Forms.ToolTip(Me.ruponents)<br />
Me.TableLayoutPanel1 = New System.Windows.Forms.TableLayoutPanel<br />
Me.Label1 = New System.Windows.Forms.Label<br />
Me.Label7 = New System.Windows.Forms.Label<br />
Me.Label2 = New System.Windows.Forms.Label<br />
Me.txtFirstName = New System.Windows.Forms.TextBox<br />
Me.txtLastName = New System.Windows.Forms.TextBox<br />
Me.txtStreet = New System.Windows.Forms.TextBox<br />
Me.Label3 = New System.Windows.Forms.Label<br />
Me.txtCity = New System.Windows.Forms.TextBox<br />
Me.txtZip = New System.Windows.Forms.TextBox<br />
Me.Label5 = New System.Windows.Forms.Label<br />
Me.Label8 = New System.Windows.Forms.Label<br />
Me.Label6 = New System.Windows.Forms.Label<br />
Me.cboState = New System.Windows.Forms.ruboBox<br />
Me.TableLayoutPanel1.SuspendLayout()<br />
Me.SuspendLayout()<br />
"<br />
"TableLayoutPanel1<br />
"<br />
Me.TableLayoutPanel1.AutoSize = True<br />
Me.TableLayoutPanel1.ColumnCount = 2<br />
Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 80.0!))<br />
Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 136.0!))<br />
Me.TableLayoutPanel1.Controls.Add(Me.Label1, 0, 0)<br />
Me.TableLayoutPanel1.Controls.Add(Me.Label7, 0, 1)<br />
Me.TableLayoutPanel1.Controls.Add(Me.Label2, 0, 2)<br />
Me.TableLayoutPanel1.Controls.Add(Me.txtFirstName, 1, 1)<br />
Me.TableLayoutPanel1.Controls.Add(Me.txtLastName, 1, 2)<br />
Me.TableLayoutPanel1.Controls.Add(Me.txtStreet, 1, 3)<br />
Me.TableLayoutPanel1.Controls.Add(Me.Label3, 0, 3)<br />
Me.TableLayoutPanel1.Controls.Add(Me.txtCity, 1, 4)<br />
Me.TableLayoutPanel1.Controls.Add(Me.txtZip, 1, 6)<br />
Me.TableLayoutPanel1.Controls.Add(Me.Label5, 0, 5)<br />
Me.TableLayoutPanel1.Controls.Add(Me.Label8, 0, 4)<br />
Me.TableLayoutPanel1.Controls.Add(Me.Label6, 0, 6)<br />
Me.TableLayoutPanel1.Controls.Add(Me.cboState, 1, 5)<br />
Me.TableLayoutPanel1.Location = New System.Drawing.Point(7, 7)<br />
Me.TableLayoutPanel1.Name = "TableLayoutPanel1"<br />
Me.TableLayoutPanel1.RowCount = 7<br />
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle)<br />
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle)<br />
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle)<br />
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle)<br />
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle)<br />
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle)<br />
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle)<br />
Me.TableLayoutPanel1.Size = New System.Drawing.Size(272, 182)<br />
Me.TableLayoutPanel1.TabIndex = 1<br />
"<br />
"Label1<br />
"<br />
Me.Label1.Anchor = System.Windows.Forms.AnchorStyles.None<br />
Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D<br />
Me.TableLayoutPanel1.SetColumnSpan(Me.Label1, 2)<br />
Me.Label1.Location = New System.Drawing.Point(36, 0)<br />
Me.Label1.Name = "Label1"<br />
Me.Label1.Size = New System.Drawing.Size(200, 20)<br />
Me.Label1.TabIndex = 37<br />
Me.Label1.Text = "Employee"<br />
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter<br />
"<br />
"Label7<br />
"<br />
Me.Label7.Anchor = System.Windows.Forms.AnchorStyles.None<br />
Me.Label7.AutoSize = True<br />
Me.Label7.Location = New System.Drawing.Point(13, 26)<br />
Me.Label7.Name = "Label7"<br />
Me.Label7.Size = New System.Drawing.Size(53, 13)<br />
Me.Label7.TabIndex = 38<br />
Me.Label7.Text = "First Name"<br />
"<br />
"Label2<br />
"<br />
Me.Label2.Anchor = System.Windows.Forms.AnchorStyles.None<br />
Me.Label2.AutoSize = True<br />
Me.Label2.Location = New System.Drawing.Point(13, 52)<br />
Me.Label2.Name = "Label2"<br />
Me.Label2.Size = New System.Drawing.Size(54, 13)<br />
Me.Label2.TabIndex = 40<br />
Me.Label2.Text = "Last Name"<br />
"<br />
"txtFirstName<br />
"<br />
Me.txtFirstName.Anchor = CType((System.Windows.Forms.AnchorStyles.Left Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)<br />
Me.txtFirstName.Location = New System.Drawing.Point(83, 23)<br />
Me.txtFirstName.Name = "txtFirstName"<br />
Me.txtFirstName.Size = New System.Drawing.Size(186, 20)<br />
Me.txtFirstName.TabIndex = 0<br />
Me.ttHint.SetToolTip(Me.txtFirstName, "Enter the customer"s first (given) name.")<br />
"<br />
"txtLastName<br />
"<br />
Me.txtLastName.Anchor = CType((System.Windows.Forms.AnchorStyles.Left Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)<br />
Me.txtLastName.Location = New System.Drawing.Point(83, 49)<br />
Me.txtLastName.Name = "txtLastName"<br />
Me.txtLastName.Size = New System.Drawing.Size(186, 20)<br />
Me.txtLastName.TabIndex = 1<br />
Me.ttHint.SetToolTip(Me.txtLastName, "Enter the customer"s last (family) name.")<br />
"<br />
"txtStreet<br />
"<br />
Me.txtStreet.Anchor = CType((System.Windows.Forms.AnchorStyles.Left Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)<br />
Me.txtStreet.Location = New System.Drawing.Point(83, 75)<br />
Me.txtStreet.Name = "txtStreet"<br />
Me.txtStreet.Size = New System.Drawing.Size(186, 20)<br />
Me.txtStreet.TabIndex = 2<br />
Me.ttHint.SetToolTip(Me.txtStreet, "Enter the customer"s stree address including apartment, suite, or other informati" & _<br />
"on.")<br />
"<br />
"Label3<br />
"<br />
Me.Label3.Anchor = System.Windows.Forms.AnchorStyles.None<br />
Me.Label3.AutoSize = True<br />
Me.Label3.Location = New System.Drawing.Point(24, 78)<br />
Me.Label3.Name = "Label3"<br />
Me.Label3.Size = New System.Drawing.Size(31, 13)<br />
Me.Label3.TabIndex = 42<br />
Me.Label3.Text = "Street"<br />
"<br />
"txtCity<br />
"<br />
Me.txtCity.Anchor = CType((System.Windows.Forms.AnchorStyles.Left Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)<br />
Me.txtCity.Location = New System.Drawing.Point(83, 101)<br />
Me.txtCity.Name = "txtCity"<br />
Me.txtCity.Size = New System.Drawing.Size(186, 20)<br />
Me.txtCity.TabIndex = 3<br />
Me.ttHint.SetToolTip(Me.txtCity, "Enter the customer"s city.")<br />
"<br />
"txtZip<br />
"<br />
Me.txtZip.Anchor = System.Windows.Forms.AnchorStyles.Left<br />
Me.txtZip.Location = New System.Drawing.Point(83, 156)<br />
Me.txtZip.Name = "txtZip"<br />
Me.txtZip.Size = New System.Drawing.Size(64, 20)<br />
Me.txtZip.TabIndex = 5<br />
Me.ttHint.SetToolTip(Me.txtZip, "Enter the customer"s ZIP code.")<br />
"<br />
"Label5<br />
"<br />
Me.Label5.Anchor = System.Windows.Forms.AnchorStyles.None<br />
Me.Label5.AutoSize = True<br />
Me.Label5.Location = New System.Drawing.Point(26, 131)<br />
Me.Label5.Name = "Label5"<br />
Me.Label5.Size = New System.Drawing.Size(28, 13)<br />
Me.Label5.TabIndex = 46<br />
Me.Label5.Text = "State"<br />
"<br />
"Label8<br />
"<br />
Me.Label8.Anchor = System.Windows.Forms.AnchorStyles.None<br />
Me.Label8.AutoSize = True<br />
Me.Label8.Location = New System.Drawing.Point(30, 104)<br />
Me.Label8.Name = "Label8"<br />
Me.Label8.Size = New System.Drawing.Size(20, 13)<br />
Me.Label8.TabIndex = 51<br />
Me.Label8.Text = "City"<br />
"<br />
"Label6<br />
"<br />
Me.Label6.Anchor = System.Windows.Forms.AnchorStyles.None<br />
Me.Label6.AutoSize = True<br />
Me.Label6.Location = New System.Drawing.Point(31, 160)<br />
Me.Label6.Name = "Label6"<br />
Me.Label6.Size = New System.Drawing.Size(18, 13)<br />
Me.Label6.TabIndex = 52<br />
Me.Label6.Text = "Zip"<br />
"<br />
"cboState<br />
"<br />
Me.cboState.Anchor = System.Windows.Forms.AnchorStyles.Left<br />
Me.cboState.FormattingEnabled = True<br />
Me.cboState.Location = New System.Drawing.Point(83, 127)<br />
Me.cboState.Name = "cboState"<br />
Me.cboState.Size = New System.Drawing.Size(48, 21)<br />
Me.cboState.TabIndex = 54<br />
Me.ttHint.SetToolTip(Me.cboState, "Select the customer"s state.")<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(287, 197)<br />
Me.Controls.Add(Me.TableLayoutPanel1)<br />
Me.Name = "Form1"<br />
Me.Text = "UseToolTip"<br />
Me.TableLayoutPanel1.ResumeLayout(False)<br />
Me.TableLayoutPanel1.PerformLayout()<br />
Me.ResumeLayout(False)<br />
Me.PerformLayout()<br />
End Sub<br />
Friend WithEvents ttHint As System.Windows.Forms.ToolTip<br />
Friend WithEvents TableLayoutPanel1 As System.Windows.Forms.TableLayoutPanel<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
Friend WithEvents Label7 As System.Windows.Forms.Label<br />
Friend WithEvents Label2 As System.Windows.Forms.Label<br />
Friend WithEvents txtFirstName As System.Windows.Forms.TextBox<br />
Friend WithEvents txtLastName As System.Windows.Forms.TextBox<br />
Friend WithEvents txtStreet As System.Windows.Forms.TextBox<br />
Friend WithEvents Label3 As System.Windows.Forms.Label<br />
Friend WithEvents txtCity As System.Windows.Forms.TextBox<br />
Friend WithEvents txtZip As System.Windows.Forms.TextBox<br />
Friend WithEvents Label5 As System.Windows.Forms.Label<br />
Friend WithEvents Label8 As System.Windows.Forms.Label<br />
Friend WithEvents Label6 As System.Windows.Forms.Label<br />
Friend WithEvents cboState As System.Windows.Forms.ruboBox<br />
End Class</source><br />
<br />
==Set Tooltips for Label==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class FrmToolTip<br />
public Shared Sub Main<br />
Application.Run(New FrmToolTipDemonstration)<br />
End Sub<br />
End class<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Class FrmToolTipDemonstration<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.ruponents = New System.ruponentModel.Container<br />
Me.lblSecond = New System.Windows.Forms.Label<br />
Me.labelsToolTip = New System.Windows.Forms.ToolTip(Me.ruponents)<br />
Me.lblFirst = New System.Windows.Forms.Label<br />
Me.SuspendLayout()<br />
"<br />
"lblSecond<br />
"<br />
Me.lblSecond.AutoSize = True<br />
Me.lblSecond.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle<br />
Me.lblSecond.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.lblSecond.Location = New System.Drawing.Point(12, 73)<br />
Me.lblSecond.Name = "lblSecond"<br />
Me.lblSecond.Size = New System.Drawing.Size(147, 19)<br />
Me.lblSecond.TabIndex = 3<br />
Me.lblSecond.Tag = ""<br />
Me.lblSecond.Text = "This is another Label."<br />
Me.labelsToolTip.SetToolTip(Me.lblSecond, "Second Label")<br />
"<br />
"lblFirst<br />
"<br />
Me.lblFirst.AutoSize = True<br />
Me.lblFirst.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle<br />
Me.lblFirst.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.lblFirst.Location = New System.Drawing.Point(12, 24)<br />
Me.lblFirst.Name = "lblFirst"<br />
Me.lblFirst.Size = New System.Drawing.Size(101, 19)<br />
Me.lblFirst.TabIndex = 2<br />
Me.lblFirst.Text = "This is a label."<br />
Me.labelsToolTip.SetToolTip(Me.lblFirst, "First Label")<br />
"<br />
"FrmToolTipDemonstration<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(252, 124)<br />
Me.Controls.Add(Me.lblSecond)<br />
Me.Controls.Add(Me.lblFirst)<br />
Me.Name = "FrmToolTipDemonstration"<br />
Me.Text = "ToolTip Demonstration"<br />
Me.ResumeLayout(False)<br />
Me.PerformLayout()<br />
End Sub<br />
Friend WithEvents lblSecond As System.Windows.Forms.Label<br />
Friend WithEvents labelsToolTip As System.Windows.Forms.ToolTip<br />
Friend WithEvents lblFirst As System.Windows.Forms.Label<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/ComboBox&diff=3909
VB.Net Tutorial/GUI/ComboBox
2010-05-26T12:57:25Z
<p>Admin: 1 версия</p>
<hr />
<div>==Add value to ComboBox==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class ComboBoxAddSelection<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
Public Sub New()<br />
MyBase.New()<br />
InitializeComponent()<br />
End Sub<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
Private components As System.ruponentModel.IContainer<br />
Friend WithEvents ComboBox1 As System.Windows.Forms.ruboBox<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.ruboBox1 = New System.Windows.Forms.ruboBox<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.Label1 = New System.Windows.Forms.Label<br />
Me.SuspendLayout()<br />
"<br />
"ComboBox1<br />
"<br />
Me.ruboBox1.Items.AddRange(New Object() {"AAAAA", "BBBBB", "CCCCC"})<br />
Me.ruboBox1.Location = New System.Drawing.Point(48, 16)<br />
Me.ruboBox1.Name = "ComboBox1"<br />
Me.ruboBox1.Size = New System.Drawing.Size(144, 21)<br />
Me.ruboBox1.TabIndex = 0<br />
Me.ruboBox1.Text = "Select"<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(24, 64)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(96, 20)<br />
Me.TextBox1.TabIndex = 1<br />
Me.TextBox1.Text = ""<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(144, 64)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.Size = New System.Drawing.Size(96, 24)<br />
Me.Button1.TabIndex = 2<br />
Me.Button1.Text = "Add"<br />
"<br />
"Label1<br />
"<br />
Me.Label1.Location = New System.Drawing.Point(40, 120)<br />
Me.Label1.Name = "Label1"<br />
Me.Label1.Size = New System.Drawing.Size(168, 24)<br />
Me.Label1.TabIndex = 3<br />
Me.Label1.Text = "Select"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(264, 182)<br />
Me.Controls.Add(Me.Label1)<br />
Me.Controls.Add(Me.Button1)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.Controls.Add(Me.ruboBox1)<br />
Me.ResumeLayout(False)<br />
End Sub<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
ComboBox1.Items.Add(TextBox1.Text)<br />
TextBox1.Text = ""<br />
End Sub<br />
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged<br />
Select Case ComboBox1.SelectedIndex<br />
Case 0<br />
Label1.Text = "A"<br />
Case 1<br />
Label1.Text = "B"<br />
Case 2<br />
Label1.Text = "C"<br />
End Select<br />
End Sub<br />
End Class</source><br />
<br />
==ComboBox Cell renderer==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.XButton = New System.Windows.Forms.Button<br />
Me.ColorList = New System.Windows.Forms.ruboBox<br />
Me.SuspendLayout()<br />
"<br />
"XButton<br />
"<br />
Me.XButton.Location = New System.Drawing.Point(112, 24)<br />
Me.XButton.Name = "XButton"<br />
Me.XButton.Size = New System.Drawing.Size(75, 23)<br />
Me.XButton.TabIndex = 0<br />
Me.XButton.Text = "Button1"<br />
Me.XButton.UseVisualStyleBackColor = True<br />
"<br />
"ColorList<br />
"<br />
Me.ColorList.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed<br />
Me.ColorList.DropDownStyle = System.Windows.Forms.ruboBoxStyle.DropDownList<br />
Me.ColorList.FormattingEnabled = True<br />
Me.ColorList.Location = New System.Drawing.Point(88, 64)<br />
Me.ColorList.Name = "ColorList"<br />
Me.ColorList.Size = New System.Drawing.Size(121, 21)<br />
Me.ColorList.TabIndex = 1<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(292, 221)<br />
Me.Controls.Add(Me.ColorList)<br />
Me.Controls.Add(Me.XButton)<br />
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle<br />
Me.MaximizeBox = False<br />
Me.Name = "Form1"<br />
Me.Text = "Control Drawing"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
Friend WithEvents XButton As System.Windows.Forms.Button<br />
Friend WithEvents ColorList As System.Windows.Forms.ruboBox<br />
End Class<br />
Public Class Form1<br />
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load<br />
ColorList.Items.Add("Red")<br />
ColorList.Items.Add("Orange")<br />
ColorList.Items.Add("Yellow")<br />
ColorList.Items.Add("Green")<br />
ColorList.Items.Add("Blue")<br />
ColorList.Items.Add("Indigo")<br />
ColorList.Items.Add("Violet")<br />
End Sub<br />
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint<br />
e.Graphics.DrawEllipse(Pens.Black, 10, 10, Me.ClientRectangle.Width - 20, _<br />
Me.ClientRectangle.Height - 20)<br />
End Sub<br />
Private Sub XButton_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles XButton.Paint<br />
Dim usePen As Pen<br />
e.Graphics.Clear(SystemColors.Control)<br />
usePen = New Pen(SystemColors.ControlText, 3)<br />
e.Graphics.DrawRectangle(usePen, XButton.ClientRectangle)<br />
usePen.Dispose()<br />
End Sub<br />
Private Sub ColorList_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ColorList.DrawItem<br />
Dim useBrush As Brush<br />
If (e.Index = -1) Then Return<br />
e.DrawBackground()<br />
useBrush = New SolidBrush(Color.FromName(CStr(ColorList.Items(e.Index))))<br />
e.Graphics.FillRectangle(useBrush, _<br />
e.Bounds.Left + 2, e.Bounds.Top + 2, _<br />
e.Bounds.Width - 4, e.Bounds.Height - 4)<br />
useBrush.Dispose()<br />
e.Graphics.DrawRectangle(Pens.Black, _<br />
e.Bounds.Left + 2, e.Bounds.Top + 2, _<br />
e.Bounds.Width - 4, e.Bounds.Height - 4)<br />
e.DrawFocusRectangle()<br />
End Sub<br />
Private Sub XButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles XButton.Click<br />
MsgBox("Button clicked.")<br />
End Sub<br />
End Class<br />
public class ComboBoxCellRenderer<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class</source><br />
<br />
==ComboBox Selected Index Changed event==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class ComboBoxSelectionEventAddValue<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents ComboBox1 As System.Windows.Forms.ruboBox<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.ruboBox1 = New System.Windows.Forms.ruboBox<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.SuspendLayout()<br />
"<br />
"ComboBox1<br />
"<br />
Me.ruboBox1.Location = New System.Drawing.Point(72, 72)<br />
Me.ruboBox1.Name = "ComboBox1"<br />
Me.ruboBox1.Size = New System.Drawing.Size(121, 21)<br />
Me.ruboBox1.TabIndex = 0<br />
Me.ruboBox1.Text = "ComboBox1"<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(16, 168)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(256, 20)<br />
Me.TextBox1.TabIndex = 2<br />
Me.TextBox1.Text = ""<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(292, 273)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.Controls.Add(Me.ruboBox1)<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
For i As Integer = 0 To 10<br />
ComboBox1.Items.Add("Item " + i.ToString())<br />
Next<br />
ComboBox1.Text = "Choose one..."<br />
End Sub<br />
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged<br />
Dim intSelectedIndex As Integer<br />
intSelectedIndex = ComboBox1.SelectedIndex<br />
Dim objSelectedItem As Object<br />
objSelectedItem = ComboBox1.SelectedItem<br />
TextBox1.Text = "Item"s index: " & intSelectedIndex & _<br />
". Item"s text: " & objSelectedItem.ToString()<br />
End Sub<br />
End Class</source><br />
<br />
==ComboBox selection event and Add items==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class ComboBoxAddSelection<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
Public Sub New()<br />
MyBase.New()<br />
InitializeComponent()<br />
End Sub<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
Private components As System.ruponentModel.IContainer<br />
Friend WithEvents ComboBox1 As System.Windows.Forms.ruboBox<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.ruboBox1 = New System.Windows.Forms.ruboBox<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.Label1 = New System.Windows.Forms.Label<br />
Me.SuspendLayout()<br />
"<br />
"ComboBox1<br />
"<br />
Me.ruboBox1.Items.AddRange(New Object() {"AAAAA", "BBBBB", "CCCCC"})<br />
Me.ruboBox1.Location = New System.Drawing.Point(48, 16)<br />
Me.ruboBox1.Name = "ComboBox1"<br />
Me.ruboBox1.Size = New System.Drawing.Size(144, 21)<br />
Me.ruboBox1.TabIndex = 0<br />
Me.ruboBox1.Text = "Select"<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(24, 64)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(96, 20)<br />
Me.TextBox1.TabIndex = 1<br />
Me.TextBox1.Text = ""<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(144, 64)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.Size = New System.Drawing.Size(96, 24)<br />
Me.Button1.TabIndex = 2<br />
Me.Button1.Text = "Add"<br />
"<br />
"Label1<br />
"<br />
Me.Label1.Location = New System.Drawing.Point(40, 120)<br />
Me.Label1.Name = "Label1"<br />
Me.Label1.Size = New System.Drawing.Size(168, 24)<br />
Me.Label1.TabIndex = 3<br />
Me.Label1.Text = "Select"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(264, 182)<br />
Me.Controls.Add(Me.Label1)<br />
Me.Controls.Add(Me.Button1)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.Controls.Add(Me.ruboBox1)<br />
Me.ResumeLayout(False)<br />
End Sub<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
ComboBox1.Items.Add(TextBox1.Text)<br />
TextBox1.Text = ""<br />
End Sub<br />
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged<br />
Select Case ComboBox1.SelectedIndex<br />
Case 0<br />
Label1.Text = "A"<br />
Case 1<br />
Label1.Text = "B"<br />
Case 2<br />
Label1.Text = "C"<br />
End Select<br />
End Sub<br />
End Class</source><br />
<br />
==Get Text from ComboBox==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class GetComboBoxText<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Private Sub Button1_Click(ByVal sender As System.Object, _<br />
ByVal e As System.EventArgs) _<br />
Handles Button1.Click<br />
Dim Language As String<br />
Language = ComboBox1.Text<br />
If Language = "Visual Basic" Then<br />
MsgBox("We have a winner!")<br />
Else<br />
MsgBox(Language & " is not a bad language.")<br />
End If<br />
End Sub<br />
End Class<br />
Partial Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.Label1 = New System.Windows.Forms.Label<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.ruboBox1 = New System.Windows.Forms.ruboBox<br />
Me.SuspendLayout()<br />
"<br />
"Label1<br />
"<br />
Me.Label1.AutoSize = True<br />
Me.Label1.Location = New System.Drawing.Point(13, 22)<br />
Me.Label1.Name = "Label1"<br />
Me.Label1.Size = New System.Drawing.Size(160, 14)<br />
Me.Label1.TabIndex = 0<br />
Me.Label1.Text = "What"s your favorite language?"<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(13, 70)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.Size = New System.Drawing.Size(267, 23)<br />
Me.Button1.TabIndex = 2<br />
Me.Button1.Text = "Evaluate my choice"<br />
"<br />
"ComboBox1<br />
"<br />
Me.ruboBox1.FormattingEnabled = True<br />
Me.ruboBox1.Items.AddRange(New Object() {"C++", "C#", "Java", "Visual Basic", "Cobol"})<br />
Me.ruboBox1.Location = New System.Drawing.Point(13, 43)<br />
Me.ruboBox1.Name = "ComboBox1"<br />
Me.ruboBox1.Size = New System.Drawing.Size(267, 21)<br />
Me.ruboBox1.TabIndex = 1<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(292, 117)<br />
Me.Controls.Add(Me.ruboBox1)<br />
Me.Controls.Add(Me.Button1)<br />
Me.Controls.Add(Me.Label1)<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.ResumeLayout(False)<br />
Me.PerformLayout()<br />
End Sub<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents ComboBox1 As System.Windows.Forms.ruboBox<br />
End Class</source><br />
<br />
==HatchBrush Illustration by using ComboBox==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System<br />
Imports System.Drawing<br />
Imports System.Collections<br />
Imports System.ruponentModel<br />
Imports System.Windows.Forms<br />
Imports System.Data<br />
Imports System.Drawing.Drawing2D<br />
public class HatchBrushStyleComboBox<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
Private style As New HatchStyle<br />
Private forClr As Color = Color.Blue<br />
Private backClr As Color = Color.Red<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
Friend WithEvents ComboBox1 As System.Windows.Forms.ruboBox<br />
Friend WithEvents Label2 As System.Windows.Forms.Label<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
Friend WithEvents Label3 As System.Windows.Forms.Label<br />
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox<br />
Friend WithEvents ForColorBtn As System.Windows.Forms.Button<br />
Friend WithEvents BackGroundBtn As System.Windows.Forms.Button<br />
Friend WithEvents ApplyBtn As System.Windows.Forms.Button<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.Label1 = New System.Windows.Forms.Label<br />
Me.ruboBox1 = New System.Windows.Forms.ruboBox<br />
Me.Label2 = New System.Windows.Forms.Label<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.Label3 = New System.Windows.Forms.Label<br />
Me.TextBox2 = New System.Windows.Forms.TextBox<br />
Me.ForColorBtn = New System.Windows.Forms.Button<br />
Me.BackGroundBtn = New System.Windows.Forms.Button<br />
Me.ApplyBtn = New System.Windows.Forms.Button<br />
Me.SuspendLayout()<br />
"<br />
"Label1<br />
"<br />
Me.Label1.Location = New System.Drawing.Point(8, 8)<br />
Me.Label1.Name = "Label1"<br />
Me.Label1.Size = New System.Drawing.Size(72, 23)<br />
Me.Label1.TabIndex = 0<br />
Me.Label1.Text = "Select Style:"<br />
"<br />
"ComboBox1<br />
"<br />
Me.ruboBox1.Location = New System.Drawing.Point(96, 8)<br />
Me.ruboBox1.Name = "ComboBox1"<br />
Me.ruboBox1.Size = New System.Drawing.Size(121, 21)<br />
Me.ruboBox1.TabIndex = 1<br />
Me.ruboBox1.Text = "ComboBox1"<br />
"<br />
"Label2<br />
"<br />
Me.Label2.Location = New System.Drawing.Point(8, 40)<br />
Me.Label2.Name = "Label2"<br />
Me.Label2.Size = New System.Drawing.Size(96, 23)<br />
Me.Label2.TabIndex = 2<br />
Me.Label2.Text = "Forground Color:"<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle<br />
Me.TextBox1.Location = New System.Drawing.Point(112, 40)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.ReadOnly = True<br />
Me.TextBox1.Size = New System.Drawing.Size(32, 20)<br />
Me.TextBox1.TabIndex = 3<br />
Me.TextBox1.Text = ""<br />
"<br />
"Label3<br />
"<br />
Me.Label3.Location = New System.Drawing.Point(0, 72)<br />
Me.Label3.Name = "Label3"<br />
Me.Label3.Size = New System.Drawing.Size(104, 23)<br />
Me.Label3.TabIndex = 4<br />
Me.Label3.Text = "Background Color:"<br />
"<br />
"TextBox2<br />
"<br />
Me.TextBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle<br />
Me.TextBox2.Location = New System.Drawing.Point(112, 72)<br />
Me.TextBox2.Name = "TextBox2"<br />
Me.TextBox2.ReadOnly = True<br />
Me.TextBox2.Size = New System.Drawing.Size(32, 20)<br />
Me.TextBox2.TabIndex = 5<br />
Me.TextBox2.Text = ""<br />
"<br />
"ForColorBtn<br />
"<br />
Me.ForColorBtn.Location = New System.Drawing.Point(152, 40)<br />
Me.ForColorBtn.Name = "ForColorBtn"<br />
Me.ForColorBtn.Size = New System.Drawing.Size(48, 23)<br />
Me.ForColorBtn.TabIndex = 6<br />
Me.ForColorBtn.Text = "Pick..."<br />
"<br />
"BackGroundBtn<br />
"<br />
Me.BackGroundBtn.Location = New System.Drawing.Point(152, 72)<br />
Me.BackGroundBtn.Name = "BackGroundBtn"<br />
Me.BackGroundBtn.Size = New System.Drawing.Size(48, 23)<br />
Me.BackGroundBtn.TabIndex = 7<br />
Me.BackGroundBtn.Text = "Pic..."<br />
"<br />
"ApplyBtn<br />
"<br />
Me.ApplyBtn.Location = New System.Drawing.Point(224, 72)<br />
Me.ApplyBtn.Name = "ApplyBtn"<br />
Me.ApplyBtn.TabIndex = 8<br />
Me.ApplyBtn.Text = "Apply"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(416, 325)<br />
Me.Controls.Add(Me.ApplyBtn)<br />
Me.Controls.Add(Me.BackGroundBtn)<br />
Me.Controls.Add(Me.ForColorBtn)<br />
Me.Controls.Add(Me.TextBox2)<br />
Me.Controls.Add(Me.Label3)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.Controls.Add(Me.Label2)<br />
Me.Controls.Add(Me.ruboBox1)<br />
Me.Controls.Add(Me.Label1)<br />
Me.Name = "Form1"<br />
Me.Text = "Hatch Brushes"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
FillHatchStyles()<br />
End Sub<br />
Private Sub FillHatchStyles()<br />
comboBox1.Items.Add(HatchStyle.BackwardDiagonal.ToString())<br />
comboBox1.Items.Add(HatchStyle.Cross.ToString())<br />
comboBox1.Items.Add(HatchStyle.DashedVertical.ToString())<br />
comboBox1.Items.Add(HatchStyle.DiagonalCross.ToString())<br />
comboBox1.Items.Add(HatchStyle.HorizontalBrick.ToString())<br />
comboBox1.Items.Add(HatchStyle.LightDownwardDiagonal.ToString())<br />
comboBox1.Items.Add(HatchStyle.LightUpwardDiagonal.ToString())<br />
comboBox1.Text = HatchStyle.BackwardDiagonal.ToString()<br />
End Sub "FillHatchStyles<br />
<br />
Private Sub ApplyBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ApplyBtn.Click<br />
Dim g As Graphics = Me.CreateGraphics()<br />
g.Clear(Me.BackColor)<br />
Dim str As String = ComboBox1.Text<br />
Select Case str<br />
Case "BackwardDiagonal"<br />
style = HatchStyle.BackwardDiagonal<br />
Case "DashedVertical"<br />
style = HatchStyle.DashedVertical<br />
Case "Cross"<br />
style = HatchStyle.Cross<br />
Case "DiagonalCross"<br />
style = HatchStyle.DiagonalCross<br />
Case "HorizontalBrick"<br />
style = HatchStyle.HorizontalBrick<br />
Case "LightDownwardDiagonal"<br />
style = HatchStyle.LightDownwardDiagonal<br />
Case "LightUpwardDiagonal"<br />
style = HatchStyle.LightUpwardDiagonal<br />
Case Else<br />
End Select<br />
Dim brush As New HatchBrush(style, forClr, backClr)<br />
g.FillRectangle(brush, 50, 100, 200, 200)<br />
brush.Dispose()<br />
g.Dispose()<br />
End Sub<br />
End Class</source><br />
<br />
==Set text for ComboBox==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class ComboBoxSelectionEventAddValue<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents ComboBox1 As System.Windows.Forms.ruboBox<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.ruboBox1 = New System.Windows.Forms.ruboBox<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.SuspendLayout()<br />
"<br />
"ComboBox1<br />
"<br />
Me.ruboBox1.Location = New System.Drawing.Point(72, 72)<br />
Me.ruboBox1.Name = "ComboBox1"<br />
Me.ruboBox1.Size = New System.Drawing.Size(121, 21)<br />
Me.ruboBox1.TabIndex = 0<br />
Me.ruboBox1.Text = "ComboBox1"<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(16, 168)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(256, 20)<br />
Me.TextBox1.TabIndex = 2<br />
Me.TextBox1.Text = ""<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(292, 273)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.Controls.Add(Me.ruboBox1)<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
For i As Integer = 0 To 10<br />
ComboBox1.Items.Add("Item " + i.ToString())<br />
Next<br />
ComboBox1.Text = "Choose one..."<br />
End Sub<br />
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged<br />
Dim intSelectedIndex As Integer<br />
intSelectedIndex = ComboBox1.SelectedIndex<br />
Dim objSelectedItem As Object<br />
objSelectedItem = ComboBox1.SelectedItem<br />
TextBox1.Text = "Item"s index: " & intSelectedIndex & _<br />
". Item"s text: " & objSelectedItem.ToString()<br />
End Sub<br />
End Class</source><br />
<br />
==Use ComboBox to control TextBox font color==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class ComboBoxSelectionEvent<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged<br />
Select Case ComboBox1.SelectedIndex<br />
Case 0<br />
TextBox1.ForeColor = System.Drawing.Color.Yellow<br />
Case 1<br />
TextBox1.ForeColor = System.Drawing.Color.Red<br />
Case 2<br />
TextBox1.ForeColor = System.Drawing.Color.Blue<br />
Case 3<br />
TextBox1.ForeColor = System.Drawing.Color.Black<br />
End Select<br />
End Sub<br />
End Class<br />
<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.ruboBox1 = New System.Windows.Forms.ruboBox<br />
Me.Label1 = New System.Windows.Forms.Label<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.SuspendLayout()<br />
"<br />
"ComboBox1<br />
"<br />
Me.ruboBox1.DropDownStyle = System.Windows.Forms.ruboBoxStyle.DropDownList<br />
Me.ruboBox1.FormattingEnabled = True<br />
Me.ruboBox1.Items.AddRange(New Object() {"Yellow", "Red", "Blue", "Black"})<br />
Me.ruboBox1.Location = New System.Drawing.Point(19, 30)<br />
Me.ruboBox1.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4)<br />
Me.ruboBox1.Name = "ComboBox1"<br />
Me.ruboBox1.Size = New System.Drawing.Size(476, 23)<br />
Me.ruboBox1.TabIndex = 0<br />
"<br />
"Label1<br />
"<br />
Me.Label1.AutoSize = True<br />
Me.Label1.Location = New System.Drawing.Point(16, 11)<br />
Me.Label1.Margin = New System.Windows.Forms.Padding(4, 0, 4, 0)<br />
Me.Label1.Name = "Label1"<br />
Me.Label1.Size = New System.Drawing.Size(67, 15)<br />
Me.Label1.TabIndex = 1<br />
Me.Label1.Text = "Color"<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(16, 62)<br />
Me.TextBox1.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4)<br />
Me.TextBox1.Multiline = True<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(479, 169)<br />
Me.TextBox1.TabIndex = 2<br />
Me.TextBox1.Text = "www.vbex.ru"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 15.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(513, 242)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.Controls.Add(Me.Label1)<br />
Me.Controls.Add(Me.ruboBox1)<br />
Me.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4)<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.ResumeLayout(False)<br />
Me.PerformLayout()<br />
End Sub<br />
Friend WithEvents ComboBox1 As System.Windows.Forms.ruboBox<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
End Class</source><br />
<br />
==Using ComboBox to select shape to draw==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class DrawShapes<br />
public Shared Sub Main<br />
Application.Run(New FrmComboBox)<br />
End Sub<br />
End class<br />
Public Class FrmComboBox<br />
Inherits Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
" contains shape list (circle, square, ellipse, pie) <br />
Friend WithEvents cboImage As System.Windows.Forms.ruboBox<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.Container<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.cboImage = New System.Windows.Forms.ruboBox()<br />
Me.SuspendLayout()<br />
"<br />
"cboImage<br />
"<br />
Me.cboImage.DropDownWidth = 121<br />
Me.cboImage.Items.AddRange(New Object() {"Circle", "Square", "Ellipse", "Pie", "Filled Circle", "Filled Square", "Filled Ellipse", "Filled Pie"})<br />
Me.cboImage.Location = New System.Drawing.Point(24, 16)<br />
Me.cboImage.Name = "cboImage"<br />
Me.cboImage.Size = New System.Drawing.Size(121, 21)<br />
Me.cboImage.TabIndex = 0<br />
"<br />
"FrmComboBox<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(292, 273)<br />
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.cboImage})<br />
Me.Name = "FrmComboBox"<br />
Me.Text = "ComboBoxTest"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub cboImage_SelectedIndexChanged _<br />
(ByVal sender As System.Object, _<br />
ByVal e As System.EventArgs) _<br />
Handles cboImage.SelectedIndexChanged<br />
Dim myGraphics As Graphics = MyBase.CreateGraphics()<br />
Dim myPen As New Pen(Color.DarkRed)<br />
Dim mySolidBrush As New SolidBrush(Color.DarkRed)<br />
myGraphics.Clear(Color.White)<br />
Select Case cboImage.SelectedIndex<br />
Case 0 " case circle is selected<br />
myGraphics.DrawEllipse(myPen, 50, 50, 150, 150)<br />
Case 1 <br />
myGraphics.DrawRectangle(myPen, 50, 50, 150, 150)<br />
Case 2 <br />
myGraphics.DrawEllipse(myPen, 50, 85, 150, 115)<br />
Case 3 <br />
myGraphics.DrawPie(myPen, 50, 50, 150, 150, 0, 45)<br />
Case 4 <br />
myGraphics.FillEllipse(mySolidBrush, 50, 50, 150, 150)<br />
Case 5 <br />
myGraphics.FillRectangle(mySolidBrush, 50, 50, 150, 150)<br />
Case 6 <br />
myGraphics.FillEllipse(mySolidBrush, 50, 85, 150, 115)<br />
Case 7 <br />
myGraphics.FillPie(mySolidBrush, 50, 50, 150, 150, 0, 45)<br />
End Select<br />
End Sub<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/Printers&diff=3903
VB.Net Tutorial/GUI/Printers
2010-05-26T12:57:24Z
<p>Admin: 1 версия</p>
<hr />
<div>==Add a printer process==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Environment<br />
Imports System.Net<br />
<br />
Public Class Tester<br />
Public Shared Sub Main<br />
Dim proc As New System.Diagnostics.Process()<br />
Dim SystemDir As String = System.Environment.SystemDirectory<br />
proc.Start("rundll32.exe", "shell32.dll,SHHelpShortcuts_RunDLL AddPrinter")<br />
End Sub<br />
End Class</source><br />
<br />
==Get installed printers==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class GetInstalledPrinters<br />
public Shared Sub Main<br />
Dim PrinterName As String<br />
For Each PrinterName In System.Drawing.Printing.PrinterSettings.InstalledPrinters<br />
Console.WriteLine(PrinterName)<br />
Next<br />
End Sub<br />
End class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/PageSetupDialog&diff=3905
VB.Net Tutorial/GUI/PageSetupDialog
2010-05-26T12:57:24Z
<p>Admin: 1 версия</p>
<hr />
<div>==Print setup Dialog==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing.Printing<br />
Imports System.Windows.Forms<br />
public class PageSetupDialogDemo<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<br />
Public Class Form1<br />
Private Sub btnShowDialog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowDialog.Click<br />
PageSetupDialog1.Document = New PrintDocument<br />
If PageSetupDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then<br />
"...<br />
End If<br />
End Sub<br />
End Class<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.btnShowDialog = New System.Windows.Forms.Button<br />
Me.PageSetupDialog1 = New System.Windows.Forms.PageSetupDialog<br />
Me.SuspendLayout()<br />
"<br />
"btnShowDialog<br />
"<br />
Me.btnShowDialog.Location = New System.Drawing.Point(104, 56)<br />
Me.btnShowDialog.Name = "btnShowDialog"<br />
Me.btnShowDialog.Size = New System.Drawing.Size(80, 24)<br />
Me.btnShowDialog.TabIndex = 2<br />
Me.btnShowDialog.Text = "Show Dialog"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(292, 140)<br />
Me.Controls.Add(Me.btnShowDialog)<br />
Me.Name = "Form1"<br />
Me.Text = "UsePageSetupDIalog"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
Friend WithEvents btnShowDialog As System.Windows.Forms.Button<br />
Friend WithEvents PageSetupDialog1 As System.Windows.Forms.PageSetupDialog<br />
End Class</source><br />
<br />
==Show PageSetupDialog and display the settings==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.IO<br />
Imports System.Windows.Forms<br />
public class PageSetupDialogSettings<br />
public Shared Sub Main<br />
Dim PageDB As New PageSetupDialog()<br />
PageDB.Document = New System.Drawing.Printing.PrintDocument()<br />
If (PageDB.ShowDialog() = DialogResult.OK) Then<br />
Console.WriteLine("Allow Margins: " & PageDB.AllowMargins)<br />
Console.WriteLine("Allow Orientation: " & PageDB.AllowOrientation)<br />
Console.WriteLine("Allow Paper: " & PageDB.AllowPaper)<br />
Console.WriteLine("Allow Printer: " & PageDB.AllowPrinter)<br />
Console.WriteLine("Minimum Margins: " & PageDB.MinMargins.ToString())<br />
Console.WriteLine("Show Network: " & PageDB.ShowNetwork)<br />
Console.WriteLine("Printer Settings: " & PageDB.PrinterSettings.ToString())<br />
End If<br />
End Sub<br />
End class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/PopupMenu&diff=3907
VB.Net Tutorial/GUI/PopupMenu
2010-05-26T12:57:24Z
<p>Admin: 1 версия</p>
<hr />
<div>==Add popup menu to Form==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class ShortcurMenu<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<br />
Public Class Form1<br />
Private Sub MenuHello_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuHello.Click<br />
MsgBox("Hello")<br />
End Sub<br />
Private Sub MenuGoodbye_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuGoodbye.Click<br />
MsgBox("Goodbye")<br />
End Sub<br />
End Class<br />
<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.ruponents = New System.ruponentModel.Container<br />
Me.MainShortcutMenu = New System.Windows.Forms.ContextMenuStrip(Me.ruponents)<br />
Me.MenuHello = New System.Windows.Forms.ToolStripMenuItem<br />
Me.MenuGoodbye = New System.Windows.Forms.ToolStripMenuItem<br />
Me.MainShortcutMenu.SuspendLayout()<br />
Me.SuspendLayout()<br />
"<br />
"MainShortcutMenu<br />
"<br />
Me.MainShortcutMenu.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.MenuHello, Me.MenuGoodbye})<br />
Me.MainShortcutMenu.Name = "MainShortcutMenu"<br />
Me.MainShortcutMenu.Size = New System.Drawing.Size(139, 48)<br />
"<br />
"MenuHello<br />
"<br />
Me.MenuHello.Name = "MenuHello"<br />
Me.MenuHello.Size = New System.Drawing.Size(138, 22)<br />
Me.MenuHello.Text = "Say Hello"<br />
"<br />
"MenuGoodbye<br />
"<br />
Me.MenuGoodbye.Name = "MenuGoodbye"<br />
Me.MenuGoodbye.Size = New System.Drawing.Size(138, 22)<br />
Me.MenuGoodbye.Text = "Say Goodbye"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(292, 126)<br />
Me.ContextMenuStrip = Me.MainShortcutMenu<br />
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle<br />
Me.MaximizeBox = False<br />
Me.Name = "Form1"<br />
Me.Text = "Shortcut Menus"<br />
Me.MainShortcutMenu.ResumeLayout(False)<br />
Me.ResumeLayout(False)<br />
End Sub<br />
Friend WithEvents MainShortcutMenu As System.Windows.Forms.ContextMenuStrip<br />
Friend WithEvents MenuHello As System.Windows.Forms.ToolStripMenuItem<br />
Friend WithEvents MenuGoodbye As System.Windows.Forms.ToolStripMenuItem<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/FolderBrowserDialog&diff=3895
VB.Net Tutorial/GUI/FolderBrowserDialog
2010-05-26T12:57:23Z
<p>Admin: 1 версия</p>
<hr />
<div>==Get the SelectedPath FolderBrowserDialog==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
Public Class Tester<br />
Public Shared Sub Main<br />
Dim DirectoryBrowser As System.Windows.Forms.FolderBrowserDialog<br />
DirectoryBrowser = New System.Windows.Forms.FolderBrowserDialog<br />
DirectoryBrowser.Description = "Which directory do you want to use?"<br />
If (DirectoryBrowser.ShowDialog() = Windows.Forms.DialogResult.OK) Then<br />
Console.WriteLine(DirectoryBrowser.SelectedPath)<br />
End If<br />
End Sub<br />
End Class</source><br />
<br />
==Set Properties for FolderBrowserDialog==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class FolderBrowserDialogProperty<br />
public Shared Sub Main<br />
Dim FolderBrowserDialog1 As FolderBrowserDialog = New System.Windows.Forms.FolderBrowserDialog<br />
With FolderBrowserDialog1<br />
.RootFolder = Environment.SpecialFolder.rumonProgramFiles<br />
.SelectedPath = "C:\Temp"<br />
.ShowNewFolderButton = False<br />
.Description = "Use the tree below to select a folder:"<br />
End With<br />
If FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then<br />
Console.WriteLine(FolderBrowserDialog1.SelectedPath)<br />
End If<br />
End Sub<br />
End class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/Visual_Inheritance&diff=3897
VB.Net Tutorial/GUI/Visual Inheritance
2010-05-26T12:57:23Z
<p>Admin: 1 версия</p>
<hr />
<div>==Form template for use with visual inheritance==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class FormInheritance<br />
public Shared Sub Main<br />
Application.Run(New FrmInheritance)<br />
End Sub<br />
End class<br />
<br />
Public Class FrmInheritance<br />
Inherits Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
Friend WithEvents lblText As System.Windows.Forms.Label<br />
Friend WithEvents lblCopyright As System.Windows.Forms.Label<br />
Friend WithEvents cmdLearn As System.Windows.Forms.Button<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.Container<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.lblCopyright = New System.Windows.Forms.Label()<br />
Me.cmdLearn = New System.Windows.Forms.Button()<br />
Me.lblText = New System.Windows.Forms.Label()<br />
Me.SuspendLayout()<br />
"<br />
"lblCopyright<br />
"<br />
Me.lblCopyright.BackColor = System.Drawing.Color.LightYellow<br />
Me.lblCopyright.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D<br />
Me.lblCopyright.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.lblCopyright.ForeColor = System.Drawing.Color.MidnightBlue<br />
Me.lblCopyright.Location = New System.Drawing.Point(20, 178)<br />
Me.lblCopyright.Name = "lblCopyright"<br />
Me.lblCopyright.Size = New System.Drawing.Size(318, 29)<br />
Me.lblCopyright.TabIndex = 1<br />
Me.lblCopyright.Text = "Copyright 2002"<br />
"<br />
"cmdLearn<br />
"<br />
Me.cmdLearn.BackColor = System.Drawing.Color.Snow<br />
Me.cmdLearn.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.cmdLearn.ForeColor = System.Drawing.SystemColors.InfoText<br />
Me.cmdLearn.Location = New System.Drawing.Point(20, 99)<br />
Me.cmdLearn.Name = "cmdLearn"<br />
Me.cmdLearn.Size = New System.Drawing.Size(144, 59)<br />
Me.cmdLearn.TabIndex = 2<br />
Me.cmdLearn.Text = "Learn More"<br />
"<br />
"lblText<br />
"<br />
Me.lblText.BackColor = System.Drawing.Color.LightYellow<br />
Me.lblText.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D<br />
Me.lblText.Font = New System.Drawing.Font("Microsoft Sans Serif", 20.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.lblText.ForeColor = System.Drawing.Color.MidnightBlue<br />
Me.lblText.Location = New System.Drawing.Point(20, 20)<br />
Me.lblText.Name = "lblText"<br />
Me.lblText.Size = New System.Drawing.Size(318, 59)<br />
Me.lblText.TabIndex = 0<br />
Me.lblText.Text = "Text"<br />
Me.lblText.TextAlign = System.Drawing.ContentAlignment.MiddleCenter<br />
"<br />
"FrmInheritance<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15)<br />
Me.BackColor = System.Drawing.SystemColors.ActiveBorder<br />
Me.ClientSize = New System.Drawing.Size(358, 223)<br />
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.cmdLearn, Me.lblCopyright, Me.lblText})<br />
Me.Name = "FrmInheritance"<br />
Me.Text = "Visual Inheritance"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
" invoked when user presses Learn More button<br />
Private Sub cmdLearn_Click(ByVal sender As System.Object, _<br />
ByVal e As System.EventArgs) Handles cmdLearn.Click<br />
MessageBox.Show("Message", "Title", MessageBoxButtons.OK, _<br />
MessageBoxIcon.Information)<br />
End Sub " cmdLearn_Click<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/ToolBar&diff=3899
VB.Net Tutorial/GUI/ToolBar
2010-05-26T12:57:23Z
<p>Admin: 1 версия</p>
<hr />
<div>==Add action listener to buttons on a ToolBar==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class ToolBarMenu<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu<br />
Friend WithEvents mnuEdit As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuEditCut As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuEditCopy As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuEditPaste As System.Windows.Forms.MenuItem<br />
Friend WithEvents txtEdit As System.Windows.Forms.TextBox<br />
Friend WithEvents ContextMenu1 As System.Windows.Forms.ContextMenu<br />
Friend WithEvents MenuItem7 As System.Windows.Forms.MenuItem<br />
Friend WithEvents ImageList1 As System.Windows.Forms.ImageList<br />
Friend WithEvents ToolBarButton1 As System.Windows.Forms.ToolBarButton<br />
Friend WithEvents ToolBarButton2 As System.Windows.Forms.ToolBarButton<br />
Friend WithEvents ToolBarButton3 As System.Windows.Forms.ToolBarButton<br />
Friend WithEvents ToolBar1 As System.Windows.Forms.ToolBar<br />
Friend WithEvents cmnuCut As System.Windows.Forms.MenuItem<br />
Friend WithEvents cmnuCopy As System.Windows.Forms.MenuItem<br />
Friend WithEvents cmnuPaste As System.Windows.Forms.MenuItem<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.ruponents = New System.ruponentModel.Container()<br />
Me.MainMenu1 = New System.Windows.Forms.MainMenu()<br />
Me.mnuEdit = New System.Windows.Forms.MenuItem()<br />
Me.mnuEditCut = New System.Windows.Forms.MenuItem()<br />
Me.mnuEditCopy = New System.Windows.Forms.MenuItem()<br />
Me.mnuEditPaste = New System.Windows.Forms.MenuItem()<br />
Me.txtEdit = New System.Windows.Forms.TextBox()<br />
Me.ContextMenu1 = New System.Windows.Forms.ContextMenu()<br />
Me.cmnuCut = New System.Windows.Forms.MenuItem()<br />
Me.cmnuCopy = New System.Windows.Forms.MenuItem()<br />
Me.cmnuPaste = New System.Windows.Forms.MenuItem()<br />
Me.MenuItem7 = New System.Windows.Forms.MenuItem()<br />
Me.ImageList1 = New System.Windows.Forms.ImageList(Me.ruponents)<br />
Me.ToolBarButton1 = New System.Windows.Forms.ToolBarButton()<br />
Me.ToolBarButton2 = New System.Windows.Forms.ToolBarButton()<br />
Me.ToolBarButton3 = New System.Windows.Forms.ToolBarButton()<br />
Me.ToolBar1 = New System.Windows.Forms.ToolBar()<br />
Me.SuspendLayout()<br />
"<br />
"MainMenu1<br />
"<br />
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuEdit})<br />
"<br />
"mnuEdit<br />
"<br />
Me.mnuEdit.Index = 0<br />
Me.mnuEdit.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuEditCut, Me.mnuEditCopy, Me.mnuEditPaste})<br />
Me.mnuEdit.Text = "&Edit"<br />
"<br />
"mnuEditCut<br />
"<br />
Me.mnuEditCut.Index = 0<br />
Me.mnuEditCut.Shortcut = System.Windows.Forms.Shortcut.CtrlX<br />
Me.mnuEditCut.Text = "Cu&t"<br />
"<br />
"mnuEditCopy<br />
"<br />
Me.mnuEditCopy.Index = 1<br />
Me.mnuEditCopy.Shortcut = System.Windows.Forms.Shortcut.CtrlC<br />
Me.mnuEditCopy.Text = "&Copy"<br />
"<br />
"mnuEditPaste<br />
"<br />
Me.mnuEditPaste.Index = 2<br />
Me.mnuEditPaste.Shortcut = System.Windows.Forms.Shortcut.CtrlV<br />
Me.mnuEditPaste.Text = "&Paste"<br />
"<br />
"txtEdit<br />
"<br />
Me.txtEdit.ContextMenu = Me.ContextMenu1<br />
Me.txtEdit.Location = New System.Drawing.Point(0, 24)<br />
Me.txtEdit.Multiline = True<br />
Me.txtEdit.Name = "txtEdit"<br />
Me.txtEdit.ScrollBars = System.Windows.Forms.ScrollBars.Both<br />
Me.txtEdit.Size = New System.Drawing.Size(248, 176)<br />
Me.txtEdit.TabIndex = 0<br />
Me.txtEdit.Text = ""<br />
"<br />
"ContextMenu1<br />
"<br />
Me.ContextMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.cmnuCut, Me.cmnuCopy, Me.cmnuPaste})<br />
"<br />
"cmnuCut<br />
"<br />
Me.cmnuCut.Index = 0<br />
Me.cmnuCut.Text = "Cut"<br />
"<br />
"cmnuCopy<br />
"<br />
Me.cmnuCopy.Index = 1<br />
Me.cmnuCopy.Text = "Copy"<br />
"<br />
"cmnuPaste<br />
"<br />
Me.cmnuPaste.Index = 2<br />
Me.cmnuPaste.Text = "Paste"<br />
"<br />
"MenuItem7<br />
"<br />
Me.MenuItem7.Index = -1<br />
Me.MenuItem7.Text = ""<br />
"<br />
"ToolBarButton1<br />
"<br />
Me.ToolBarButton1.ImageIndex = 0<br />
"<br />
"ToolBarButton2<br />
"<br />
Me.ToolBarButton2.ImageIndex = 1<br />
"<br />
"ToolBarButton3<br />
"<br />
Me.ToolBarButton3.ImageIndex = 2<br />
"<br />
"ToolBar1<br />
"<br />
Me.ToolBar1.Buttons.AddRange(New System.Windows.Forms.ToolBarButton() {Me.ToolBarButton1, Me.ToolBarButton2, Me.ToolBarButton3})<br />
Me.ToolBar1.ButtonSize = New System.Drawing.Size(23, 22)<br />
Me.ToolBar1.DropDownArrows = True<br />
Me.ToolBar1.Name = "ToolBar1"<br />
Me.ToolBar1.ShowToolTips = True<br />
Me.ToolBar1.Size = New System.Drawing.Size(248, 25)<br />
Me.ToolBar1.TabIndex = 1<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(248, 201)<br />
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.ToolBar1, Me.txtEdit})<br />
Me.Menu = Me.MainMenu1<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick<br />
Select Case ToolBar1.Buttons.IndexOf(e.Button)<br />
Case 0<br />
mnuEditCut_Click(sender, e)<br />
Case 1<br />
mnuEditCopy_Click(sender, e)<br />
Case 2<br />
mnuEditPaste_Click(sender, e)<br />
End Select<br />
End Sub<br />
Private Sub mnuEditCut_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuEditCut.Click, cmnuCut.Click<br />
txtEdit.Cut()<br />
End Sub<br />
Private Sub mnuEditCopy_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuEditCopy.Click, cmnuCopy.Click<br />
txtEdit.Copy()<br />
End Sub<br />
<br />
Private Sub mnuEditPaste_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuEditPaste.Click, cmnuPaste.Click<br />
txtEdit.Paste()<br />
End Sub<br />
End Class</source><br />
<br />
==Button, Menu, ComboBox on ToolBar==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class ToolBarButtonComboBox<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents ToolBar1 As System.Windows.Forms.ToolBar<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
Friend WithEvents ToolBarButton1 As System.Windows.Forms.ToolBarButton<br />
Friend WithEvents ToolBarButton2 As System.Windows.Forms.ToolBarButton<br />
Friend WithEvents ToolBarButton3 As System.Windows.Forms.ToolBarButton<br />
Friend WithEvents ContextMenu1 As System.Windows.Forms.ContextMenu<br />
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem<br />
Friend WithEvents ToolBarButton4 As System.Windows.Forms.ToolBarButton<br />
Friend WithEvents ToolBarButton5 As System.Windows.Forms.ToolBarButton<br />
Friend WithEvents ToolBarButton6 As System.Windows.Forms.ToolBarButton<br />
Friend WithEvents ComboBox1 As System.Windows.Forms.ruboBox<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.ToolBar1 = New System.Windows.Forms.ToolBar<br />
Me.Label1 = New System.Windows.Forms.Label<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.ToolBarButton1 = New System.Windows.Forms.ToolBarButton<br />
Me.ToolBarButton2 = New System.Windows.Forms.ToolBarButton<br />
Me.ToolBarButton3 = New System.Windows.Forms.ToolBarButton<br />
Me.ContextMenu1 = New System.Windows.Forms.ContextMenu<br />
Me.MenuItem1 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem2 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem3 = New System.Windows.Forms.MenuItem<br />
Me.ToolBarButton4 = New System.Windows.Forms.ToolBarButton<br />
Me.ToolBarButton5 = New System.Windows.Forms.ToolBarButton<br />
Me.ToolBarButton6 = New System.Windows.Forms.ToolBarButton<br />
Me.ruboBox1 = New System.Windows.Forms.ruboBox<br />
Me.SuspendLayout()<br />
"<br />
"ToolBar1<br />
"<br />
Me.ToolBar1.Buttons.AddRange(New System.Windows.Forms.ToolBarButton() {Me.ToolBarButton1, Me.ToolBarButton2, Me.ToolBarButton3, Me.ToolBarButton4, Me.ToolBarButton5, Me.ToolBarButton6})<br />
Me.ToolBar1.DropDownArrows = True<br />
Me.ToolBar1.Location = New System.Drawing.Point(0, 0)<br />
Me.ToolBar1.Name = "ToolBar1"<br />
Me.ToolBar1.ShowToolTips = True<br />
Me.ToolBar1.Size = New System.Drawing.Size(368, 42)<br />
Me.ToolBar1.TabIndex = 0<br />
"<br />
"Label1<br />
"<br />
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 24.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.Label1.Location = New System.Drawing.Point(0, 48)<br />
Me.Label1.Name = "Label1"<br />
Me.Label1.Size = New System.Drawing.Size(160, 40)<br />
Me.Label1.TabIndex = 1<br />
Me.Label1.Text = "Toolbars"<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(72, 136)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(152, 20)<br />
Me.TextBox1.TabIndex = 2<br />
Me.TextBox1.Text = ""<br />
"<br />
"ToolBarButton1<br />
"<br />
Me.ToolBarButton1.Text = "Button 1"<br />
"<br />
"ToolBarButton2<br />
"<br />
Me.ToolBarButton2.Text = "Button 2"<br />
"<br />
"ToolBarButton3<br />
"<br />
Me.ToolBarButton3.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton<br />
Me.ToolBarButton3.Text = "Toggle Button "<br />
"<br />
"ContextMenu1<br />
"<br />
Me.ContextMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem2, Me.MenuItem3})<br />
"<br />
"MenuItem1<br />
"<br />
Me.MenuItem1.Index = 0<br />
Me.MenuItem1.Text = "Red"<br />
"<br />
"MenuItem2<br />
"<br />
Me.MenuItem2.Index = 1<br />
Me.MenuItem2.Text = "Green"<br />
"<br />
"MenuItem3<br />
"<br />
Me.MenuItem3.Index = 2<br />
Me.MenuItem3.Text = "Blue"<br />
"<br />
"ToolBarButton4<br />
"<br />
Me.ToolBarButton4.DropDownMenu = Me.ContextMenu1<br />
Me.ToolBarButton4.Style = System.Windows.Forms.ToolBarButtonStyle.DropDownButton<br />
Me.ToolBarButton4.Text = "Button 4"<br />
"<br />
"ToolBarButton5<br />
"<br />
Me.ToolBarButton5.Style = System.Windows.Forms.ToolBarButtonStyle.Separator<br />
"<br />
"ToolBarButton6<br />
"<br />
Me.ToolBarButton6.Style = System.Windows.Forms.ToolBarButtonStyle.Separator<br />
"<br />
"ComboBox1<br />
"<br />
Me.ruboBox1.Items.AddRange(New Object() {"Item 0", "Item 1", "Item 2"})<br />
Me.ruboBox1.Location = New System.Drawing.Point(264, 8)<br />
Me.ruboBox1.Name = "ComboBox1"<br />
Me.ruboBox1.Size = New System.Drawing.Size(88, 21)<br />
Me.ruboBox1.TabIndex = 3<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(368, 273)<br />
Me.Controls.Add(Me.ruboBox1)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.Controls.Add(Me.Label1)<br />
Me.Controls.Add(Me.ToolBar1)<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick<br />
TextBox1.Text = "You clicked " & e.Button.Text<br />
End Sub<br />
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click<br />
TextBox1.Text = "You clicked the Red item."<br />
End Sub<br />
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click<br />
TextBox1.Text = "You clicked the Green item."<br />
End Sub<br />
Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click<br />
TextBox1.Text = "You clicked the Blue item."<br />
End Sub<br />
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged<br />
TextBox1.Text = "You selected item " & ComboBox1.SelectedIndex<br />
End Sub<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/Text_File_Print&diff=3901
VB.Net Tutorial/GUI/Text File Print
2010-05-26T12:57:23Z
<p>Admin: 1 версия</p>
<hr />
<div>==Print text file==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.IO<br />
Imports System.Text.Encoding<br />
Imports System.Drawing<br />
Imports System.Drawing.Printing<br />
Imports System.Windows.Forms<br />
public class PrintTextFile<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
Public Sub New()<br />
MyBase.New()<br />
InitializeComponent()<br />
End Sub<br />
Private components As System.ruponentModel.IContainer<br />
Friend WithEvents PrintDialog1 As System.Windows.Forms.PrintDialog<br />
Friend WithEvents PrintPreviewDialog1 As System.Windows.Forms.PrintPreviewDialog<br />
Friend WithEvents PageSetupDialog1 As System.Windows.Forms.PageSetupDialog<br />
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu<br />
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuPreview As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuPrint As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuExit As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem<br />
Friend WithEvents Panel1 As System.Windows.Forms.Panel<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog<br />
Friend WithEvents mnuOpen As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuPageSetup As System.Windows.Forms.MenuItem<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.PrintDialog1 = New System.Windows.Forms.PrintDialog()<br />
Me.PrintPreviewDialog1 = New System.Windows.Forms.PrintPreviewDialog()<br />
Me.PageSetupDialog1 = New System.Windows.Forms.PageSetupDialog()<br />
Me.MainMenu1 = New System.Windows.Forms.MainMenu()<br />
Me.MenuItem1 = New System.Windows.Forms.MenuItem()<br />
Me.mnuOpen = New System.Windows.Forms.MenuItem()<br />
Me.MenuItem3 = New System.Windows.Forms.MenuItem()<br />
Me.mnuPageSetup = New System.Windows.Forms.MenuItem()<br />
Me.mnuPreview = New System.Windows.Forms.MenuItem()<br />
Me.mnuPrint = New System.Windows.Forms.MenuItem()<br />
Me.MenuItem5 = New System.Windows.Forms.MenuItem()<br />
Me.mnuExit = New System.Windows.Forms.MenuItem()<br />
Me.Panel1 = New System.Windows.Forms.Panel()<br />
Me.TextBox1 = New System.Windows.Forms.TextBox()<br />
Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog()<br />
Me.Panel1.SuspendLayout()<br />
Me.SuspendLayout()<br />
"<br />
"PrintPreviewDialog1<br />
"<br />
Me.PrintPreviewDialog1.AutoScrollMargin = New System.Drawing.Size(0, 0)<br />
Me.PrintPreviewDialog1.AutoScrollMinSize = New System.Drawing.Size(0, 0)<br />
Me.PrintPreviewDialog1.ClientSize = New System.Drawing.Size(400, 300)<br />
Me.PrintPreviewDialog1.Enabled = True<br />
Me.PrintPreviewDialog1.Location = New System.Drawing.Point(375, 17)<br />
Me.PrintPreviewDialog1.MaximumSize = New System.Drawing.Size(0, 0)<br />
Me.PrintPreviewDialog1.Name = "PrintPreviewDialog1"<br />
Me.PrintPreviewDialog1.Opacity = 1<br />
Me.PrintPreviewDialog1.TransparencyKey = System.Drawing.Color.Empty<br />
Me.PrintPreviewDialog1.Visible = False<br />
"<br />
"MainMenu1<br />
"<br />
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1})<br />
"<br />
"MenuItem1<br />
"<br />
Me.MenuItem1.Index = 0<br />
Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuOpen, Me.MenuItem3, Me.mnuPageSetup, Me.mnuPreview, Me.mnuPrint, Me.MenuItem5, Me.mnuExit})<br />
Me.MenuItem1.Text = "&File"<br />
"<br />
"mnuOpen<br />
"<br />
Me.mnuOpen.Index = 0<br />
Me.mnuOpen.Text = "Open"<br />
"<br />
"MenuItem3<br />
"<br />
Me.MenuItem3.Index = 1<br />
Me.MenuItem3.Text = "-"<br />
"<br />
"mnuPageSetup<br />
"<br />
Me.mnuPageSetup.Index = 2<br />
Me.mnuPageSetup.Text = "Page Setup"<br />
"<br />
"mnuPreview<br />
"<br />
Me.mnuPreview.Index = 3<br />
Me.mnuPreview.Text = "Print Preview"<br />
"<br />
"mnuPrint<br />
"<br />
Me.mnuPrint.Index = 4<br />
Me.mnuPrint.Text = "Print"<br />
"<br />
"MenuItem5<br />
"<br />
Me.MenuItem5.Index = 5<br />
Me.MenuItem5.Text = "-"<br />
"<br />
"mnuExit<br />
"<br />
Me.mnuExit.Index = 6<br />
Me.mnuExit.Text = "Exit"<br />
"<br />
"Panel1<br />
"<br />
Me.Panel1.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox1})<br />
Me.Panel1.Dock = System.Windows.Forms.DockStyle.Fill<br />
Me.Panel1.DockPadding.All = 5<br />
Me.Panel1.Name = "Panel1"<br />
Me.Panel1.Size = New System.Drawing.Size(563, 325)<br />
Me.Panel1.TabIndex = 0<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Dock = System.Windows.Forms.DockStyle.Fill<br />
Me.TextBox1.Location = New System.Drawing.Point(6, 5)<br />
Me.TextBox1.Multiline = True<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(551, 315)<br />
Me.TextBox1.TabIndex = 0<br />
Me.TextBox1.Text = ""<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)<br />
Me.ClientSize = New System.Drawing.Size(563, 325)<br />
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Panel1})<br />
Me.Menu = Me.MainMenu1<br />
Me.Name = "Form1"<br />
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen<br />
Me.Text = "Dialog Application"<br />
Me.Panel1.ResumeLayout(False)<br />
Me.ResumeLayout(False)<br />
End Sub<br />
Private printerSettings As System.Drawing.Printing.PageSettings<br />
Private printingFont As Font<br />
Private streamReader As StreamReader<br />
Private filename As String<br />
Private Sub mnuPageSetup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuPageSetup.Click<br />
With PageSetupDialog1<br />
Try<br />
If (printerSettings Is Nothing) Then<br />
printerSettings = New System.Drawing.Printing.PageSettings()<br />
End If<br />
.AllowMargins = True<br />
.AllowOrientation = True<br />
.AllowPaper = True<br />
.AllowPrinter = True<br />
.PageSettings = printerSettings<br />
.ShowDialog()<br />
Catch ex As Exception<br />
MessageBox.Show(ex.StackTrace.ToString(), "Print", _<br />
MessageBoxButtons.OK, MessageBoxIcon.Error, _<br />
MessageBoxDefaultButton.Button1)<br />
End Try<br />
End With<br />
End Sub<br />
Private Sub mnuPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuPreview.Click<br />
If Not filename Is Nothing Then<br />
Try<br />
streamReader = New StreamReader(filename)<br />
Try<br />
printingFont = New Font("Arial", 10)<br />
Dim pd As New PrintDocument()<br />
AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage<br />
If Not (printerSettings Is Nothing) Then<br />
pd.DefaultPageSettings = printerSettings<br />
End If<br />
With PrintPreviewDialog1<br />
.Document = pd<br />
.ShowDialog()<br />
End With<br />
Finally<br />
streamReader.Close()<br />
End Try<br />
Catch ex As Exception<br />
MessageBox.Show(ex.Message, "Print", _<br />
MessageBoxButtons.OK, MessageBoxIcon.Error, _<br />
MessageBoxDefaultButton.Button1)<br />
End Try<br />
Else<br />
MessageBox.Show("Please select file first.", "Print", _<br />
MessageBoxButtons.OK, MessageBoxIcon.Error, _<br />
MessageBoxDefaultButton.Button1)<br />
End If<br />
End Sub<br />
Private Sub mnuPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuPrint.Click<br />
If Not filename Is Nothing Then<br />
Try<br />
streamReader = New StreamReader(filename)<br />
Try<br />
printingFont = New Font("Arial", 10)<br />
Dim pd As New PrintDocument()<br />
AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage<br />
If Not (printerSettings Is Nothing) Then<br />
pd.DefaultPageSettings = printerSettings<br />
End If<br />
With PrintDialog1<br />
.Document = pd<br />
.AllowPrintToFile = True<br />
.AllowSelection = True<br />
.AllowSomePages = True<br />
If .ShowDialog() = DialogResult.OK Then<br />
pd.Print()<br />
End If<br />
End With<br />
Finally<br />
streamReader.Close()<br />
End Try<br />
Catch ex As Exception<br />
MessageBox.Show(ex.StackTrace.ToString, "Print", _<br />
MessageBoxButtons.OK, MessageBoxIcon.Error, _<br />
MessageBoxDefaultButton.Button1)<br />
End Try<br />
Else<br />
MessageBox.Show("Please select file first.", "Print", _<br />
MessageBoxButtons.OK, MessageBoxIcon.Error, _<br />
MessageBoxDefaultButton.Button1)<br />
End If<br />
End Sub<br />
Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)<br />
Dim linesPerPage As Single = 0<br />
Dim yPos As Single = 0<br />
Dim count As Integer = 0<br />
Dim leftMargin As Single = ev.MarginBounds.Left<br />
Dim topMargin As Single = ev.MarginBounds.Top<br />
Dim line As String = Nothing<br />
linesPerPage = ev.MarginBounds.Height / printingFont.GetHeight(ev.Graphics)<br />
While count < linesPerPage<br />
line = streamReader.ReadLine()<br />
If line Is Nothing Then<br />
Exit While<br />
End If<br />
yPos = topMargin + count * printingFont.GetHeight(ev.Graphics)<br />
ev.Graphics.DrawString(line, printingFont, Brushes.Black, leftMargin, yPos, New StringFormat())<br />
count += 1<br />
End While<br />
If Not (line Is Nothing) Then<br />
ev.HasMorePages = True<br />
Else<br />
ev.HasMorePages = False<br />
End If<br />
End Sub<br />
Private Sub mnuOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOpen.Click<br />
Dim sr As StreamReader = Nothing<br />
Dim fs As FileStream = Nothing<br />
With OpenFileDialog1<br />
.InitialDirectory = "C:\"<br />
.Filter = "Text files (*.txt)|*.txt"<br />
.FilterIndex = 2<br />
.RestoreDirectory = True<br />
.ShowHelp = True<br />
.Title = "Open File Dialog"<br />
If .ShowDialog() = DialogResult.OK Then<br />
Me.Text = .FileName<br />
filename = .FileName<br />
TextBox1.Text = ""<br />
Try<br />
fs = New FileStream(.FileName, FileMode.Open, FileAccess.Read)<br />
sr = New StreamReader(fs, System.Text.Encoding.Default)<br />
TextBox1.Text = sr.ReadToEnd()<br />
Catch ex As Exception<br />
MessageBox.Show(ex.StackTrace.ToString(), "Print", _<br />
MessageBoxButtons.OK, MessageBoxIcon.Error, _<br />
MessageBoxDefaultButton.Button1)<br />
Finally<br />
If Not (sr Is Nothing) Then<br />
sr.Close()<br />
End If<br />
If Not (fs Is Nothing) Then<br />
fs.Close()<br />
End If<br />
End Try<br />
End If<br />
End With<br />
End Sub<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/RadioButton_MenuItem&diff=3889
VB.Net Tutorial/GUI/RadioButton MenuItem
2010-05-26T12:57:22Z
<p>Admin: 1 версия</p>
<hr />
<div>==RadioButton MenuItem==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class RadioButtonCheckBox<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<br />
Public Class MDIChild<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox<br />
Friend WithEvents mainMenu1 As System.Windows.Forms.MainMenu<br />
Friend WithEvents mnuMDIOptions As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMDIOpiton1 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMDIOpiton2 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMDIOpiton3 As System.Windows.Forms.MenuItem<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.RichTextBox1 = New System.Windows.Forms.RichTextBox()<br />
Me.mainMenu1 = New System.Windows.Forms.MainMenu()<br />
Me.mnuMDIOptions = New System.Windows.Forms.MenuItem()<br />
Me.mnuMDIOpiton1 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMDIOpiton2 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMDIOpiton3 = New System.Windows.Forms.MenuItem()<br />
Me.SuspendLayout()<br />
"<br />
"RichTextBox1<br />
"<br />
Me.RichTextBox1.Name = "RichTextBox1"<br />
Me.RichTextBox1.Size = New System.Drawing.Size(296, 176)<br />
Me.RichTextBox1.TabIndex = 0<br />
Me.RichTextBox1.Text = "RichTextBox1"<br />
"<br />
"mainMenu1<br />
"<br />
Me.mainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuMDIOptions})<br />
"<br />
"mnuMDIOptions<br />
"<br />
Me.mnuMDIOptions.Index = 0<br />
Me.mnuMDIOptions.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuMDIOpiton1, Me.mnuMDIOpiton2, Me.mnuMDIOpiton3})<br />
Me.mnuMDIOptions.MergeOrder = 1<br />
Me.mnuMDIOptions.Text = "MDIChildOptions"<br />
"<br />
"mnuMDIOpiton1<br />
"<br />
Me.mnuMDIOpiton1.Index = 0<br />
Me.mnuMDIOpiton1.Text = "MDI Option 1"<br />
"<br />
"mnuMDIOpiton2<br />
"<br />
Me.mnuMDIOpiton2.Index = 1<br />
Me.mnuMDIOpiton2.Text = "MDI Option 2"<br />
"<br />
"mnuMDIOpiton3<br />
"<br />
Me.mnuMDIOpiton3.Index = 2<br />
Me.mnuMDIOpiton3.Text = "MDI Option 3"<br />
"<br />
"MDIChild<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(292, 174)<br />
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.RichTextBox1})<br />
Me.Menu = Me.mainMenu1<br />
Me.Name = "MDIChild"<br />
Me.Text = "MDIChild"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub Option_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _<br />
Handles mnuMDIOpiton1.Click, mnuMDIOpiton2.Click, mnuMDIOpiton3.Click<br />
Dim item As MenuItem = CType(sender, MenuItem)<br />
item.Checked = Not item.Checked<br />
End Sub<br />
End Class<br />
<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents mainMenu1 As System.Windows.Forms.MainMenu<br />
Friend WithEvents mnuFile As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuNew As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuFileOpen As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuFileClose As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuFileSave As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuFileSaveAs As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuEdit As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuEditCopy As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuEditPaste As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuOptions As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuOption1 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuOption2 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuOption3 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuRadioOptions As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuRadioOption1 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuRadioOption2 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuRadioOption3 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuWindow As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu1 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu11 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu12 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu13 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu14 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMerge As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu2 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu21 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu22 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu23 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu24 As System.Windows.Forms.MenuItem<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.mainMenu1 = New System.Windows.Forms.MainMenu()<br />
Me.mnuFile = New System.Windows.Forms.MenuItem()<br />
Me.mnuNew = New System.Windows.Forms.MenuItem()<br />
Me.mnuFileOpen = New System.Windows.Forms.MenuItem()<br />
Me.mnuFileClose = New System.Windows.Forms.MenuItem()<br />
Me.mnuFileSave = New System.Windows.Forms.MenuItem()<br />
Me.mnuFileSaveAs = New System.Windows.Forms.MenuItem()<br />
Me.mnuEdit = New System.Windows.Forms.MenuItem()<br />
Me.mnuEditCopy = New System.Windows.Forms.MenuItem()<br />
Me.mnuEditPaste = New System.Windows.Forms.MenuItem()<br />
Me.mnuOptions = New System.Windows.Forms.MenuItem()<br />
Me.mnuOption1 = New System.Windows.Forms.MenuItem()<br />
Me.mnuOption2 = New System.Windows.Forms.MenuItem()<br />
Me.mnuOption3 = New System.Windows.Forms.MenuItem()<br />
Me.mnuRadioOptions = New System.Windows.Forms.MenuItem()<br />
Me.mnuRadioOption1 = New System.Windows.Forms.MenuItem()<br />
Me.mnuRadioOption2 = New System.Windows.Forms.MenuItem()<br />
Me.mnuRadioOption3 = New System.Windows.Forms.MenuItem()<br />
Me.mnuWindow = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu1 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu11 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu12 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu13 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu14 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMerge = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu2 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu21 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu22 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu23 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu24 = New System.Windows.Forms.MenuItem()<br />
"<br />
"mainMenu1<br />
"<br />
Me.mainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuFile, Me.mnuEdit, Me.mnuOptions, Me.mnuRadioOptions, Me.mnuWindow, Me.mnuMenu1, Me.mnuMenu2})<br />
"<br />
"mnuFile<br />
"<br />
Me.mnuFile.Index = 0<br />
Me.mnuFile.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuNew, Me.mnuFileOpen, Me.mnuFileClose, Me.mnuFileSave, Me.mnuFileSaveAs})<br />
Me.mnuFile.Text = "File"<br />
"<br />
"mnuNew<br />
"<br />
Me.mnuNew.Index = 0<br />
Me.mnuNew.Shortcut = System.Windows.Forms.Shortcut.CtrlN<br />
Me.mnuNew.Text = "&New"<br />
"<br />
"mnuFileOpen<br />
"<br />
Me.mnuFileOpen.Index = 1<br />
Me.mnuFileOpen.Text = "Open"<br />
"<br />
"mnuFileClose<br />
"<br />
Me.mnuFileClose.Index = 2<br />
Me.mnuFileClose.Text = "Close"<br />
"<br />
"mnuFileSave<br />
"<br />
Me.mnuFileSave.Index = 3<br />
Me.mnuFileSave.Text = "Save"<br />
"<br />
"mnuFileSaveAs<br />
"<br />
Me.mnuFileSaveAs.Index = 4<br />
Me.mnuFileSaveAs.Text = "Save&As"<br />
"<br />
"mnuEdit<br />
"<br />
Me.mnuEdit.Index = 1<br />
Me.mnuEdit.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuEditCopy, Me.mnuEditPaste})<br />
Me.mnuEdit.Text = "Edit"<br />
"<br />
"mnuEditCopy<br />
"<br />
Me.mnuEditCopy.Index = 0<br />
Me.mnuEditCopy.Text = "&Copy"<br />
"<br />
"mnuEditPaste<br />
"<br />
Me.mnuEditPaste.Index = 1<br />
Me.mnuEditPaste.Text = "Paste"<br />
"<br />
"mnuOptions<br />
"<br />
Me.mnuOptions.Index = 2<br />
Me.mnuOptions.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuOption1, Me.mnuOption2, Me.mnuOption3})<br />
Me.mnuOptions.Text = "Options"<br />
"<br />
"mnuOption1<br />
"<br />
Me.mnuOption1.Index = 0<br />
Me.mnuOption1.Text = "Option1"<br />
"<br />
"mnuOption2<br />
"<br />
Me.mnuOption2.Index = 1<br />
Me.mnuOption2.Text = "Option2"<br />
"<br />
"mnuOption3<br />
"<br />
Me.mnuOption3.Index = 2<br />
Me.mnuOption3.Text = "Option3"<br />
"<br />
"mnuRadioOptions<br />
"<br />
Me.mnuRadioOptions.Index = 3<br />
Me.mnuRadioOptions.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuRadioOption1, Me.mnuRadioOption2, Me.mnuRadioOption3})<br />
Me.mnuRadioOptions.Text = "Radio Options"<br />
"<br />
"mnuROption1<br />
"<br />
Me.mnuRadioOption1.Index = 0<br />
Me.mnuRadioOption1.RadioCheck = True<br />
Me.mnuRadioOption1.Text = "Radio Option 1"<br />
"<br />
"mnuROption2<br />
"<br />
Me.mnuRadioOption2.Index = 1<br />
Me.mnuRadioOption2.RadioCheck = True<br />
Me.mnuRadioOption2.Text = "Radio Option 2"<br />
"<br />
"mnuROption3<br />
"<br />
Me.mnuRadioOption3.Index = 2<br />
Me.mnuRadioOption3.RadioCheck = True<br />
Me.mnuRadioOption3.Text = "Radio Option 3"<br />
"<br />
"mnuWindow<br />
"<br />
Me.mnuWindow.Index = 4<br />
Me.mnuWindow.MdiList = True<br />
Me.mnuWindow.MergeOrder = 99<br />
Me.mnuWindow.Text = "&Window"<br />
"<br />
"mnuMenu1<br />
"<br />
Me.mnuMenu1.Index = 5<br />
Me.mnuMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuMenu11, Me.mnuMenu12, Me.mnuMenu13, Me.mnuMenu14, Me.mnuMerge})<br />
Me.mnuMenu1.Text = "Menu 1"<br />
"<br />
"mnuMenu11<br />
"<br />
Me.mnuMenu11.Index = 0<br />
Me.mnuMenu11.MergeOrder = 1<br />
Me.mnuMenu11.Text = "Menu 1.1"<br />
"<br />
"mnuMenu12<br />
"<br />
Me.mnuMenu12.Index = 1<br />
Me.mnuMenu12.MergeOrder = 2<br />
Me.mnuMenu12.Text = "Menu 1.2"<br />
"<br />
"mnuMenu13<br />
"<br />
Me.mnuMenu13.Index = 2<br />
Me.mnuMenu13.MergeOrder = 3<br />
Me.mnuMenu13.Text = "Menu 1.3"<br />
"<br />
"mnuMenu14<br />
"<br />
Me.mnuMenu14.Index = 3<br />
Me.mnuMenu14.MergeOrder = 4<br />
Me.mnuMenu14.Text = "Menu 1.4"<br />
"<br />
"mnuMerge<br />
"<br />
Me.mnuMerge.Index = 4<br />
Me.mnuMerge.MergeOrder = 99<br />
Me.mnuMerge.Text = "Merge!"<br />
"<br />
"mnuMenu2<br />
"<br />
Me.mnuMenu2.Index = 6<br />
Me.mnuMenu2.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuMenu21, Me.mnuMenu22, Me.mnuMenu23, Me.mnuMenu24})<br />
Me.mnuMenu2.Text = "Menu 2"<br />
"<br />
"mnuMenu21<br />
"<br />
Me.mnuMenu21.Index = 0<br />
Me.mnuMenu21.MergeOrder = 1<br />
Me.mnuMenu21.Text = "Menu 2.1"<br />
"<br />
"mnuMenu22<br />
"<br />
Me.mnuMenu22.Index = 1<br />
Me.mnuMenu22.MergeOrder = 2<br />
Me.mnuMenu22.MergeType = System.Windows.Forms.MenuMerge.Replace<br />
Me.mnuMenu22.Text = "Menu 2.2"<br />
"<br />
"mnuMenu23<br />
"<br />
Me.mnuMenu23.Index = 2<br />
Me.mnuMenu23.MergeOrder = 3<br />
Me.mnuMenu23.MergeType = System.Windows.Forms.MenuMerge.Remove<br />
Me.mnuMenu23.Text = "Menu 2.3"<br />
"<br />
"mnuMenu24<br />
"<br />
Me.mnuMenu24.Index = 3<br />
Me.mnuMenu24.MergeOrder = 5<br />
Me.mnuMenu24.Text = "Menu 2.4"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(456, 146)<br />
Me.IsMdiContainer = True<br />
Me.Menu = Me.mainMenu1<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
End Sub<br />
#End Region<br />
Private Sub mnuNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _<br />
Handles mnuNew.Click<br />
Dim newMDIChild As New MDIChild()<br />
newMDIChild.MdiParent = Me<br />
newMDIChild.Show()<br />
End Sub<br />
Private Sub mnuFileOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _<br />
Handles mnuFileOpen.Click<br />
MessageBox.Show("You clicked file open!", _<br />
"Menu event tester", _<br />
MessageBoxButtons.OK, _<br />
MessageBoxIcon.Information)<br />
End Sub<br />
Private Sub mnuFileClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _<br />
Handles mnuFileClose.Click<br />
MessageBox.Show("You clicked file close!", "Menu event tester", MessageBoxButtons.OK, MessageBoxIcon.Information)<br />
End Sub<br />
<br />
Private Sub mnuEditCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _<br />
Handles mnuEditCopy.Click<br />
MessageBox.Show("You clicked Edit copy!", "Menu event tester", MessageBoxButtons.OK, MessageBoxIcon.Information)<br />
End Sub<br />
Private Sub mnuEditPaste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _<br />
Handles mnuEditPaste.Click<br />
MessageBox.Show("You clicked Edit paste!", "Menu event tester", MessageBoxButtons.OK, MessageBoxIcon.Information)<br />
End Sub<br />
Private Sub Option_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _<br />
Handles mnuOption1.Click, mnuOption2.Click, mnuOption3.Click<br />
Dim item As MenuItem = CType(sender, MenuItem)<br />
item.Checked = Not item.Checked<br />
End Sub<br />
Private Sub RadioOption_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _<br />
Handles mnuRadioOption1.Click, mnuRadioOption2.Click, mnuRadioOption3.Click<br />
Dim item As MenuItem = CType(sender, MenuItem)<br />
Dim parent As Menu = item.Parent<br />
Dim tempMi As MenuItem<br />
For Each tempMi In parent.MenuItems<br />
tempMi.Checked = False<br />
Next<br />
item.Checked = True<br />
End Sub<br />
Private Sub mnuMerge_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)<br />
Dim item As MenuItem = CType(sender, MenuItem)<br />
item.Parent.MergeMenu(mnuMenu2)<br />
End Sub<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/Drag_Drop&diff=3891
VB.Net Tutorial/GUI/Drag Drop
2010-05-26T12:57:22Z
<p>Admin: 1 версия</p>
<hr />
<div>==Copy and paste Object==<br />
<br />
<br />
<br />
<source lang="vbnet">" Requires a reference to System.Xml.<br />
Imports System.Xml.Serialization<br />
Imports System.IO<br />
Imports System.Windows.Forms<br />
public class CopyPasteEmployee<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<br />
Public Class Form1<br />
<Serializable()> _<br />
Public Class Employee<br />
Public FirstName As String<br />
Public LastName As String<br />
Public Sub New()<br />
End Sub<br />
Public Sub New(ByVal first_name As String, ByVal last_name As String)<br />
FirstName = first_name<br />
LastName = last_name<br />
End Sub<br />
End Class<br />
" Copy the Employee to the clipboard.<br />
Private Sub btnCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCopy.Click<br />
Dim emp As New Employee(txtFirstName.Text, txtLastName.Text)<br />
Dim data_object As New DataObject<br />
data_object.SetData("Employee", emp)<br />
Clipboard.SetDataObject(data_object)<br />
End Sub<br />
" Paste data from the clipboard.<br />
Private Sub btnPaste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPaste.Click<br />
Dim data_object As IDataObject = Clipboard.GetDataObject()<br />
If data_object.GetDataPresent("Employee") Then<br />
Dim emp As Employee = DirectCast(data_object.GetData("Employee"), Employee)<br />
txtPasteFirstName.Text = emp.FirstName<br />
txtPasteLastName.Text = emp.LastName<br />
End If<br />
End Sub<br />
End Class<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.btnPaste = New System.Windows.Forms.Button<br />
Me.txtPasteLastName = New System.Windows.Forms.TextBox<br />
Me.txtPasteFirstName = New System.Windows.Forms.TextBox<br />
Me.Label3 = New System.Windows.Forms.Label<br />
Me.Label4 = New System.Windows.Forms.Label<br />
Me.btnCopy = New System.Windows.Forms.Button<br />
Me.txtLastName = New System.Windows.Forms.TextBox<br />
Me.txtFirstName = New System.Windows.Forms.TextBox<br />
Me.Label2 = New System.Windows.Forms.Label<br />
Me.Label1 = New System.Windows.Forms.Label<br />
Me.SuspendLayout()<br />
"<br />
"btnPaste<br />
"<br />
Me.btnPaste.Location = New System.Drawing.Point(232, 96)<br />
Me.btnPaste.Name = "btnPaste"<br />
Me.btnPaste.Size = New System.Drawing.Size(48, 24)<br />
Me.btnPaste.TabIndex = 22<br />
Me.btnPaste.Text = "Paste"<br />
"<br />
"txtPasteLastName<br />
"<br />
Me.txtPasteLastName.Location = New System.Drawing.Point(72, 112)<br />
Me.txtPasteLastName.Name = "txtPasteLastName"<br />
Me.txtPasteLastName.Size = New System.Drawing.Size(136, 20)<br />
Me.txtPasteLastName.TabIndex = 21<br />
"<br />
"txtPasteFirstName<br />
"<br />
Me.txtPasteFirstName.Location = New System.Drawing.Point(72, 88)<br />
Me.txtPasteFirstName.Name = "txtPasteFirstName"<br />
Me.txtPasteFirstName.Size = New System.Drawing.Size(136, 20)<br />
Me.txtPasteFirstName.TabIndex = 20<br />
"<br />
"Label3<br />
"<br />
Me.Label3.AutoSize = True<br />
Me.Label3.Location = New System.Drawing.Point(8, 112)<br />
Me.Label3.Name = "Label3"<br />
Me.Label3.Size = New System.Drawing.Size(54, 13)<br />
Me.Label3.TabIndex = 19<br />
Me.Label3.Text = "Last Name"<br />
"<br />
"Label4<br />
"<br />
Me.Label4.AutoSize = True<br />
Me.Label4.Location = New System.Drawing.Point(8, 88)<br />
Me.Label4.Name = "Label4"<br />
Me.Label4.Size = New System.Drawing.Size(53, 13)<br />
Me.Label4.TabIndex = 18<br />
Me.Label4.Text = "First Name"<br />
"<br />
"btnCopy<br />
"<br />
Me.btnCopy.Location = New System.Drawing.Point(232, 16)<br />
Me.btnCopy.Name = "btnCopy"<br />
Me.btnCopy.Size = New System.Drawing.Size(48, 24)<br />
Me.btnCopy.TabIndex = 17<br />
Me.btnCopy.Text = "Copy"<br />
"<br />
"txtLastName<br />
"<br />
Me.txtLastName.Location = New System.Drawing.Point(72, 32)<br />
Me.txtLastName.Name = "txtLastName"<br />
Me.txtLastName.Size = New System.Drawing.Size(136, 20)<br />
Me.txtLastName.TabIndex = 16<br />
Me.txtLastName.Text = "AAAAAA"<br />
"<br />
"txtFirstName<br />
"<br />
Me.txtFirstName.Location = New System.Drawing.Point(72, 8)<br />
Me.txtFirstName.Name = "txtFirstName"<br />
Me.txtFirstName.Size = New System.Drawing.Size(136, 20)<br />
Me.txtFirstName.TabIndex = 15<br />
Me.txtFirstName.Text = "BBBBB"<br />
"<br />
"Label2<br />
"<br />
Me.Label2.AutoSize = True<br />
Me.Label2.Location = New System.Drawing.Point(8, 32)<br />
Me.Label2.Name = "Label2"<br />
Me.Label2.Size = New System.Drawing.Size(54, 13)<br />
Me.Label2.TabIndex = 14<br />
Me.Label2.Text = "Last Name"<br />
"<br />
"Label1<br />
"<br />
Me.Label1.AutoSize = True<br />
Me.Label1.Location = New System.Drawing.Point(8, 8)<br />
Me.Label1.Name = "Label1"<br />
Me.Label1.Size = New System.Drawing.Size(53, 13)<br />
Me.Label1.TabIndex = 13<br />
Me.Label1.Text = "First Name"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(288, 139)<br />
Me.Controls.Add(Me.btnPaste)<br />
Me.Controls.Add(Me.txtPasteLastName)<br />
Me.Controls.Add(Me.txtPasteFirstName)<br />
Me.Controls.Add(Me.Label3)<br />
Me.Controls.Add(Me.Label4)<br />
Me.Controls.Add(Me.btnCopy)<br />
Me.Controls.Add(Me.txtLastName)<br />
Me.Controls.Add(Me.txtFirstName)<br />
Me.Controls.Add(Me.Label2)<br />
Me.Controls.Add(Me.Label1)<br />
Me.Name = "Form1"<br />
Me.Text = "CopyPasteEmployee"<br />
Me.ResumeLayout(False)<br />
Me.PerformLayout()<br />
End Sub<br />
Friend WithEvents btnPaste As System.Windows.Forms.Button<br />
Friend WithEvents txtPasteLastName As System.Windows.Forms.TextBox<br />
Friend WithEvents txtPasteFirstName As System.Windows.Forms.TextBox<br />
Friend WithEvents Label3 As System.Windows.Forms.Label<br />
Friend WithEvents Label4 As System.Windows.Forms.Label<br />
Friend WithEvents btnCopy As System.Windows.Forms.Button<br />
Friend WithEvents txtLastName As System.Windows.Forms.TextBox<br />
Friend WithEvents txtFirstName As System.Windows.Forms.TextBox<br />
Friend WithEvents Label2 As System.Windows.Forms.Label<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
End Class</source><br />
<br />
==Drop a file==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Data<br />
Imports System.Data.OleDb<br />
Imports System.Windows.Forms<br />
public class FileDrop<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
" Allow Copy if there is FileDrop data.<br />
Private Sub lblDropTarget_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lblDropTarget.DragEnter<br />
If e.Data.GetDataPresent(DataFormats.FileDrop) Then<br />
e.Effect = DragDropEffects.Copy<br />
Else<br />
e.Effect = DragDropEffects.None<br />
End If<br />
End Sub<br />
" Display the dropped file names.<br />
Private Sub lblDropTarget_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lblDropTarget.DragDrop<br />
lstFiles.Items.Clear()<br />
Dim file_names As String() = DirectCast(e.Data.GetData(DataFormats.FileDrop), String())<br />
For Each file_name As String In file_names<br />
lstFiles.Items.Add(file_name)<br />
Next file_name<br />
End Sub<br />
End Class<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.lstFiles = New System.Windows.Forms.ListBox<br />
Me.lblDropTarget = New System.Windows.Forms.Label<br />
Me.SuspendLayout()<br />
"<br />
"lstFiles<br />
"<br />
Me.lstFiles.Dock = System.Windows.Forms.DockStyle.Fill<br />
Me.lstFiles.FormattingEnabled = True<br />
Me.lstFiles.Location = New System.Drawing.Point(0, 48)<br />
Me.lstFiles.Name = "lstFiles"<br />
Me.lstFiles.Size = New System.Drawing.Size(274, 160)<br />
Me.lstFiles.TabIndex = 3<br />
"<br />
"lblDropTarget<br />
"<br />
Me.lblDropTarget.AllowDrop = True<br />
Me.lblDropTarget.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D<br />
Me.lblDropTarget.Dock = System.Windows.Forms.DockStyle.Top<br />
Me.lblDropTarget.Location = New System.Drawing.Point(0, 0)<br />
Me.lblDropTarget.Name = "lblDropTarget"<br />
Me.lblDropTarget.Size = New System.Drawing.Size(274, 48)<br />
Me.lblDropTarget.TabIndex = 2<br />
Me.lblDropTarget.Text = "Drop Target"<br />
Me.lblDropTarget.TextAlign = System.Drawing.ContentAlignment.MiddleCenter<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(274, 210)<br />
Me.Controls.Add(Me.lstFiles)<br />
Me.Controls.Add(Me.lblDropTarget)<br />
Me.Name = "Form1"<br />
Me.Text = "AcceptFiles"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
Friend WithEvents lstFiles As System.Windows.Forms.ListBox<br />
Friend WithEvents lblDropTarget As System.Windows.Forms.Label<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/Introduction&diff=3893
VB.Net Tutorial/GUI/Introduction
2010-05-26T12:57:22Z
<p>Admin: 1 версия</p>
<hr />
<div>==Add button to a form==<br />
<br />
<br />
<br />
<source lang="vbnet">imports System<br />
imports System.Drawing<br />
imports System.Windows.Forms<br />
namespace WinForms<br />
public class HelloWorld : inherits System.Windows.Forms.Form<br />
Private WithEvents btn as Button<br />
public sub New()<br />
Text = "Hello World"<br />
btn = new Button()<br />
btn.Location = new Point(50,50)<br />
btn.Text = "Goodbye"<br />
Controls.Add(btn)<br />
end sub<br />
public shared sub Main() <br />
Application.Run(new HelloWorld())<br />
end sub<br />
private sub btn_Click(ByVal sender as object,ByVal e as EventArgs) Handles btn.Click<br />
Application.Exit()<br />
end sub<br />
end class<br />
end namespace</source><br />
<br />
==Button PerformClick Method==<br />
<br />
<br />
<br />
<source lang="vbnet">imports System<br />
imports System.Drawing<br />
imports System.Windows.Forms<br />
public class ButtonPerformClick : inherits Form<br />
dim btn1 as Button<br />
dim btn2 as Button<br />
public sub New()<br />
Size = new Size(200,100)<br />
btn1 = new Button()<br />
btn1.Parent = me<br />
btn1.Text = "Button1"<br />
btn1.Location = new Point(10,10)<br />
AddHandler btn1.Click, AddressOf btn1_Click<br />
btn2 = new Button()<br />
btn2.Parent = me<br />
btn2.Text = "Button1"<br />
btn2.Location = new Point(100,10)<br />
AddHandler btn2.Click, AddressOf btn2_Click<br />
end sub<br />
<br />
private sub btn1_Click(ByVal sender as object,ByVal e as EventArgs)<br />
MessageBox.Show("Button1 clicked.")<br />
btn2.PerformClick()<br />
end sub<br />
private sub btn2_Click(ByVal sender as object,ByVal e as EventArgs)<br />
MessageBox.Show("Button2 clicked.")<br />
end sub<br />
public shared sub Main() <br />
Application.Run(new ButtonPerformClick())<br />
end sub<br />
end class</source><br />
<br />
==Control Dock: Top, Bottom==<br />
<br />
<br />
<br />
<source lang="vbnet">imports System<br />
imports System.Drawing<br />
imports System.Windows.Forms<br />
public class ControlDock : inherits Form<br />
public sub New()<br />
Text = "Control Docking"<br />
Size = new Size(350,400)<br />
dim yButtonSize as integer = Font.Height * 2<br />
dim btnFirst as new Button()<br />
btnFirst.Parent = me<br />
btnFirst.Text = "First Button"<br />
btnFirst.Height = yButtonSize<br />
btnFirst.Dock = DockStyle.Top<br />
dim btnSecond as new Button()<br />
btnSecond.Parent = me<br />
btnSecond.Text = "Second Button"<br />
btnSecond.Height = yButtonSize<br />
btnSecond.Dock = DockStyle.Bottom<br />
end sub<br />
public shared sub Main() <br />
Application.Run(new ControlDock())<br />
end sub<br />
end class</source><br />
<br />
==Create Form by inheriting System.Windows.Forms.Form==<br />
<br />
<br />
<br />
<source lang="vbnet">imports System.Windows.Forms<br />
namespace WinForms<br />
public class HelloWorld : inherits System.Windows.Forms.Form<br />
public sub New()<br />
Text = "Hello World"<br />
end sub<br />
shared sub Main() <br />
Application.Run(new HelloWorld())<br />
end sub<br />
end class<br />
end namespace</source><br />
<br />
==Use With statement to set Form properties==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class FormWith<br />
public Shared Sub Main<br />
Dim Form2 As New Form()<br />
With Form2<br />
.Cursor = System.Windows.Forms.Cursors.Cross<br />
.Enabled = True<br />
.FormBorderStyle = FormBorderStyle.Sizable<br />
.Height = 400<br />
.HelpButton = True<br />
.MaximizeBox = True<br />
.MinimizeBox = True<br />
.Name = "Form2"<br />
.ShowInTaskbar = True<br />
.StartPosition = FormStartPosition.CenterParent<br />
.Text = "New Form"<br />
.Width = 500<br />
.WindowState = FormWindowState.Normal<br />
.ShowDialog()<br />
End With<br />
End Sub<br />
End class</source><br />
<br />
==Your first Form window==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System<br />
Imports System.Windows.Forms<br />
Class MyFirstForm<br />
Inherits Form<br />
Private WithEvents mybutton As Button<br />
Public Sub New()<br />
Me.Text = "Hello, WinForms!"<br />
mybutton = New Button()<br />
mybutton.Text = "Click Me!"<br />
Me.Controls.Add(mybutton)<br />
End Sub<br />
Public Sub mybutton_Click(sender As Object, e As EventArgs) Handles mybutton.Click<br />
MessageBox.Show("Message")<br />
End Sub<br />
End Class<br />
Class MyFirstApp<br />
Shared Sub Main()<br />
Dim myform As Form = New MyFirstForm()<br />
Application.Run(myform)<br />
End Sub<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/OpenFileDialog&diff=3885
VB.Net Tutorial/GUI/OpenFileDialog
2010-05-26T12:57:21Z
<p>Admin: 1 версия</p>
<hr />
<div>==File Open/Save dialog==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class FileSaveOpenDialog<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
Public Sub New()<br />
MyBase.New()<br />
InitializeComponent()<br />
End Sub<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
Private components As System.ruponentModel.IContainer<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents Button2 As System.Windows.Forms.Button<br />
Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog<br />
Friend WithEvents SaveFileDialog1 As System.Windows.Forms.SaveFileDialog<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.Button2 = New System.Windows.Forms.Button<br />
Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog<br />
Me.SaveFileDialog1 = New System.Windows.Forms.SaveFileDialog<br />
Me.SuspendLayout()<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(32, 32)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.Size = New System.Drawing.Size(88, 32)<br />
Me.Button1.TabIndex = 0<br />
Me.Button1.Text = "Open"<br />
"<br />
"Button2<br />
"<br />
Me.Button2.Location = New System.Drawing.Point(160, 32)<br />
Me.Button2.Name = "Button2"<br />
Me.Button2.Size = New System.Drawing.Size(88, 32)<br />
Me.Button2.TabIndex = 1<br />
Me.Button2.Text = "Save"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(292, 110)<br />
Me.Controls.Add(Me.Button2)<br />
Me.Controls.Add(Me.Button1)<br />
Me.ResumeLayout(False)<br />
End Sub<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
OpenFileDialog1.ShowDialog()<br />
End Sub<br />
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click<br />
SaveFileDialog1.ShowDialog()<br />
End Sub<br />
End Class</source><br />
<br />
==Get selected file name in a OpenFileDialog==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class OpenFileDialogSelectedFileName<br />
public Shared Sub Main<br />
Dim FileDB As New OpenFileDialog()<br />
If (FileDB.ShowDialog() = DialogResult.OK) Then<br />
Console.WriteLine("File: " & FileDB.FileName)<br />
Else<br />
Console.WriteLine("User selected Cancel")<br />
End If<br />
End Sub<br />
End class</source><br />
<br />
==Open File Dialog Filter==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class PictureBoxImageFromOpenFileDialog<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
Public Sub New()<br />
MyBase.New()<br />
InitializeComponent()<br />
End Sub<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
Private components As System.ruponentModel.IContainer<br />
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.PictureBox1 = New System.Windows.Forms.PictureBox<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog<br />
Me.SuspendLayout()<br />
"<br />
"PictureBox1<br />
"<br />
Me.PictureBox1.Location = New System.Drawing.Point(16, 16)<br />
Me.PictureBox1.Name = "PictureBox1"<br />
Me.PictureBox1.Size = New System.Drawing.Size(248, 176)<br />
Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize<br />
Me.PictureBox1.TabIndex = 0<br />
Me.PictureBox1.TabStop = False<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(96, 208)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.Size = New System.Drawing.Size(88, 24)<br />
Me.Button1.TabIndex = 1<br />
Me.Button1.Text = "Open"<br />
"<br />
"OpenFileDialog1<br />
"<br />
Me.OpenFileDialog1.Filter = "bmp(*.bmp)|*.bmp"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(292, 266)<br />
Me.Controls.Add(Me.Button1)<br />
Me.Controls.Add(Me.PictureBox1)<br />
Me.ResumeLayout(False)<br />
End Sub<br />
<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
Dim pic As Image<br />
OpenFileDialog1.ShowDialog()<br />
pic = New Bitmap(OpenFileDialog1.FileName)<br />
PictureBox1.Image = pic<br />
End Sub<br />
End Class</source><br />
<br />
==Prevent dialog box from validating file==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.IO<br />
Imports System.Windows.Forms<br />
Module Module1<br />
Sub Main()<br />
Dim FileDB As New OpenFileDialog()<br />
FileDB.Filter = "All files | *.* | Text files | *.txt"<br />
FileDB.FilterIndex = 2<br />
FileDB.InitialDirectory = "C:\Temp"<br />
FileDB.AddExtension = True<br />
FileDB.DefaultExt = "txt"<br />
" Prevent dialog box from validating file<br />
FileDB.CheckFileExists = False<br />
FileDB.CheckPathExists = False<br />
If (FileDB.ShowDialog() = DialogResult.OK) Then<br />
Dim SourceFile As StreamReader<br />
Try<br />
SourceFile = New StreamReader(FileDB.FileName)<br />
Console.WriteLine(SourceFile.ReadToEnd())<br />
SourceFile.Close()<br />
Catch Except As Exception<br />
Console.WriteLine("Error: " & Except.Message)<br />
End Try<br />
Else<br />
Console.WriteLine("User selected Cancel")<br />
End If<br />
End Sub<br />
End Module</source><br />
<br />
==Set InitialDirectory and FilterIndex for OpenFileDialog==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class OpenFileDialogInitDirectory<br />
public Shared Sub Main<br />
Dim FileDB As New OpenFileDialog()<br />
FileDB.Filter = "All files | *.* | Word files | *.doc | Text files | *.txt"<br />
FileDB.FilterIndex = 3<br />
FileDB.InitialDirectory = "C:\Temp"<br />
If (FileDB.ShowDialog() = DialogResult.OK) Then<br />
Console.WriteLine("File: " & FileDB.FileName)<br />
Else<br />
Console.WriteLine("User selected Cancel")<br />
End If<br />
End Sub<br />
End class</source><br />
<br />
==Set OpenFileDialog Filter and get selected file name==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class FileOpenDialogFilter<br />
public Shared Sub Main<br />
Dim openFileDialog1 As System.Windows.Forms.OpenFileDialog<br />
openFileDialog1 = New System.Windows.Forms.OpenFileDialog()<br />
<br />
openFileDialog1.Filter = "Word (*.doc) |*.doc;*.rtf|(*.txt) |*.txt|(*.*) |*.*"<br />
If openFileDialog1.ShowDialog() = DialogResult.OK Then<br />
Console.WriteLine(openFileDialog1.FileName)<br />
End If<br />
End Sub<br />
End class</source><br />
<br />
==Use OpenFileDialog to load image to PictureBox==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class OpenFileDialogPicture<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.PictureBox1 = New System.Windows.Forms.PictureBox<br />
Me.SuspendLayout()<br />
"<br />
"OpenFileDialog1<br />
"<br />
Me.OpenFileDialog1.Filter = "JPEG files (*.jpg)|*.jpg|GIF files (*.gif)|*.gif|All files (*.*)|*.*"<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(96, 88)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.Size = New System.Drawing.Size(88, 23)<br />
Me.Button1.TabIndex = 0<br />
Me.Button1.Text = "Show Dialog"<br />
"<br />
"PictureBox1<br />
"<br />
Me.PictureBox1.Location = New System.Drawing.Point(88, 144)<br />
Me.PictureBox1.Name = "PictureBox1"<br />
Me.PictureBox1.Size = New System.Drawing.Size(104, 88)<br />
Me.PictureBox1.TabIndex = 1<br />
Me.PictureBox1.TabStop = False<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(292, 273)<br />
Me.Controls.Add(Me.PictureBox1)<br />
Me.Controls.Add(Me.Button1)<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then<br />
PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)<br />
End If<br />
End Sub<br />
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ruponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk<br />
End Sub<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/CheckBox_MenuItem&diff=3887
VB.Net Tutorial/GUI/CheckBox MenuItem
2010-05-26T12:57:21Z
<p>Admin: 1 версия</p>
<hr />
<div>==CheckBox MenuItem==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class RadioButtonCheckBox<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<br />
Public Class MDIChild<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox<br />
Friend WithEvents mainMenu1 As System.Windows.Forms.MainMenu<br />
Friend WithEvents mnuMDIOptions As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMDIOpiton1 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMDIOpiton2 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMDIOpiton3 As System.Windows.Forms.MenuItem<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.RichTextBox1 = New System.Windows.Forms.RichTextBox()<br />
Me.mainMenu1 = New System.Windows.Forms.MainMenu()<br />
Me.mnuMDIOptions = New System.Windows.Forms.MenuItem()<br />
Me.mnuMDIOpiton1 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMDIOpiton2 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMDIOpiton3 = New System.Windows.Forms.MenuItem()<br />
Me.SuspendLayout()<br />
"<br />
"RichTextBox1<br />
"<br />
Me.RichTextBox1.Name = "RichTextBox1"<br />
Me.RichTextBox1.Size = New System.Drawing.Size(296, 176)<br />
Me.RichTextBox1.TabIndex = 0<br />
Me.RichTextBox1.Text = "RichTextBox1"<br />
"<br />
"mainMenu1<br />
"<br />
Me.mainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuMDIOptions})<br />
"<br />
"mnuMDIOptions<br />
"<br />
Me.mnuMDIOptions.Index = 0<br />
Me.mnuMDIOptions.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuMDIOpiton1, Me.mnuMDIOpiton2, Me.mnuMDIOpiton3})<br />
Me.mnuMDIOptions.MergeOrder = 1<br />
Me.mnuMDIOptions.Text = "MDIChildOptions"<br />
"<br />
"mnuMDIOpiton1<br />
"<br />
Me.mnuMDIOpiton1.Index = 0<br />
Me.mnuMDIOpiton1.Text = "MDI Option 1"<br />
"<br />
"mnuMDIOpiton2<br />
"<br />
Me.mnuMDIOpiton2.Index = 1<br />
Me.mnuMDIOpiton2.Text = "MDI Option 2"<br />
"<br />
"mnuMDIOpiton3<br />
"<br />
Me.mnuMDIOpiton3.Index = 2<br />
Me.mnuMDIOpiton3.Text = "MDI Option 3"<br />
"<br />
"MDIChild<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(292, 174)<br />
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.RichTextBox1})<br />
Me.Menu = Me.mainMenu1<br />
Me.Name = "MDIChild"<br />
Me.Text = "MDIChild"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub Option_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _<br />
Handles mnuMDIOpiton1.Click, mnuMDIOpiton2.Click, mnuMDIOpiton3.Click<br />
Dim item As MenuItem = CType(sender, MenuItem)<br />
item.Checked = Not item.Checked<br />
End Sub<br />
End Class<br />
<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents mainMenu1 As System.Windows.Forms.MainMenu<br />
Friend WithEvents mnuFile As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuNew As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuFileOpen As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuFileClose As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuFileSave As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuFileSaveAs As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuEdit As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuEditCopy As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuEditPaste As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuOptions As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuOption1 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuOption2 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuOption3 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuRadioOptions As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuRadioOption1 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuRadioOption2 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuRadioOption3 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuWindow As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu1 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu11 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu12 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu13 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu14 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMerge As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu2 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu21 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu22 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu23 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu24 As System.Windows.Forms.MenuItem<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.mainMenu1 = New System.Windows.Forms.MainMenu()<br />
Me.mnuFile = New System.Windows.Forms.MenuItem()<br />
Me.mnuNew = New System.Windows.Forms.MenuItem()<br />
Me.mnuFileOpen = New System.Windows.Forms.MenuItem()<br />
Me.mnuFileClose = New System.Windows.Forms.MenuItem()<br />
Me.mnuFileSave = New System.Windows.Forms.MenuItem()<br />
Me.mnuFileSaveAs = New System.Windows.Forms.MenuItem()<br />
Me.mnuEdit = New System.Windows.Forms.MenuItem()<br />
Me.mnuEditCopy = New System.Windows.Forms.MenuItem()<br />
Me.mnuEditPaste = New System.Windows.Forms.MenuItem()<br />
Me.mnuOptions = New System.Windows.Forms.MenuItem()<br />
Me.mnuOption1 = New System.Windows.Forms.MenuItem()<br />
Me.mnuOption2 = New System.Windows.Forms.MenuItem()<br />
Me.mnuOption3 = New System.Windows.Forms.MenuItem()<br />
Me.mnuRadioOptions = New System.Windows.Forms.MenuItem()<br />
Me.mnuRadioOption1 = New System.Windows.Forms.MenuItem()<br />
Me.mnuRadioOption2 = New System.Windows.Forms.MenuItem()<br />
Me.mnuRadioOption3 = New System.Windows.Forms.MenuItem()<br />
Me.mnuWindow = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu1 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu11 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu12 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu13 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu14 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMerge = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu2 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu21 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu22 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu23 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu24 = New System.Windows.Forms.MenuItem()<br />
"<br />
"mainMenu1<br />
"<br />
Me.mainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuFile, Me.mnuEdit, Me.mnuOptions, Me.mnuRadioOptions, Me.mnuWindow, Me.mnuMenu1, Me.mnuMenu2})<br />
"<br />
"mnuFile<br />
"<br />
Me.mnuFile.Index = 0<br />
Me.mnuFile.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuNew, Me.mnuFileOpen, Me.mnuFileClose, Me.mnuFileSave, Me.mnuFileSaveAs})<br />
Me.mnuFile.Text = "File"<br />
"<br />
"mnuNew<br />
"<br />
Me.mnuNew.Index = 0<br />
Me.mnuNew.Shortcut = System.Windows.Forms.Shortcut.CtrlN<br />
Me.mnuNew.Text = "&New"<br />
"<br />
"mnuFileOpen<br />
"<br />
Me.mnuFileOpen.Index = 1<br />
Me.mnuFileOpen.Text = "Open"<br />
"<br />
"mnuFileClose<br />
"<br />
Me.mnuFileClose.Index = 2<br />
Me.mnuFileClose.Text = "Close"<br />
"<br />
"mnuFileSave<br />
"<br />
Me.mnuFileSave.Index = 3<br />
Me.mnuFileSave.Text = "Save"<br />
"<br />
"mnuFileSaveAs<br />
"<br />
Me.mnuFileSaveAs.Index = 4<br />
Me.mnuFileSaveAs.Text = "Save&As"<br />
"<br />
"mnuEdit<br />
"<br />
Me.mnuEdit.Index = 1<br />
Me.mnuEdit.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuEditCopy, Me.mnuEditPaste})<br />
Me.mnuEdit.Text = "Edit"<br />
"<br />
"mnuEditCopy<br />
"<br />
Me.mnuEditCopy.Index = 0<br />
Me.mnuEditCopy.Text = "&Copy"<br />
"<br />
"mnuEditPaste<br />
"<br />
Me.mnuEditPaste.Index = 1<br />
Me.mnuEditPaste.Text = "Paste"<br />
"<br />
"mnuOptions<br />
"<br />
Me.mnuOptions.Index = 2<br />
Me.mnuOptions.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuOption1, Me.mnuOption2, Me.mnuOption3})<br />
Me.mnuOptions.Text = "Options"<br />
"<br />
"mnuOption1<br />
"<br />
Me.mnuOption1.Index = 0<br />
Me.mnuOption1.Text = "Option1"<br />
"<br />
"mnuOption2<br />
"<br />
Me.mnuOption2.Index = 1<br />
Me.mnuOption2.Text = "Option2"<br />
"<br />
"mnuOption3<br />
"<br />
Me.mnuOption3.Index = 2<br />
Me.mnuOption3.Text = "Option3"<br />
"<br />
"mnuRadioOptions<br />
"<br />
Me.mnuRadioOptions.Index = 3<br />
Me.mnuRadioOptions.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuRadioOption1, Me.mnuRadioOption2, Me.mnuRadioOption3})<br />
Me.mnuRadioOptions.Text = "Radio Options"<br />
"<br />
"mnuROption1<br />
"<br />
Me.mnuRadioOption1.Index = 0<br />
Me.mnuRadioOption1.RadioCheck = True<br />
Me.mnuRadioOption1.Text = "Radio Option 1"<br />
"<br />
"mnuROption2<br />
"<br />
Me.mnuRadioOption2.Index = 1<br />
Me.mnuRadioOption2.RadioCheck = True<br />
Me.mnuRadioOption2.Text = "Radio Option 2"<br />
"<br />
"mnuROption3<br />
"<br />
Me.mnuRadioOption3.Index = 2<br />
Me.mnuRadioOption3.RadioCheck = True<br />
Me.mnuRadioOption3.Text = "Radio Option 3"<br />
"<br />
"mnuWindow<br />
"<br />
Me.mnuWindow.Index = 4<br />
Me.mnuWindow.MdiList = True<br />
Me.mnuWindow.MergeOrder = 99<br />
Me.mnuWindow.Text = "&Window"<br />
"<br />
"mnuMenu1<br />
"<br />
Me.mnuMenu1.Index = 5<br />
Me.mnuMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuMenu11, Me.mnuMenu12, Me.mnuMenu13, Me.mnuMenu14, Me.mnuMerge})<br />
Me.mnuMenu1.Text = "Menu 1"<br />
"<br />
"mnuMenu11<br />
"<br />
Me.mnuMenu11.Index = 0<br />
Me.mnuMenu11.MergeOrder = 1<br />
Me.mnuMenu11.Text = "Menu 1.1"<br />
"<br />
"mnuMenu12<br />
"<br />
Me.mnuMenu12.Index = 1<br />
Me.mnuMenu12.MergeOrder = 2<br />
Me.mnuMenu12.Text = "Menu 1.2"<br />
"<br />
"mnuMenu13<br />
"<br />
Me.mnuMenu13.Index = 2<br />
Me.mnuMenu13.MergeOrder = 3<br />
Me.mnuMenu13.Text = "Menu 1.3"<br />
"<br />
"mnuMenu14<br />
"<br />
Me.mnuMenu14.Index = 3<br />
Me.mnuMenu14.MergeOrder = 4<br />
Me.mnuMenu14.Text = "Menu 1.4"<br />
"<br />
"mnuMerge<br />
"<br />
Me.mnuMerge.Index = 4<br />
Me.mnuMerge.MergeOrder = 99<br />
Me.mnuMerge.Text = "Merge!"<br />
"<br />
"mnuMenu2<br />
"<br />
Me.mnuMenu2.Index = 6<br />
Me.mnuMenu2.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuMenu21, Me.mnuMenu22, Me.mnuMenu23, Me.mnuMenu24})<br />
Me.mnuMenu2.Text = "Menu 2"<br />
"<br />
"mnuMenu21<br />
"<br />
Me.mnuMenu21.Index = 0<br />
Me.mnuMenu21.MergeOrder = 1<br />
Me.mnuMenu21.Text = "Menu 2.1"<br />
"<br />
"mnuMenu22<br />
"<br />
Me.mnuMenu22.Index = 1<br />
Me.mnuMenu22.MergeOrder = 2<br />
Me.mnuMenu22.MergeType = System.Windows.Forms.MenuMerge.Replace<br />
Me.mnuMenu22.Text = "Menu 2.2"<br />
"<br />
"mnuMenu23<br />
"<br />
Me.mnuMenu23.Index = 2<br />
Me.mnuMenu23.MergeOrder = 3<br />
Me.mnuMenu23.MergeType = System.Windows.Forms.MenuMerge.Remove<br />
Me.mnuMenu23.Text = "Menu 2.3"<br />
"<br />
"mnuMenu24<br />
"<br />
Me.mnuMenu24.Index = 3<br />
Me.mnuMenu24.MergeOrder = 5<br />
Me.mnuMenu24.Text = "Menu 2.4"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(456, 146)<br />
Me.IsMdiContainer = True<br />
Me.Menu = Me.mainMenu1<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
End Sub<br />
#End Region<br />
Private Sub mnuNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _<br />
Handles mnuNew.Click<br />
Dim newMDIChild As New MDIChild()<br />
newMDIChild.MdiParent = Me<br />
newMDIChild.Show()<br />
End Sub<br />
Private Sub mnuFileOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _<br />
Handles mnuFileOpen.Click<br />
MessageBox.Show("You clicked file open!", _<br />
"Menu event tester", _<br />
MessageBoxButtons.OK, _<br />
MessageBoxIcon.Information)<br />
End Sub<br />
Private Sub mnuFileClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _<br />
Handles mnuFileClose.Click<br />
MessageBox.Show("You clicked file close!", "Menu event tester", MessageBoxButtons.OK, MessageBoxIcon.Information)<br />
End Sub<br />
<br />
Private Sub mnuEditCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _<br />
Handles mnuEditCopy.Click<br />
MessageBox.Show("You clicked Edit copy!", "Menu event tester", MessageBoxButtons.OK, MessageBoxIcon.Information)<br />
End Sub<br />
Private Sub mnuEditPaste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _<br />
Handles mnuEditPaste.Click<br />
MessageBox.Show("You clicked Edit paste!", "Menu event tester", MessageBoxButtons.OK, MessageBoxIcon.Information)<br />
End Sub<br />
Private Sub Option_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _<br />
Handles mnuOption1.Click, mnuOption2.Click, mnuOption3.Click<br />
Dim item As MenuItem = CType(sender, MenuItem)<br />
item.Checked = Not item.Checked<br />
End Sub<br />
Private Sub RadioOption_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _<br />
Handles mnuRadioOption1.Click, mnuRadioOption2.Click, mnuRadioOption3.Click<br />
Dim item As MenuItem = CType(sender, MenuItem)<br />
Dim parent As Menu = item.Parent<br />
Dim tempMi As MenuItem<br />
For Each tempMi In parent.MenuItems<br />
tempMi.Checked = False<br />
Next<br />
item.Checked = True<br />
End Sub<br />
Private Sub mnuMerge_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)<br />
Dim item As MenuItem = CType(sender, MenuItem)<br />
item.Parent.MergeMenu(mnuMenu2)<br />
End Sub<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/Controls&diff=3883
VB.Net Tutorial/GUI/Controls
2010-05-26T12:57:20Z
<p>Admin: 1 версия</p>
<hr />
<div>==Add Label to a form==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class AddNewLabelToForm<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<br />
Public Class Form1<br />
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
Dim lbl As New Label<br />
lbl.SetBounds(10, 50, 100, 25)<br />
lbl.Text = "Hello World!"<br />
Me.Controls.Add(lbl)<br />
End Sub<br />
End Class<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.SuspendLayout()<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(292, 273)<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
End Class</source><br />
<br />
==Add TextBox to Form in code==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class AddTextBoxForm<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<br />
Public Class Form1<br />
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load<br />
Dim dynamicText As TextBox = Nothing<br />
dynamicText = New Windows.Forms.TextBox<br />
dynamicText.Name = "TimeTextBox"<br />
dynamicText.Location = New System.Drawing.Point(8, 8)<br />
dynamicText.Size = New System.Drawing.Size(232, 20)<br />
dynamicText.TabIndex = 0<br />
Me.Controls.Add(dynamicText)<br />
Dim theTextBox As TextBox<br />
theTextBox = Me.Controls("TimeTextBox")<br />
If (theTextBox IsNot Nothing) Then<br />
theTextBox.Text = Now.ToLongTimeString()<br />
End If<br />
End Sub<br />
End Class<br />
<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.SuspendLayout()<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(260, 76)<br />
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle<br />
Me.MaximizeBox = False<br />
Me.Name = "Form1"<br />
Me.Text = "Dynamic Controls"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
End Class</source><br />
<br />
==Add the Button control to the Form Controls collection==<br />
<br />
<br />
<br />
<source lang="vbnet">imports System<br />
imports System.Drawing<br />
imports System.Windows.Forms<br />
public class ControlParent : inherits Form<br />
Private WithEvents btn as Button<br />
public sub New()<br />
btn = new Button()<br />
btn.Location = new Point(50,50)<br />
btn.Size = new Size(100,23)<br />
btn.Text = "Relationships"<br />
Controls.Add(btn)<br />
btn.Parent = me<br />
end sub<br />
public shared sub Main() <br />
Application.Run(new ControlParent())<br />
end sub<br />
private sub btn_Click(ByVal sender as object,ByVal e as EventArgs) Handles btn.Click<br />
Console.WriteLine("Button Parent: " + btn.Parent.ToString())<br />
Console.WriteLine("Button HasChildren: " + btn.HasChildren.ToString())<br />
Console.WriteLine("TopLevelControl: " + btn.TopLevelControl.ToString())<br />
Console.WriteLine("Form HasChildren: " + me.HasChildren.ToString())<br />
Console.WriteLine("Form Controls Count: " + me.Controls.Count.ToString())<br />
end sub<br />
end class</source><br />
<br />
==Cast event sender to control==<br />
<br />
<br />
<br />
<source lang="vbnet">Option Strict On<br />
Imports System.Drawing<br />
Imports System.Windows.Forms<br />
Public Class Form1 : Inherits Form<br />
" Instantiate buttons<br />
Public WithEvents btnOK As New Button()<br />
Public WithEvents btnCancel As New Button()<br />
Public WithEvents btnQuit As New Button()<br />
<br />
" Application entry point<br />
Public Shared Sub Main()<br />
Dim frm As New Form1()<br />
frm.ShowDialog()<br />
End Sub<br />
<br />
" Class constructor<br />
Public Sub New()<br />
MyBase.New()<br />
" Define button sizes and locations<br />
Me.btnOK.Location = New Point(100, 50)<br />
Me.btnOK.Size = New Size(100, 50)<br />
Me.btnOK.Text = "OK"<br />
Me.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK<br />
Me.btnCancel.Location = New Point(100, 125)<br />
Me.btnCancel.Size = New Size(100, 50)<br />
Me.btnCancel.Text = "Cancel"<br />
Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel<br />
<br />
Me.btnQuit.Location = New Point(100, 200)<br />
Me.btnQuit.Size = New Size(100, 50)<br />
Me.btnQuit.Text = "Exit"<br />
Me.btnQuit.DialogResult = System.Windows.Forms.DialogResult.Abort<br />
" Define form controls and caption<br />
Me.Controls.Add(btnOK)<br />
Me.Controls.Add(btnCancel)<br />
Me.Controls.Add(btnQuit)<br />
Me.Text = "Button Click Events"<br />
End Sub<br />
<br />
" Event handler for all three buttons<br />
Private Sub ButtonClicked(ByVal sender As System.Object, _<br />
ByVal e As System.EventArgs) _<br />
Handles btnOK.Click, btnCancel.Click, btnQuit.Click<br />
If TypeOf sender Is Button Then<br />
Dim btn As Button = DirectCast(sender, Button)<br />
If btn.Name = "btnOK" Then<br />
Console.WriteLine("btnOK")<br />
ElseIf btn.Name = "btnCancel" Then<br />
Console.WriteLine("Cancel")<br />
Exit Sub<br />
Else <br />
Me.Close()<br />
End If<br />
Else<br />
Throw New ArgumentException( _<br />
"The event was raised by an invalid object.")<br />
End If<br />
End Sub<br />
End Class</source><br />
<br />
==Check Control type==<br />
<br />
<br />
<br />
<source lang="vbnet">Option Strict On<br />
Imports System.Drawing<br />
Imports System.Windows.Forms<br />
Public Class Form1 : Inherits Form<br />
" Instantiate buttons<br />
Public WithEvents btnOK As New Button()<br />
Public WithEvents btnCancel As New Button()<br />
Public WithEvents btnQuit As New Button()<br />
<br />
" Application entry point<br />
Public Shared Sub Main()<br />
Dim frm As New Form1()<br />
frm.ShowDialog()<br />
End Sub<br />
<br />
" Class constructor<br />
Public Sub New()<br />
MyBase.New()<br />
" Define button sizes and locations<br />
Me.btnOK.Location = New Point(100, 50)<br />
Me.btnOK.Size = New Size(100, 50)<br />
Me.btnOK.Text = "OK"<br />
Me.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK<br />
Me.btnCancel.Location = New Point(100, 125)<br />
Me.btnCancel.Size = New Size(100, 50)<br />
Me.btnCancel.Text = "Cancel"<br />
Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel<br />
<br />
Me.btnQuit.Location = New Point(100, 200)<br />
Me.btnQuit.Size = New Size(100, 50)<br />
Me.btnQuit.Text = "Exit"<br />
Me.btnQuit.DialogResult = System.Windows.Forms.DialogResult.Abort<br />
" Define form controls and caption<br />
Me.Controls.Add(btnOK)<br />
Me.Controls.Add(btnCancel)<br />
Me.Controls.Add(btnQuit)<br />
Me.Text = "Button Click Events"<br />
End Sub<br />
<br />
" Event handler for all three buttons<br />
Private Sub ButtonClicked(ByVal sender As System.Object, _<br />
ByVal e As System.EventArgs) _<br />
Handles btnOK.Click, btnCancel.Click, btnQuit.Click<br />
If TypeOf sender Is Button Then<br />
Dim btn As Button = DirectCast(sender, Button)<br />
If btn.Name = "btnOK" Then<br />
Console.WriteLine("btnOK")<br />
ElseIf btn.Name = "btnCancel" Then<br />
Console.WriteLine("Cancel")<br />
Exit Sub<br />
Else <br />
Me.Close()<br />
End If<br />
Else<br />
Throw New ArgumentException( _<br />
"The event was raised by an invalid object.")<br />
End If<br />
End Sub<br />
End Class</source><br />
<br />
==Hide a control==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class HideControl<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<br />
Public Class Form1<br />
Public val1 As Integer<br />
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click<br />
If val1 = 1 Then<br />
Button1.Visible = False<br />
val1 = 0<br />
Button2.Text = "Button1 Hidden"<br />
Else<br />
Button1.Visible = True<br />
val1 = 1<br />
Button2.Text = "Click Button2 to hide button1"<br />
End If<br />
End Sub<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
End Sub<br />
End Class<br />
<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.Button2 = New System.Windows.Forms.Button<br />
Me.SuspendLayout()<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(105, 65)<br />
Me.Button1.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.Size = New System.Drawing.Size(253, 40)<br />
Me.Button1.TabIndex = 0<br />
Me.Button1.Text = "Button1"<br />
Me.Button1.UseVisualStyleBackColor = True<br />
Me.Button1.Visible = False<br />
"<br />
"Button2<br />
"<br />
Me.Button2.Location = New System.Drawing.Point(105, 162)<br />
Me.Button2.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4)<br />
Me.Button2.Name = "Button2"<br />
Me.Button2.Size = New System.Drawing.Size(253, 41)<br />
Me.Button2.TabIndex = 1<br />
Me.Button2.Text = "click Button2 to hide button1"<br />
Me.Button2.UseVisualStyleBackColor = True<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 15.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(473, 300)<br />
Me.Controls.Add(Me.Button2)<br />
Me.Controls.Add(Me.Button1)<br />
Me.Margin = New System.Windows.Forms.Padding(4, 4, 4, 4)<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents Button2 As System.Windows.Forms.Button<br />
End Class</source><br />
<br />
==Read and Save controls on a form to a file==<br />
<br />
<br />
<br />
<source lang="vbnet">Option Strict On<br />
Imports System.IO<br />
Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class SaveReadControlsFile<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
Friend WithEvents Panel1 As System.Windows.Forms.Panel<br />
Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox<br />
Friend WithEvents ColorDialog1 As System.Windows.Forms.ColorDialog<br />
Friend WithEvents FontDialog1 As System.Windows.Forms.FontDialog<br />
Friend WithEvents SaveFileDialog1 As System.Windows.Forms.SaveFileDialog<br />
Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog<br />
Friend WithEvents btnChangeColor As System.Windows.Forms.Button<br />
Friend WithEvents btnChangeFont As System.Windows.Forms.Button<br />
Friend WithEvents btnSaveRTF As System.Windows.Forms.Button<br />
Friend WithEvents btnOpenRTF As System.Windows.Forms.Button<br />
Friend WithEvents btnWriteControls As System.Windows.Forms.Button<br />
Friend WithEvents btnReadControls As System.Windows.Forms.Button<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox<br />
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.Panel1 = New System.Windows.Forms.Panel()<br />
Me.RichTextBox1 = New System.Windows.Forms.RichTextBox()<br />
Me.ColorDialog1 = New System.Windows.Forms.ColorDialog()<br />
Me.FontDialog1 = New System.Windows.Forms.FontDialog()<br />
Me.SaveFileDialog1 = New System.Windows.Forms.SaveFileDialog()<br />
Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog()<br />
Me.btnChangeColor = New System.Windows.Forms.Button()<br />
Me.btnChangeFont = New System.Windows.Forms.Button()<br />
Me.btnSaveRTF = New System.Windows.Forms.Button()<br />
Me.btnOpenRTF = New System.Windows.Forms.Button()<br />
Me.btnWriteControls = New System.Windows.Forms.Button()<br />
Me.btnReadControls = New System.Windows.Forms.Button()<br />
Me.TextBox1 = New System.Windows.Forms.TextBox()<br />
Me.TextBox2 = New System.Windows.Forms.TextBox()<br />
Me.TextBox3 = New System.Windows.Forms.TextBox()<br />
Me.Panel1.SuspendLayout()<br />
Me.SuspendLayout()<br />
"<br />
"Panel1<br />
"<br />
Me.Panel1.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnReadControls, Me.btnWriteControls, Me.btnOpenRTF, Me.btnSaveRTF, Me.btnChangeFont, Me.btnChangeColor})<br />
Me.Panel1.Dock = System.Windows.Forms.DockStyle.Bottom<br />
Me.Panel1.Location = New System.Drawing.Point(0, 222)<br />
Me.Panel1.Name = "Panel1"<br />
Me.Panel1.Size = New System.Drawing.Size(656, 64)<br />
Me.Panel1.TabIndex = 0<br />
"<br />
"RichTextBox1<br />
"<br />
Me.RichTextBox1.Location = New System.Drawing.Point(16, 8)<br />
Me.RichTextBox1.Name = "RichTextBox1"<br />
Me.RichTextBox1.Size = New System.Drawing.Size(336, 176)<br />
Me.RichTextBox1.TabIndex = 1<br />
Me.RichTextBox1.Text = "Mr. and Mrs. Dursley, of number four, Privet Drive, were proud to say that they w" & _<br />
"ere perfectly normal, thank you very much."<br />
"<br />
"btnChangeColor<br />
"<br />
Me.btnChangeColor.Location = New System.Drawing.Point(24, 24)<br />
Me.btnChangeColor.Name = "btnChangeColor"<br />
Me.btnChangeColor.Size = New System.Drawing.Size(88, 32)<br />
Me.btnChangeColor.TabIndex = 0<br />
Me.btnChangeColor.Text = "Change Color"<br />
"<br />
"btnChangeFont<br />
"<br />
Me.btnChangeFont.Location = New System.Drawing.Point(128, 24)<br />
Me.btnChangeFont.Name = "btnChangeFont"<br />
Me.btnChangeFont.Size = New System.Drawing.Size(88, 32)<br />
Me.btnChangeFont.TabIndex = 1<br />
Me.btnChangeFont.Text = "Change Font"<br />
"<br />
"btnSaveRTF<br />
"<br />
Me.btnSaveRTF.Location = New System.Drawing.Point(232, 24)<br />
Me.btnSaveRTF.Name = "btnSaveRTF"<br />
Me.btnSaveRTF.Size = New System.Drawing.Size(88, 32)<br />
Me.btnSaveRTF.TabIndex = 2<br />
Me.btnSaveRTF.Text = "Save RTF"<br />
"<br />
"btnOpenRTF<br />
"<br />
Me.btnOpenRTF.Location = New System.Drawing.Point(336, 24)<br />
Me.btnOpenRTF.Name = "btnOpenRTF"<br />
Me.btnOpenRTF.Size = New System.Drawing.Size(88, 32)<br />
Me.btnOpenRTF.TabIndex = 3<br />
Me.btnOpenRTF.Text = "Open RTF"<br />
"<br />
"btnWriteControls<br />
"<br />
Me.btnWriteControls.Location = New System.Drawing.Point(440, 24)<br />
Me.btnWriteControls.Name = "btnWriteControls"<br />
Me.btnWriteControls.Size = New System.Drawing.Size(88, 32)<br />
Me.btnWriteControls.TabIndex = 4<br />
Me.btnWriteControls.Text = "Write Controls"<br />
"<br />
"btnReadControls<br />
"<br />
Me.btnReadControls.Location = New System.Drawing.Point(544, 24)<br />
Me.btnReadControls.Name = "btnReadControls"<br />
Me.btnReadControls.Size = New System.Drawing.Size(88, 32)<br />
Me.btnReadControls.TabIndex = 5<br />
Me.btnReadControls.Text = "Read Controls"<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(400, 24)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(232, 20)<br />
Me.TextBox1.TabIndex = 2<br />
Me.TextBox1.Text = "TextBox1"<br />
"<br />
"TextBox2<br />
"<br />
Me.TextBox2.Location = New System.Drawing.Point(400, 68)<br />
Me.TextBox2.Name = "TextBox2"<br />
Me.TextBox2.Size = New System.Drawing.Size(232, 20)<br />
Me.TextBox2.TabIndex = 3<br />
Me.TextBox2.Text = "TextBox2"<br />
"<br />
"TextBox3<br />
"<br />
Me.TextBox3.Location = New System.Drawing.Point(400, 112)<br />
Me.TextBox3.Name = "TextBox3"<br />
Me.TextBox3.Size = New System.Drawing.Size(232, 20)<br />
Me.TextBox3.TabIndex = 4<br />
Me.TextBox3.Text = "TextBox3"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(656, 286)<br />
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox3, Me.TextBox2, Me.TextBox1, Me.RichTextBox1, Me.Panel1})<br />
Me.Panel1.ResumeLayout(False)<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub btnWriteControls_Click(ByVal sender As System.Object, _<br />
ByVal e As System.EventArgs) Handles btnWriteControls.Click<br />
"Get a file<br />
Dim theFile As String<br />
SaveFileDialog1.InitialDirectory = Application.ExecutablePath<br />
SaveFileDialog1.DefaultExt = "hld" "custom format<br />
SaveFileDialog1.FileName = "myFile"<br />
SaveFileDialog1.Filter = "HLD Files (*.hld)|*.hld|All Files (*.*) | *.*"<br />
SaveFileDialog1.OverwritePrompt = True<br />
SaveFileDialog1.ShowDialog()<br />
theFile = SaveFileDialog1.FileName<br />
Dim fs As FileStream = New FileStream(theFile, FileMode.OpenOrCreate)<br />
Dim w As StreamWriter = New StreamWriter(fs)<br />
Dim c As Object<br />
For Each c In Me.Controls<br />
If TypeOf (c) Is TextBox Then<br />
Dim tbox As TextBox = CType(c, TextBox)<br />
w.WriteLine(tbox.Name & "=" & tbox.Text)<br />
End If<br />
Next<br />
w.Close()<br />
fs.Close()<br />
End Sub<br />
Private Sub btnReadControls_Click(ByVal sender As System.Object, _<br />
ByVal e As System.EventArgs) Handles btnReadControls.Click<br />
Dim theFile As String<br />
OpenFileDialog1.InitialDirectory = Application.ExecutablePath<br />
OpenFileDialog1.DefaultExt = "hld" "custom format<br />
OpenFileDialog1.FileName = "myFile"<br />
OpenFileDialog1.Filter = "HLD Files (*.hld)|*.hld|All Files (*.*) | *.*"<br />
OpenFileDialog1.ShowDialog()<br />
theFile = OpenFileDialog1.FileName<br />
Dim fs As FileStream = New FileStream(theFile, FileMode.Open)<br />
Dim r As StreamReader = New StreamReader(fs)<br />
Dim c As Object<br />
Dim tmpArray() As String<br />
For Each c In Me.Controls<br />
If TypeOf (c) Is TextBox Then<br />
Dim tbox As TextBox = CType(c, TextBox)<br />
tmpArray = Split(r.ReadLine(), "=")<br />
If tbox.Name = tmpArray(0) Then<br />
tbox.Text = tmpArray(1)<br />
End If<br />
End If<br />
Next<br />
r.Close()<br />
End Sub<br />
End Class</source><br />
<br />
==Set Control Parent==<br />
<br />
<br />
<br />
<source lang="vbnet">imports System<br />
imports System.Drawing<br />
imports System.Windows.Forms<br />
public class ControlParent : inherits Form<br />
Private WithEvents btn as Button<br />
public sub New()<br />
btn = new Button()<br />
btn.Location = new Point(50,50)<br />
btn.Size = new Size(100,23)<br />
btn.Text = "Relationships"<br />
Controls.Add(btn)<br />
btn.Parent = me<br />
end sub<br />
public shared sub Main() <br />
Application.Run(new ControlParent())<br />
end sub<br />
private sub btn_Click(ByVal sender as object,ByVal e as EventArgs) Handles btn.Click<br />
Console.WriteLine("Button Parent: " + btn.Parent.ToString())<br />
Console.WriteLine("Button HasChildren: " + btn.HasChildren.ToString())<br />
Console.WriteLine("TopLevelControl: " + btn.TopLevelControl.ToString())<br />
Console.WriteLine("Form HasChildren: " + me.HasChildren.ToString())<br />
Console.WriteLine("Form Controls Count: " + me.Controls.Count.ToString())<br />
end sub<br />
end class</source><br />
<br />
==Use Constrol"s Tag==<br />
<br />
<br />
<br />
<source lang="vbnet">imports System<br />
imports System.Drawing<br />
imports System.Windows.Forms<br />
public class Tags : inherits Form<br />
private lbl as Label<br />
public sub New()<br />
Size = new Size(300,200)<br />
lbl = new Label()<br />
lbl.Text = "Label..."<br />
lbl.AutoSize = true<br />
lbl.Parent = me<br />
lbl.Location = new Point(10,10)<br />
dim theEnum as new FontStyle()<br />
dim theStyles as FontStyle() = CType([Enum].GetValues(theEnum.GetType()), FontStyle())<br />
dim i as integer = 1<br />
dim style as FontStyle<br />
for each style in theStyles<br />
dim btn as new Button()<br />
btn.Parent = me<br />
btn.Location = new Point(25,25 * i)<br />
btn.Size = new Size(75,20)<br />
btn.Text = style.ToString()<br />
btn.Tag = style<br />
AddHandler btn.Click, AddressOf btn_Click<br />
i += 1<br />
next<br />
end sub<br />
public shared sub Main() <br />
Application.Run(new Tags())<br />
end sub<br />
private sub btn_Click(ByVal sender as object,ByVal e as EventArgs)<br />
dim btn as Button = CType(sender, Button)<br />
dim fs as FontStyle = CType(btn.Tag, FontStyle)<br />
lbl.Font = new Font(lbl.Font, fs)<br />
end sub<br />
end class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/ListView&diff=3881
VB.Net Tutorial/GUI/ListView
2010-05-26T12:57:19Z
<p>Admin: 1 версия</p>
<hr />
<div>==Add and delete ListView Item==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class ListViewState<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
Public Sub New()<br />
MyBase.New()<br />
InitializeComponent()<br />
End Sub<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
Private components As System.ruponentModel.IContainer<br />
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu<br />
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem<br />
Friend WithEvents ListView1 As System.Windows.Forms.ListView<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
Friend WithEvents Label2 As System.Windows.Forms.Label<br />
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents Button3 As System.Windows.Forms.Button<br />
Friend WithEvents ImageList1 As System.Windows.Forms.ImageList<br />
Friend WithEvents ImageList2 As System.Windows.Forms.ImageList<br />
Friend WithEvents ImageList3 As System.Windows.Forms.ImageList<br />
Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader<br />
Friend WithEvents ColumnHeader2 As System.Windows.Forms.ColumnHeader<br />
Friend WithEvents ColumnHeader3 As System.Windows.Forms.ColumnHeader<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.ruponents = New System.ruponentModel.Container<br />
Me.MainMenu1 = New System.Windows.Forms.MainMenu<br />
Me.MenuItem1 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem2 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem3 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem4 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem5 = New System.Windows.Forms.MenuItem<br />
Me.ListView1 = New System.Windows.Forms.ListView<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.Label1 = New System.Windows.Forms.Label<br />
Me.Label2 = New System.Windows.Forms.Label<br />
Me.TextBox2 = New System.Windows.Forms.TextBox<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.Button3 = New System.Windows.Forms.Button<br />
Me.ColumnHeader1 = New System.Windows.Forms.ColumnHeader<br />
Me.ColumnHeader2 = New System.Windows.Forms.ColumnHeader<br />
Me.ColumnHeader3 = New System.Windows.Forms.ColumnHeader<br />
Me.SuspendLayout()<br />
"<br />
"MainMenu1<br />
"<br />
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1})<br />
"<br />
"MenuItem1<br />
"<br />
Me.MenuItem1.Index = 0<br />
Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem2, Me.MenuItem3, Me.MenuItem4, Me.MenuItem5})<br />
Me.MenuItem1.Text = "View"<br />
"<br />
"MenuItem2<br />
"<br />
Me.MenuItem2.Index = 0<br />
Me.MenuItem2.Text = "Large Icon"<br />
"<br />
"MenuItem3<br />
"<br />
Me.MenuItem3.Index = 1<br />
Me.MenuItem3.Text = "Small Icon"<br />
"<br />
"MenuItem4<br />
"<br />
Me.MenuItem4.Index = 2<br />
Me.MenuItem4.Text = "List"<br />
"<br />
"MenuItem5<br />
"<br />
Me.MenuItem5.Index = 3<br />
Me.MenuItem5.Text = "Detail"<br />
"<br />
"ListView1<br />
"<br />
Me.ListView1.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2, Me.ColumnHeader3})<br />
Me.ListView1.Dock = System.Windows.Forms.DockStyle.Top<br />
Me.ListView1.Location = New System.Drawing.Point(0, 0)<br />
Me.ListView1.Name = "ListView1"<br />
Me.ListView1.Size = New System.Drawing.Size(328, 128)<br />
Me.ListView1.TabIndex = 0<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(88, 168)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(80, 20)<br />
Me.TextBox1.TabIndex = 1<br />
Me.TextBox1.Text = ""<br />
"<br />
"Label1<br />
"<br />
Me.Label1.Location = New System.Drawing.Point(48, 168)<br />
Me.Label1.Name = "Label1"<br />
Me.Label1.Size = New System.Drawing.Size(40, 24)<br />
Me.Label1.TabIndex = 2<br />
Me.Label1.Text = "Project"<br />
"<br />
"Label2<br />
"<br />
Me.Label2.Location = New System.Drawing.Point(16, 200)<br />
Me.Label2.Name = "Label2"<br />
Me.Label2.Size = New System.Drawing.Size(72, 24)<br />
Me.Label2.TabIndex = 3<br />
Me.Label2.Text = "No"<br />
"<br />
"TextBox2<br />
"<br />
Me.TextBox2.Location = New System.Drawing.Point(88, 200)<br />
Me.TextBox2.Name = "TextBox2"<br />
Me.TextBox2.Size = New System.Drawing.Size(80, 20)<br />
Me.TextBox2.TabIndex = 4<br />
Me.TextBox2.Text = ""<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(192, 184)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.Size = New System.Drawing.Size(72, 24)<br />
Me.Button1.TabIndex = 5<br />
Me.Button1.Text = "Add"<br />
"<br />
"Button3<br />
"<br />
Me.Button3.Location = New System.Drawing.Point(120, 240)<br />
Me.Button3.Name = "Button3"<br />
Me.Button3.Size = New System.Drawing.Size(80, 24)<br />
Me.Button3.TabIndex = 9<br />
Me.Button3.Text = "Delete"<br />
"<br />
"ColumnHeader1<br />
"<br />
Me.ColumnHeader1.Text = "File"<br />
"<br />
"ColumnHeader2<br />
"<br />
Me.ColumnHeader2.Text = "Size"<br />
"<br />
"ColumnHeader3<br />
"<br />
Me.ColumnHeader3.Text = "Change Date"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(328, 297)<br />
Me.Controls.Add(Me.Button3)<br />
Me.Controls.Add(Me.Button1)<br />
Me.Controls.Add(Me.TextBox2)<br />
Me.Controls.Add(Me.Label2)<br />
Me.Controls.Add(Me.Label1)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.Controls.Add(Me.ListView1)<br />
Me.Menu = Me.MainMenu1<br />
Me.ResumeLayout(False)<br />
End Sub<br />
<br />
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click<br />
ListView1.View = View.LargeIcon<br />
End Sub<br />
Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click<br />
ListView1.View = View.SmallIcon<br />
End Sub<br />
Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click<br />
ListView1.View = View.List<br />
End Sub<br />
Private Sub MenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem5.Click<br />
ListView1.View = View.Details<br />
End Sub<br />
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click<br />
ListView1.FocusedItem.Remove()<br />
End Sub<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
<br />
ListView1.Items.Add("new", 2)<br />
End Sub<br />
End Class</source><br />
<br />
==Add columns and rows to a ListView==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class AddColumnToListView<br />
public Shared Sub Main<br />
Application.Run(New Form2)<br />
End Sub<br />
End class<br />
Public Class Form2<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents ListView1 As System.Windows.Forms.ListView<br />
Friend WithEvents Button2 As System.Windows.Forms.Button<br />
Friend WithEvents ListView2 As System.Windows.Forms.ListView<br />
Friend WithEvents Button3 As System.Windows.Forms.Button<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.Button1 = New System.Windows.Forms.Button()<br />
Me.ListView1 = New System.Windows.Forms.ListView()<br />
Me.Button2 = New System.Windows.Forms.Button()<br />
Me.ListView2 = New System.Windows.Forms.ListView()<br />
Me.Button3 = New System.Windows.Forms.Button()<br />
Me.SuspendLayout()<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(32, 8)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.TabIndex = 0<br />
Me.Button1.Text = "Get Files"<br />
"<br />
"ListView1<br />
"<br />
Me.ListView1.Location = New System.Drawing.Point(32, 40)<br />
Me.ListView1.Name = "ListView1"<br />
Me.ListView1.Size = New System.Drawing.Size(480, 56)<br />
Me.ListView1.TabIndex = 1<br />
"<br />
"Button2<br />
"<br />
Me.Button2.Location = New System.Drawing.Point(32, 120)<br />
Me.Button2.Name = "Button2"<br />
Me.Button2.Size = New System.Drawing.Size(80, 24)<br />
Me.Button2.TabIndex = 2<br />
Me.Button2.Text = "Add Item"<br />
"<br />
"ListView2<br />
"<br />
Me.ListView2.Location = New System.Drawing.Point(32, 160)<br />
Me.ListView2.Name = "ListView2"<br />
Me.ListView2.Size = New System.Drawing.Size(504, 97)<br />
Me.ListView2.TabIndex = 3<br />
Me.ListView2.View = System.Windows.Forms.View.Details<br />
"<br />
"Button3<br />
"<br />
Me.Button3.Location = New System.Drawing.Point(120, 120)<br />
Me.Button3.Name = "Button3"<br />
Me.Button3.TabIndex = 4<br />
Me.Button3.Text = "Add Column"<br />
"<br />
"Form2<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(712, 429)<br />
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button3, Me.ListView2, Me.Button2, Me.ListView1, Me.Button1})<br />
Me.Name = "Form2"<br />
Me.Text = "ListView Example"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
ListView1.Columns.Clear()<br />
ListView1.Items.Clear()<br />
ListView1.View = View.Details<br />
ListView1.Columns.Add("Filename", 100, HorizontalAlignment.Left)<br />
ListView1.Columns.Add("Extension", 50, HorizontalAlignment.Left)<br />
ListView1.Columns.Add("Bytes", 50, HorizontalAlignment.Right)<br />
Dim DI As System.IO.DirectoryInfo = New System.IO.DirectoryInfo("c:\")<br />
Dim files() As System.IO.FileInfo = DI.GetFiles<br />
Dim file As System.IO.FileInfo<br />
Dim li As ListViewItem<br />
For Each file In files<br />
li = ListView1.Items.Add(file.Name)<br />
li.SubItems.Add(file.Extension)<br />
li.SubItems.Add(file.Length)<br />
Next<br />
End Sub<br />
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click<br />
ListView2.Items.Add("boo")<br />
End Sub<br />
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click<br />
ListView2.Columns.Add("mycolumn", 20, HorizontalAlignment.Center)<br />
End Sub<br />
End Class</source><br />
<br />
==Add file name to ListView==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class AddImageFileToListView<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents ListView1 As System.Windows.Forms.ListView<br />
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.ListView1 = New System.Windows.Forms.ListView()<br />
Me.PictureBox1 = New System.Windows.Forms.PictureBox()<br />
Me.Button1 = New System.Windows.Forms.Button()<br />
Me.TextBox1 = New System.Windows.Forms.TextBox()<br />
Me.SuspendLayout()<br />
"<br />
"ListView1<br />
"<br />
Me.ListView1.Location = New System.Drawing.Point(8, 16)<br />
Me.ListView1.MultiSelect = False<br />
Me.ListView1.Name = "ListView1"<br />
Me.ListView1.Size = New System.Drawing.Size(304, 232)<br />
Me.ListView1.TabIndex = 0<br />
Me.ListView1.View = System.Windows.Forms.View.Details<br />
"<br />
"PictureBox1<br />
"<br />
Me.PictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D<br />
Me.PictureBox1.Location = New System.Drawing.Point(320, 16)<br />
Me.PictureBox1.Name = "PictureBox1"<br />
Me.PictureBox1.Size = New System.Drawing.Size(600, 568)<br />
Me.PictureBox1.TabIndex = 1<br />
Me.PictureBox1.TabStop = False<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(8, 256)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.Size = New System.Drawing.Size(64, 24)<br />
Me.Button1.TabIndex = 2<br />
Me.Button1.Text = "New Path:"<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(8, 288)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(256, 20)<br />
Me.TextBox1.TabIndex = 3<br />
Me.TextBox1.Text = "c:\winnt"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(804, 585)<br />
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox1, Me.Button1, Me.PictureBox1, Me.ListView1})<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged<br />
PictureBox1.Image = Image.FromFile(ListView1.FocusedItem.Text)<br />
End Sub<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
ListView1.Columns.Clear()<br />
ListView1.View = View.Details<br />
ListView1.Columns.Add("Filename", 100, HorizontalAlignment.Left)<br />
ListView1.Columns.Add("Extension", 50, HorizontalAlignment.Left)<br />
ListView1.Columns.Add("Bytes", 50, HorizontalAlignment.Right)<br />
Dim DI As System.IO.DirectoryInfo = New System.IO.DirectoryInfo("c:\")<br />
Dim files() As System.IO.FileInfo = DI.GetFiles<br />
Dim file As System.IO.FileInfo<br />
For Each file In files<br />
Select Case file.Extension<br />
Case ".jpeg", ".gif", ".bmp", ".jpg", ".tif", ".tiff", ".avi"<br />
Dim li As New ListViewItem(file.FullName)<br />
li.SubItems.Add(file.Extension)<br />
li.SubItems.Add(file.Length)<br />
ListView1.Items.Add(li)<br />
End Select<br />
Next<br />
End Sub<br />
End Class</source><br />
<br />
==Change ListView state: LargeIcon, SmallIcon, List and Detail==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class ListViewState<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
Public Sub New()<br />
MyBase.New()<br />
InitializeComponent()<br />
End Sub<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
Private components As System.ruponentModel.IContainer<br />
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu<br />
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem<br />
Friend WithEvents ListView1 As System.Windows.Forms.ListView<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
Friend WithEvents Label2 As System.Windows.Forms.Label<br />
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents Button3 As System.Windows.Forms.Button<br />
Friend WithEvents ImageList1 As System.Windows.Forms.ImageList<br />
Friend WithEvents ImageList2 As System.Windows.Forms.ImageList<br />
Friend WithEvents ImageList3 As System.Windows.Forms.ImageList<br />
Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader<br />
Friend WithEvents ColumnHeader2 As System.Windows.Forms.ColumnHeader<br />
Friend WithEvents ColumnHeader3 As System.Windows.Forms.ColumnHeader<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.ruponents = New System.ruponentModel.Container<br />
Me.MainMenu1 = New System.Windows.Forms.MainMenu<br />
Me.MenuItem1 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem2 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem3 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem4 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem5 = New System.Windows.Forms.MenuItem<br />
Me.ListView1 = New System.Windows.Forms.ListView<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.Label1 = New System.Windows.Forms.Label<br />
Me.Label2 = New System.Windows.Forms.Label<br />
Me.TextBox2 = New System.Windows.Forms.TextBox<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.Button3 = New System.Windows.Forms.Button<br />
Me.ColumnHeader1 = New System.Windows.Forms.ColumnHeader<br />
Me.ColumnHeader2 = New System.Windows.Forms.ColumnHeader<br />
Me.ColumnHeader3 = New System.Windows.Forms.ColumnHeader<br />
Me.SuspendLayout()<br />
"<br />
"MainMenu1<br />
"<br />
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1})<br />
"<br />
"MenuItem1<br />
"<br />
Me.MenuItem1.Index = 0<br />
Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem2, Me.MenuItem3, Me.MenuItem4, Me.MenuItem5})<br />
Me.MenuItem1.Text = "View"<br />
"<br />
"MenuItem2<br />
"<br />
Me.MenuItem2.Index = 0<br />
Me.MenuItem2.Text = "Large Icon"<br />
"<br />
"MenuItem3<br />
"<br />
Me.MenuItem3.Index = 1<br />
Me.MenuItem3.Text = "Small Icon"<br />
"<br />
"MenuItem4<br />
"<br />
Me.MenuItem4.Index = 2<br />
Me.MenuItem4.Text = "List"<br />
"<br />
"MenuItem5<br />
"<br />
Me.MenuItem5.Index = 3<br />
Me.MenuItem5.Text = "Detail"<br />
"<br />
"ListView1<br />
"<br />
Me.ListView1.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2, Me.ColumnHeader3})<br />
Me.ListView1.Dock = System.Windows.Forms.DockStyle.Top<br />
Me.ListView1.Location = New System.Drawing.Point(0, 0)<br />
Me.ListView1.Name = "ListView1"<br />
Me.ListView1.Size = New System.Drawing.Size(328, 128)<br />
Me.ListView1.TabIndex = 0<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(88, 168)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(80, 20)<br />
Me.TextBox1.TabIndex = 1<br />
Me.TextBox1.Text = ""<br />
"<br />
"Label1<br />
"<br />
Me.Label1.Location = New System.Drawing.Point(48, 168)<br />
Me.Label1.Name = "Label1"<br />
Me.Label1.Size = New System.Drawing.Size(40, 24)<br />
Me.Label1.TabIndex = 2<br />
Me.Label1.Text = "Project"<br />
"<br />
"Label2<br />
"<br />
Me.Label2.Location = New System.Drawing.Point(16, 200)<br />
Me.Label2.Name = "Label2"<br />
Me.Label2.Size = New System.Drawing.Size(72, 24)<br />
Me.Label2.TabIndex = 3<br />
Me.Label2.Text = "No"<br />
"<br />
"TextBox2<br />
"<br />
Me.TextBox2.Location = New System.Drawing.Point(88, 200)<br />
Me.TextBox2.Name = "TextBox2"<br />
Me.TextBox2.Size = New System.Drawing.Size(80, 20)<br />
Me.TextBox2.TabIndex = 4<br />
Me.TextBox2.Text = ""<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(192, 184)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.Size = New System.Drawing.Size(72, 24)<br />
Me.Button1.TabIndex = 5<br />
Me.Button1.Text = "Add"<br />
"<br />
"Button3<br />
"<br />
Me.Button3.Location = New System.Drawing.Point(120, 240)<br />
Me.Button3.Name = "Button3"<br />
Me.Button3.Size = New System.Drawing.Size(80, 24)<br />
Me.Button3.TabIndex = 9<br />
Me.Button3.Text = "Delete"<br />
"<br />
"ColumnHeader1<br />
"<br />
Me.ColumnHeader1.Text = "File"<br />
"<br />
"ColumnHeader2<br />
"<br />
Me.ColumnHeader2.Text = "Size"<br />
"<br />
"ColumnHeader3<br />
"<br />
Me.ColumnHeader3.Text = "Change Date"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(328, 297)<br />
Me.Controls.Add(Me.Button3)<br />
Me.Controls.Add(Me.Button1)<br />
Me.Controls.Add(Me.TextBox2)<br />
Me.Controls.Add(Me.Label2)<br />
Me.Controls.Add(Me.Label1)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.Controls.Add(Me.ListView1)<br />
Me.Menu = Me.MainMenu1<br />
Me.ResumeLayout(False)<br />
End Sub<br />
<br />
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click<br />
ListView1.View = View.LargeIcon<br />
End Sub<br />
Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click<br />
ListView1.View = View.SmallIcon<br />
End Sub<br />
Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click<br />
ListView1.View = View.List<br />
End Sub<br />
Private Sub MenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem5.Click<br />
ListView1.View = View.Details<br />
End Sub<br />
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click<br />
ListView1.FocusedItem.Remove()<br />
End Sub<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
<br />
ListView1.Items.Add("new", 2)<br />
End Sub<br />
End Class</source><br />
<br />
==Creating List Views in Code==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class ListViewCreationInCode<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
Dim ListView1 As ListView<br />
Public Sub New()<br />
MyBase.New()<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(292, 273)<br />
Me.ResumeLayout(False)<br />
ListView1 = New ListView<br />
ListView1.Location = New Point(75, 90)<br />
ListView1.Size = New Size(150, 150)<br />
Controls.Add(ListView1)<br />
ListView1.Columns.Add("File Name", 200, HorizontalAlignment.Left)<br />
ListView1.Columns.Add("Size", 100, HorizontalAlignment.Left)<br />
ListView1.Columns.Add("Date", 100, HorizontalAlignment.Left)<br />
ListView1.Columns.Add("Attribute", 100, HorizontalAlignment.Center)<br />
Dim ListItem1 As ListViewItem<br />
ListItem1 = ListView1.Items.Add("Item 1")<br />
Dim ListItem2 As ListViewItem<br />
ListItem2 = ListView1.Items.Add("Item 2")<br />
Dim ListItem3 As ListViewItem<br />
ListItem3 = ListView1.Items.Add("Item 3")<br />
Dim ListItem4 As ListViewItem<br />
ListItem4 = ListView1.Items.Add("Item 4")<br />
ListView1.View = View.SmallIcon<br />
End Sub<br />
End Class</source><br />
<br />
==Displaying directories and their contents in ListView==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.IO<br />
Imports System.Windows.Forms<br />
public class LoadFileDirectoryInformationTreeView<br />
public Shared Sub Main<br />
Application.Run(New FrmListView)<br />
End Sub<br />
End class<br />
Public Class FrmListView<br />
Inherits Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
" display labels for current location in directory tree<br />
Friend WithEvents lblCurrent As Label<br />
Friend WithEvents lblDisplay As Label<br />
" displays contents of current directory<br />
Friend WithEvents lvwBrowser As ListView<br />
" specifies images for file icons and folder icons<br />
Friend WithEvents ilsFileFolder As ImageList<br />
<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.ruponents = New System.ruponentModel.Container()<br />
Me.ilsFileFolder = New System.Windows.Forms.ImageList(Me.ruponents)<br />
Me.lvwBrowser = New System.Windows.Forms.ListView()<br />
Me.lblCurrent = New System.Windows.Forms.Label()<br />
Me.lblDisplay = New System.Windows.Forms.Label()<br />
Me.SuspendLayout()<br />
"<br />
"ilsFileFolder<br />
"<br />
Me.ilsFileFolder.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit<br />
Me.ilsFileFolder.ImageSize = New System.Drawing.Size(16, 16)<br />
Me.ilsFileFolder.TransparentColor = System.Drawing.Color.Transparent<br />
"<br />
"lvwBrowser<br />
"<br />
Me.lvwBrowser.Location = New System.Drawing.Point(16, 88)<br />
Me.lvwBrowser.Name = "lvwBrowser"<br />
Me.lvwBrowser.RightToLeft = System.Windows.Forms.RightToLeft.No<br />
Me.lvwBrowser.Size = New System.Drawing.Size(448, 232)<br />
Me.lvwBrowser.SmallImageList = Me.ilsFileFolder<br />
Me.lvwBrowser.TabIndex = 2<br />
Me.lvwBrowser.View = System.Windows.Forms.View.List<br />
"<br />
"lblCurrent<br />
"<br />
Me.lblCurrent.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.lblCurrent.ForeColor = System.Drawing.SystemColors.WindowText<br />
Me.lblCurrent.Location = New System.Drawing.Point(16, 16)<br />
Me.lblCurrent.Name = "lblCurrent"<br />
Me.lblCurrent.Size = New System.Drawing.Size(112, 23)<br />
Me.lblCurrent.TabIndex = 0<br />
Me.lblCurrent.Text = "Now in Directory:"<br />
"<br />
"lblDisplay<br />
"<br />
Me.lblDisplay.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.lblDisplay.ForeColor = System.Drawing.SystemColors.WindowText<br />
Me.lblDisplay.Location = New System.Drawing.Point(128, 16)<br />
Me.lblDisplay.Name = "lblDisplay"<br />
Me.lblDisplay.Size = New System.Drawing.Size(344, 56)<br />
Me.lblDisplay.TabIndex = 1<br />
"<br />
"FrmListView<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(488, 341)<br />
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lvwBrowser, Me.lblDisplay, Me.lblCurrent})<br />
Me.Name = "FrmListView"<br />
Me.Text = "ListViewTest"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Dim currentDirectory As String = Directory.GetCurrentDirectory()<br />
Private Sub lvwBrowser_Click(ByVal sender As System.Object, _<br />
ByVal e As System.EventArgs) Handles lvwBrowser.Click<br />
If lvwBrowser.SelectedItems.Count <> 0 Then<br />
If lvwBrowser.Items(0).Selected Then<br />
Dim directoryObject As DirectoryInfo = _<br />
New DirectoryInfo(currentDirectory)<br />
If Not (directoryObject.Parent Is Nothing) Then<br />
LoadFilesInDirectory(directoryObject.Parent.FullName)<br />
End If<br />
Else<br />
Dim chosen As String = lvwBrowser.SelectedItems(0).Text<br />
If Directory.Exists(currentDirectory & "\" & chosen) Then<br />
If currentDirectory = "C:\" Then<br />
LoadFilesInDirectory(currentDirectory & chosen)<br />
Else<br />
LoadFilesInDirectory(currentDirectory & "\" & chosen)<br />
End If<br />
End If<br />
End If<br />
lblDisplay.Text = currentDirectory<br />
End If<br />
End Sub <br />
Public Sub LoadFilesInDirectory(ByVal currentDirectoryValue As String)<br />
lvwBrowser.Items.Clear()<br />
lvwBrowser.Items.Add("Go Up One Level")<br />
currentDirectory = currentDirectoryValue<br />
Dim newCurrentDirectory As DirectoryInfo = New DirectoryInfo(currentDirectory)<br />
Dim directoryArray As DirectoryInfo() = newCurrentDirectory.GetDirectories()<br />
Dim fileArray As FileInfo() = newCurrentDirectory.GetFiles()<br />
Dim dir As DirectoryInfo<br />
For Each dir In directoryArray<br />
Dim newDirectoryItem As ListViewItem = lvwBrowser.Items.Add(dir.Name)<br />
Next<br />
Dim file As FileInfo<br />
For Each file In fileArray<br />
Dim newFileItem As ListViewItem =lvwBrowser.Items.Add(file.Name)<br />
Next<br />
End Sub <br />
Private Sub FrmListView_Load(ByVal sender As System.Object, _<br />
ByVal e As System.EventArgs) Handles MyBase.Load<br />
LoadFilesInDirectory(currentDirectory)<br />
lblDisplay.Text = currentDirectory<br />
End Sub <br />
End Class</source><br />
<br />
==ListView Demo==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class ListViewIllustration<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Private Sub btnPopulate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPopulate.Click<br />
Dim intWidth As Integer<br />
Dim objItem As ListViewItem<br />
"Set the default view.<br />
ListView1.View = View.Details<br />
optDetails.Checked = True<br />
"Add the column headers.<br />
intWidth = ListView1.Width - 5<br />
ListView1.Columns.Add("Name", CInt(intWidth / 4))<br />
ListView1.Columns.Add("Address", CInt(intWidth / 4))<br />
ListView1.Columns.Add("Phone", CInt(intWidth / 4))<br />
ListView1.Columns.Add("FAX", CInt(intWidth / 4))<br />
"Add some list view items.<br />
objItem = ListView1.Items.Add("AAAAA")<br />
With objItem<br />
.SubItems.Add("123 Main St.")<br />
.SubItems.Add("555-555-5555")<br />
.SubItems.Add("555-555-5555")<br />
.ImageIndex = 0<br />
End With<br />
objItem = ListView1.Items.Add("BBBBB")<br />
With objItem<br />
.SubItems.Add("456 Main St.")<br />
.SubItems.Add("555-555-5555")<br />
.SubItems.Add("555-555-5555")<br />
.ImageIndex = 0<br />
End With<br />
End Sub<br />
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click<br />
Dim strItemText As String<br />
Dim objItem As ListViewItem<br />
"Add some list view items.<br />
strItemText = "name:"<br />
objItem = ListView1.Items.Add(strItemText)<br />
With objItem<br />
.SubItems.Add("123 Some St.")<br />
.SubItems.Add("555-555-5555")<br />
.SubItems.Add("555-555-5555")<br />
.ImageIndex = 0<br />
End With<br />
End Sub<br />
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click<br />
ListView1.Items.Clear()<br />
End Sub<br />
<br />
Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click<br />
Dim objListItem As ListViewItem<br />
For Each objListItem In ListView1.SelectedItems<br />
objListItem.Remove()<br />
Next objListItem<br />
End Sub<br />
Private Sub btnDisplayItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplayItem.Click<br />
Dim strMessage As String<br />
Dim objListItem As ListViewItem<br />
If ListView1.SelectedItems.Count > 0 Then<br />
objListItem = ListView1.SelectedItems(0)<br />
With objListItem<br />
strMessage = "NAME: " & .Text & vbCrLf & _<br />
"ADDRESS: " & .SubItems(1).Text & vbCrLf & _<br />
"PHONE: " & .SubItems(2).Text & vbCrLf & _<br />
"FAX: " & .SubItems(3).Text<br />
End With<br />
MsgBox(strMessage)<br />
End If<br />
End Sub<br />
<br />
Private Sub optLargeIcon_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optLargeIcon.CheckedChanged<br />
ListView1.View = View.LargeIcon<br />
End Sub<br />
Private Sub optSmallIcon_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optSmallIcon.CheckedChanged<br />
ListView1.View = View.SmallIcon<br />
End Sub<br />
Private Sub optList_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optList.CheckedChanged<br />
ListView1.View = View.List<br />
End Sub<br />
Private Sub optTile_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optTile.CheckedChanged<br />
ListView1.View = View.Tile<br />
End Sub<br />
Private Sub optDetails_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optDetails.CheckedChanged<br />
ListView1.View = View.Details<br />
End Sub<br />
End Class<br />
Partial Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.ruponents = New System.ruponentModel.Container<br />
Me.ListView1 = New System.Windows.Forms.ListView<br />
Me.btnPopulate = New System.Windows.Forms.Button<br />
Me.GroupBox1 = New System.Windows.Forms.GroupBox<br />
Me.optDetails = New System.Windows.Forms.RadioButton<br />
Me.optTile = New System.Windows.Forms.RadioButton<br />
Me.optList = New System.Windows.Forms.RadioButton<br />
Me.optSmallIcon = New System.Windows.Forms.RadioButton<br />
Me.optLargeIcon = New System.Windows.Forms.RadioButton<br />
Me.btnAdd = New System.Windows.Forms.Button<br />
Me.btnRemove = New System.Windows.Forms.Button<br />
Me.btnClear = New System.Windows.Forms.Button<br />
Me.btnDisplayItem = New System.Windows.Forms.Button<br />
Me.GroupBox1.SuspendLayout()<br />
Me.SuspendLayout()<br />
"<br />
"ListView1<br />
"<br />
Me.ListView1.FullRowSelect = True<br />
Me.ListView1.Location = New System.Drawing.Point(17, 18)<br />
Me.ListView1.Name = "ListView1"<br />
Me.ListView1.Size = New System.Drawing.Size(342, 364)<br />
Me.ListView1.TabIndex = 0<br />
Me.ListView1.UseCompatibleStateImageBehavior = False<br />
"<br />
"btnPopulate<br />
"<br />
Me.btnPopulate.Location = New System.Drawing.Point(366, 239)<br />
Me.btnPopulate.Name = "btnPopulate"<br />
Me.btnPopulate.Size = New System.Drawing.Size(161, 23)<br />
Me.btnPopulate.TabIndex = 2<br />
Me.btnPopulate.Text = "Populate"<br />
"<br />
"GroupBox1<br />
"<br />
Me.GroupBox1.Controls.Add(Me.optDetails)<br />
Me.GroupBox1.Controls.Add(Me.optTile)<br />
Me.GroupBox1.Controls.Add(Me.optList)<br />
Me.GroupBox1.Controls.Add(Me.optSmallIcon)<br />
Me.GroupBox1.Controls.Add(Me.optLargeIcon)<br />
Me.GroupBox1.Location = New System.Drawing.Point(370, 13)<br />
Me.GroupBox1.Name = "GroupBox1"<br />
Me.GroupBox1.Size = New System.Drawing.Size(156, 166)<br />
Me.GroupBox1.TabIndex = 1<br />
Me.GroupBox1.TabStop = False<br />
Me.GroupBox1.Text = "Views"<br />
"<br />
"optDetails<br />
"<br />
Me.optDetails.AutoSize = True<br />
Me.optDetails.Location = New System.Drawing.Point(30, 126)<br />
Me.optDetails.Name = "optDetails"<br />
Me.optDetails.Size = New System.Drawing.Size(57, 17)<br />
Me.optDetails.TabIndex = 4<br />
Me.optDetails.Text = "Details"<br />
"<br />
"optTile<br />
"<br />
Me.optTile.AutoSize = True<br />
Me.optTile.Location = New System.Drawing.Point(30, 102)<br />
Me.optTile.Name = "optTile"<br />
Me.optTile.Size = New System.Drawing.Size(42, 17)<br />
Me.optTile.TabIndex = 3<br />
Me.optTile.Text = "Tile"<br />
"<br />
"optList<br />
"<br />
Me.optList.AutoSize = True<br />
Me.optList.Location = New System.Drawing.Point(30, 78)<br />
Me.optList.Name = "optList"<br />
Me.optList.Size = New System.Drawing.Size(41, 17)<br />
Me.optList.TabIndex = 2<br />
Me.optList.Text = "List"<br />
"<br />
"optSmallIcon<br />
"<br />
Me.optSmallIcon.AutoSize = True<br />
Me.optSmallIcon.Location = New System.Drawing.Point(30, 54)<br />
Me.optSmallIcon.Name = "optSmallIcon"<br />
Me.optSmallIcon.Size = New System.Drawing.Size(79, 17)<br />
Me.optSmallIcon.TabIndex = 1<br />
Me.optSmallIcon.Text = "Small Icons"<br />
"<br />
"optLargeIcon<br />
"<br />
Me.optLargeIcon.AutoSize = True<br />
Me.optLargeIcon.Location = New System.Drawing.Point(30, 30)<br />
Me.optLargeIcon.Name = "optLargeIcon"<br />
Me.optLargeIcon.Size = New System.Drawing.Size(81, 17)<br />
Me.optLargeIcon.TabIndex = 0<br />
Me.optLargeIcon.Text = "Large Icons"<br />
"<br />
"btnAdd<br />
"<br />
Me.btnAdd.Location = New System.Drawing.Point(365, 269)<br />
Me.btnAdd.Name = "btnAdd"<br />
Me.btnAdd.Size = New System.Drawing.Size(161, 23)<br />
Me.btnAdd.TabIndex = 3<br />
Me.btnAdd.Text = "Add"<br />
"<br />
"btnRemove<br />
"<br />
Me.btnRemove.Location = New System.Drawing.Point(366, 299)<br />
Me.btnRemove.Name = "btnRemove"<br />
Me.btnRemove.Size = New System.Drawing.Size(161, 23)<br />
Me.btnRemove.TabIndex = 4<br />
Me.btnRemove.Text = "Remove"<br />
"<br />
"btnClear<br />
"<br />
Me.btnClear.Location = New System.Drawing.Point(365, 329)<br />
Me.btnClear.Name = "btnClear"<br />
Me.btnClear.Size = New System.Drawing.Size(161, 23)<br />
Me.btnClear.TabIndex = 5<br />
Me.btnClear.Text = "Clear"<br />
"<br />
"btnDisplayItem<br />
"<br />
Me.btnDisplayItem.Location = New System.Drawing.Point(365, 359)<br />
Me.btnDisplayItem.Name = "btnDisplayItem"<br />
Me.btnDisplayItem.Size = New System.Drawing.Size(161, 23)<br />
Me.btnDisplayItem.TabIndex = 6<br />
Me.btnDisplayItem.Text = "Display Item"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(539, 394)<br />
Me.Controls.Add(Me.btnDisplayItem)<br />
Me.Controls.Add(Me.btnClear)<br />
Me.Controls.Add(Me.btnRemove)<br />
Me.Controls.Add(Me.btnAdd)<br />
Me.Controls.Add(Me.GroupBox1)<br />
Me.Controls.Add(Me.btnPopulate)<br />
Me.Controls.Add(Me.ListView1)<br />
Me.Name = "Form1"<br />
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen<br />
Me.Text = "ListView"<br />
Me.GroupBox1.ResumeLayout(False)<br />
Me.GroupBox1.PerformLayout()<br />
Me.ResumeLayout(False)<br />
End Sub<br />
Friend WithEvents ListView1 As System.Windows.Forms.ListView<br />
Friend WithEvents btnPopulate As System.Windows.Forms.Button<br />
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox<br />
Friend WithEvents optDetails As System.Windows.Forms.RadioButton<br />
Friend WithEvents optTile As System.Windows.Forms.RadioButton<br />
Friend WithEvents optList As System.Windows.Forms.RadioButton<br />
Friend WithEvents optSmallIcon As System.Windows.Forms.RadioButton<br />
Friend WithEvents optLargeIcon As System.Windows.Forms.RadioButton<br />
Friend WithEvents btnAdd As System.Windows.Forms.Button<br />
Friend WithEvents btnRemove As System.Windows.Forms.Button<br />
Friend WithEvents btnClear As System.Windows.Forms.Button<br />
Friend WithEvents btnDisplayItem As System.Windows.Forms.Button<br />
Friend WithEvents ImageList1 As System.Windows.Forms.ImageList<br />
End Class</source><br />
<br />
==ListView ItemActivate event==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class TreeViewListView<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents TreeView1 As System.Windows.Forms.TreeView<br />
Friend WithEvents Splitter1 As System.Windows.Forms.Splitter<br />
Friend WithEvents ListView1 As System.Windows.Forms.ListView<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.ruponents = New System.ruponentModel.Container()<br />
Me.TreeView1 = New System.Windows.Forms.TreeView()<br />
Me.Splitter1 = New System.Windows.Forms.Splitter()<br />
Me.ListView1 = New System.Windows.Forms.ListView()<br />
Me.SuspendLayout()<br />
"<br />
"TreeView1<br />
"<br />
Me.TreeView1.Dock = System.Windows.Forms.DockStyle.Left<br />
Me.TreeView1.Name = "TreeView1"<br />
Me.TreeView1.Nodes.AddRange(New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Letter", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("a", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("z"), New System.Windows.Forms.TreeNode("b")}), New System.Windows.Forms.TreeNode("c", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("d"), New System.Windows.Forms.TreeNode("e")})})})<br />
Me.TreeView1.Size = New System.Drawing.Size(121, 273)<br />
Me.TreeView1.TabIndex = 0<br />
"<br />
"Splitter1<br />
"<br />
Me.Splitter1.Location = New System.Drawing.Point(121, 0)<br />
Me.Splitter1.Name = "Splitter1"<br />
Me.Splitter1.Size = New System.Drawing.Size(3, 273)<br />
Me.Splitter1.TabIndex = 1<br />
Me.Splitter1.TabStop = False<br />
"<br />
"ListView1<br />
"<br />
Me.ListView1.Dock = System.Windows.Forms.DockStyle.Fill<br />
Me.ListView1.Location = New System.Drawing.Point(124, 0)<br />
Me.ListView1.Name = "ListView1"<br />
Me.ListView1.Size = New System.Drawing.Size(168, 273)<br />
Me.ListView1.TabIndex = 2<br />
Me.ListView1.View = System.Windows.Forms.View.List<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(292, 273)<br />
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.ListView1, Me.Splitter1, Me.TreeView1})<br />
Me.Name = "Form1"<br />
Me.Text = "Vehicle Hierarchy"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect<br />
select case e.Node.Text<br />
case "a"<br />
listView1.Clear()<br />
listView1.Items.Add("a",3)<br />
listView1.Items.Add("b", 4)<br />
listView1.Items.Add("c", 6)<br />
case "b"<br />
listView1.Clear()<br />
listView1.Items.Add("a", 1)<br />
listView1.Items.Add("b", 2)<br />
listView1.Items.Add("c", 5)<br />
end select<br />
End Sub<br />
Private Sub ListView1_ItemActivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.ItemActivate<br />
dim strItem as String = listView1.FocusedItem.Text<br />
Console.WriteLine(strItem)<br />
End Sub<br />
End Class</source><br />
<br />
==ListView Item Check event==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class ListViewViewChange<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents ListView1 As System.Windows.Forms.ListView<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
Friend WithEvents ComboBox1 As System.Windows.Forms.ruboBox<br />
Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader<br />
Friend WithEvents ColumnHeader2 As System.Windows.Forms.ColumnHeader<br />
Friend WithEvents ColumnHeader3 As System.Windows.Forms.ColumnHeader<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.ruponents = New System.ruponentModel.Container<br />
Dim ListViewItem1 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem("Item 0", 0)<br />
Dim ListViewItem2 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem("Item 1", 0)<br />
Dim ListViewItem3 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem("Item 2", 0)<br />
Dim ListViewItem4 As System.Windows.Forms.ListViewItem = New System.Windows.Forms.ListViewItem("Item 3", 0)<br />
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))<br />
Me.ListView1 = New System.Windows.Forms.ListView<br />
Me.ColumnHeader1 = New System.Windows.Forms.ColumnHeader<br />
Me.ColumnHeader2 = New System.Windows.Forms.ColumnHeader<br />
Me.ColumnHeader3 = New System.Windows.Forms.ColumnHeader<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.ruboBox1 = New System.Windows.Forms.ruboBox<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.SuspendLayout()<br />
"<br />
"ListView1<br />
"<br />
Me.ListView1.AllowColumnReorder = True<br />
Me.ListView1.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2, Me.ColumnHeader3})<br />
Me.ListView1.Items.AddRange(New System.Windows.Forms.ListViewItem() {ListViewItem1, ListViewItem2, ListViewItem3, ListViewItem4})<br />
Me.ListView1.Location = New System.Drawing.Point(32, 104)<br />
Me.ListView1.Name = "ListView1"<br />
Me.ListView1.Size = New System.Drawing.Size(216, 112)<br />
Me.ListView1.TabIndex = 1<br />
"<br />
"ColumnHeader1<br />
"<br />
Me.ColumnHeader1.Text = "Column Header 1"<br />
"<br />
"ColumnHeader2<br />
"<br />
Me.ColumnHeader2.Text = "Column Header 2"<br />
"<br />
"ColumnHeader3<br />
"<br />
Me.ColumnHeader3.Text = "Column Header 3"<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(64, 232)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(160, 20)<br />
Me.TextBox1.TabIndex = 2<br />
Me.TextBox1.Text = ""<br />
"<br />
"ComboBox1<br />
"<br />
Me.ruboBox1.Items.AddRange(New Object() {"Large Icon View", "Report View", "Small Icon View", "List View"})<br />
Me.ruboBox1.Location = New System.Drawing.Point(16, 64)<br />
Me.ruboBox1.Name = "ComboBox1"<br />
Me.ruboBox1.Size = New System.Drawing.Size(121, 21)<br />
Me.ruboBox1.TabIndex = 3<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(144, 64)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.Size = New System.Drawing.Size(112, 23)<br />
Me.Button1.TabIndex = 4<br />
Me.Button1.Text = "Show Check Boxes"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(292, 273)<br />
Me.Controls.Add(Me.Button1)<br />
Me.Controls.Add(Me.ruboBox1)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.Controls.Add(Me.ListView1)<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged<br />
ListView1.View = ComboBox1.SelectedIndex<br />
End Sub<br />
Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged<br />
If ListView1.SelectedIndices.Count > 0 Then<br />
TextBox1.Text = "Item " & ListView1.SelectedIndices(0) & " was clicked."<br />
End If<br />
End Sub<br />
Private Sub ListView1_ColumnClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles ListView1.ColumnClick<br />
TextBox1.Text = "Column " & (e.Column + 1) & " was clicked."<br />
End Sub<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
ListView1.CheckBoxes = True<br />
End Sub<br />
Private Sub ListView1_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles ListView1.ItemCheck<br />
If e.NewValue = CheckState.Checked Then<br />
TextBox1.Text = "Item " & e.Index() & " is checked."<br />
Else<br />
TextBox1.Text = "Item " & e.Index() & " is not checked."<br />
End If<br />
End Sub<br />
End Class</source><br />
<br />
==ListView with CheckBox cell==<br />
<br />
<br />
<br />
<source lang="vbnet">"Visual Basic.Net JingCai Programming 100 Examples<br />
"Author: Yong Zhang<br />
"Publisher: Water Publisher China<br />
"ISBN: 750841156<br />
<br />
Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
Imports System.Runtime.InteropServices<br />
Imports System.IO<br />
public class FileListView<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<br />
Public Class Form1<br />
Dim nIndex As Integer = 0<br />
Private Sub CreateMyListView(ByVal dirpath As String)<br />
Dim hImgSmall As IntPtr<br />
Dim hImgLarge As IntPtr<br />
Dim shinfo As FileInfoClass.SHFILEINFO = New FileInfoClass.SHFILEINFO()<br />
ListView1.Clear()<br />
ImageListSmall.Images.Clear()<br />
ImageListLarge.Images.Clear()<br />
nIndex = 0<br />
ListView1.Columns.Add("File Name", 200, HorizontalAlignment.Left)<br />
ListView1.Columns.Add("Size", 100, HorizontalAlignment.Left)<br />
ListView1.Columns.Add("Date", 100, HorizontalAlignment.Left)<br />
ListView1.Columns.Add("Attribute", 100, HorizontalAlignment.Center)<br />
ListView1.LargeImageList = imageListLarge<br />
ListView1.SmallImageList = imageListSmall<br />
ListView1.View = View.Details<br />
ListView1.LabelEdit = True<br />
ListView1.AllowColumnReorder = True<br />
ListView1.CheckBoxes = True<br />
ListView1.FullRowSelect = True<br />
ListView1.GridLines = True<br />
ListView1.Sorting = SortOrder.Ascending<br />
Dim FilesInDir As String() = Directory.GetFiles(dirpath, "*.*")<br />
Dim SFile As String<br />
Dim item1 As New ListViewItem("", 0)<br />
item1.SubItems.Add("1")<br />
item1.SubItems.Add("2")<br />
item1.SubItems.Add("3")<br />
Dim ctdate As Date<br />
Dim fAttr As FileAttribute<br />
For Each SFile In FilesInDir<br />
ctdate = IO.File.GetCreationTime(SFile)<br />
fAttr = IO.File.GetAttributes(SFile)<br />
shinfo.szDisplayName = New String(Chr(0), 260)<br />
shinfo.szTypeName = New String(Chr(0), 80)<br />
hImgSmall = FileInfoClass.SHGetFileInfo(SFile, 0, shinfo, _<br />
Marshal.SizeOf(shinfo), _<br />
FileInfoClass.SHGFI_ICON Or FileInfoClass.SHGFI_SMALLICON)<br />
ImageListSmall.Images.Add(System.Drawing.Icon.FromHandle(shinfo.hIcon)) "Add icon to smallimageList.<br />
hImgLarge = FileInfoClass.SHGetFileInfo(SFile, 0, shinfo, _<br />
Marshal.SizeOf(shinfo), _<br />
FileInfoClass.SHGFI_ICON Or FileInfoClass.SHGFI_LARGEICON)<br />
ImageListLarge.Images.Add(System.Drawing.Icon.FromHandle(shinfo.hIcon)) "Add icon to LargeimageList.<br />
ListView1.Items.Add(New ListViewItem(New String() {SFile, CStr(FileLen(SFile)), ctdate.ToString, fAttr.ToString}, nIndex))<br />
nIndex = nIndex + 1<br />
Next<br />
End Sub<br />
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
Dim disks As String() = Directory.GetLogicalDrives<br />
Dim Sdisk As String<br />
ComboBox1.Items.Clear()<br />
For Each Sdisk In disks<br />
ComboBox1.Items.Add(Sdisk)<br />
Next<br />
End Sub<br />
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged<br />
CreateMyListView(ComboBox1.Text)<br />
End Sub<br />
End Class<br />
Public Class FileInfoClass<br />
Public Structure SHFILEINFO<br />
Public hIcon As IntPtr <br />
Public iIcon As Integer <br />
Public dwAttributes As Integer <br />
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _<br />
Public szDisplayName As String<br />
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)> _<br />
Public szTypeName As String<br />
End Structure<br />
Public Declare Auto Function SHGetFileInfo Lib "shell32.dll" _<br />
(ByVal pszPath As String, _<br />
ByVal dwFileAttributes As Integer, _<br />
ByRef psfi As SHFILEINFO, _<br />
ByVal cbFileInfo As Integer, _<br />
ByVal uFlags As Integer) As IntPtr<br />
Public Const SHGFI_ICON = &H100<br />
Public Const SHGFI_SMALLICON = &H1<br />
Public Const SHGFI_LARGEICON = &H0 " Large icon<br />
End Class<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.ruponents = New System.ruponentModel.Container<br />
Me.ruboBox1 = New System.Windows.Forms.ruboBox<br />
Me.ListView1 = New System.Windows.Forms.ListView<br />
Me.ImageListSmall = New System.Windows.Forms.ImageList(Me.ruponents)<br />
Me.ImageListLarge = New System.Windows.Forms.ImageList(Me.ruponents)<br />
Me.SuspendLayout()<br />
"<br />
"ComboBox1<br />
"<br />
Me.ruboBox1.FormattingEnabled = True<br />
Me.ruboBox1.Location = New System.Drawing.Point(12, 3)<br />
Me.ruboBox1.Name = "ComboBox1"<br />
Me.ruboBox1.Size = New System.Drawing.Size(413, 20)<br />
Me.ruboBox1.TabIndex = 0<br />
"<br />
"ListView1<br />
"<br />
Me.ListView1.Location = New System.Drawing.Point(12, 29)<br />
Me.ListView1.Name = "ListView1"<br />
Me.ListView1.Size = New System.Drawing.Size(413, 207)<br />
Me.ListView1.TabIndex = 1<br />
Me.ListView1.UseCompatibleStateImageBehavior = False<br />
"<br />
"ImageListSmall<br />
"<br />
Me.ImageListSmall.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit<br />
Me.ImageListSmall.ImageSize = New System.Drawing.Size(16, 16)<br />
Me.ImageListSmall.TransparentColor = System.Drawing.Color.Transparent<br />
"<br />
"ImageListLarge<br />
"<br />
Me.ImageListLarge.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit<br />
Me.ImageListLarge.ImageSize = New System.Drawing.Size(16, 16)<br />
Me.ImageListLarge.TransparentColor = System.Drawing.Color.Transparent<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(437, 246)<br />
Me.Controls.Add(Me.ListView1)<br />
Me.Controls.Add(Me.ruboBox1)<br />
Me.ResumeLayout(False)<br />
End Sub<br />
Friend WithEvents ComboBox1 As System.Windows.Forms.ruboBox<br />
Friend WithEvents ListView1 As System.Windows.Forms.ListView<br />
Friend WithEvents ImageListSmall As System.Windows.Forms.ImageList<br />
Friend WithEvents ImageListLarge As System.Windows.Forms.ImageList<br />
End Class</source><br />
<br />
==Runtime ListView==<br />
<br />
<br />
<br />
<source lang="vbnet">"Visual Basic 2005 Programmer"s Reference<br />
"by Rod Stephens (Author) <br />
"# Publisher: Wrox (October 21, 2005)<br />
"# Language: English<br />
"# ISBN-10: 0764571982<br />
"# ISBN-13: 978-0764571985<br />
<br />
Imports System.Windows.Forms<br />
<br />
public class ListViewRunTime<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
" Make the ListView column headers.<br />
ListViewMakeColumnHeaders(lvwBooks, _<br />
"Title", HorizontalAlignment.Left, 120, _<br />
"URL", HorizontalAlignment.Left, 120, _<br />
"ISBN", HorizontalAlignment.Left, 90, _<br />
"Picture", HorizontalAlignment.Left, 120, _<br />
"Pages", HorizontalAlignment.Right, 50, _<br />
"Year", HorizontalAlignment.Right, 40)<br />
ListViewMakeRow(lvwBooks, 0, _<br />
"Visual Basic and XML", _<br />
"http://www.vb-helper.ru/xml.htm", _<br />
"0-471-12060-X", _<br />
"http://www.vb-helper.ru/xml.jpg", _<br />
"503", _<br />
"2002")<br />
ListViewMakeRow(lvwBooks, 0, _<br />
"Visual Basic Graphics Programming, 2e", _<br />
"http://www.vb-helper.ru/vbgp.htm", _<br />
"0-471-35599-2", _<br />
"http://www.vb-helper.ru/vbgp.jpg", _<br />
"712", _<br />
"2000")<br />
ListViewMakeRow(lvwBooks, 0, _<br />
"Ready-to-Run Visual Basic Algorithms", _<br />
"http://www.vb-helper.ru/vba.htm", _<br />
"0-471-24268-3", _<br />
"http://www.vb-helper.ru/vba.jpg", _<br />
"395", _<br />
"1998")<br />
ListViewSizeColumns(lvwBooks, True)<br />
Text = "RunTimeListView (" & lvwBooks.View.ToString & ")"<br />
lvwBooks.View = View.Details<br />
CheckMenus()<br />
End Sub<br />
" Make the ListView"s column headers.<br />
" The ParamArray entries should be triples holding<br />
" column title, HorizontalAlignment value, and width.<br />
Private Sub ListViewMakeColumnHeaders(ByVal lvw As ListView, ByVal ParamArray header_info() As Object)<br />
" Remove any existing headers.<br />
lvw.Columns.Clear()<br />
" Make the column headers.<br />
For i As Integer = header_info.GetLowerBound(0) To header_info.GetUpperBound(0) Step 3<br />
Dim col_header As ColumnHeader = lvw.Columns.Add( _<br />
DirectCast(header_info(i), String), _<br />
-1, _<br />
DirectCast(header_info(i + 1), HorizontalAlignment))<br />
col_header.Width = DirectCast(header_info(i + 2), Integer)<br />
Next i<br />
End Sub<br />
" Make a ListView row.<br />
Private Sub ListViewMakeRow(ByVal lvw As ListView, ByVal image_index As Integer, ByVal item_title As String, ByVal ParamArray subitem_titles() As String)<br />
" Make the item.<br />
Dim new_item As ListViewItem = lvw.Items.Add(item_title)<br />
new_item.ImageIndex = image_index<br />
" Make the sub-items.<br />
For i As Integer = subitem_titles.GetLowerBound(0) To subitem_titles.GetUpperBound(0)<br />
new_item.SubItems.Add(subitem_titles(i))<br />
Next i<br />
End Sub<br />
" Set column widths to -1 to fit data,<br />
" -2 to fit data and header.<br />
Private Sub ListViewSizeColumns(ByVal lvw As ListView, ByVal allow_room_for_header As Boolean)<br />
Dim new_wid As Integer = -1<br />
If allow_room_for_header Then new_wid = -2<br />
" Set the width for each column.<br />
For i As Integer = 0 To lvw.Columns.Count - 1<br />
lvw.Columns(i).Width = new_wid<br />
Next i<br />
End Sub<br />
Private Sub mnuViewDetails_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuViewDetails.Click<br />
lvwBooks.View = View.Details<br />
Text = "RunTimeListView (" & lvwBooks.View.ToString & ")"<br />
CheckMenus()<br />
End Sub<br />
Private Sub mnuViewLargeIcons_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuViewLargeIcons.Click<br />
lvwBooks.View = View.LargeIcon<br />
Text = "RunTimeListView (" & lvwBooks.View.ToString & ")"<br />
CheckMenus()<br />
End Sub<br />
Private Sub mnuViewList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuViewList.Click<br />
lvwBooks.View = View.List<br />
Text = "RunTimeListView (" & lvwBooks.View.ToString & ")"<br />
CheckMenus()<br />
End Sub<br />
Private Sub mnuViewSmallIcons_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuViewSmallIcons.Click<br />
lvwBooks.View = View.SmallIcon<br />
Text = "RunTimeListView (" & lvwBooks.View.ToString & ")"<br />
CheckMenus()<br />
End Sub<br />
Private Sub mnuViewTile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuViewTile.Click<br />
lvwBooks.View = View.Tile<br />
Text = "RunTimeListView (" & lvwBooks.View.ToString & ")"<br />
CheckMenus()<br />
End Sub<br />
Private Sub CheckMenus()<br />
mnuViewDetails.Checked = (lvwBooks.View = View.Details)<br />
mnuViewLargeIcons.Checked = (lvwBooks.View = View.LargeIcon)<br />
mnuViewList.Checked = (lvwBooks.View = View.List)<br />
mnuViewSmallIcons.Checked = (lvwBooks.View = View.SmallIcon)<br />
mnuViewTile.Checked = (lvwBooks.View = View.Tile)<br />
End Sub<br />
End Class<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.ruponents = New System.ruponentModel.Container<br />
Me.MenuStrip1 = New System.Windows.Forms.MenuStrip<br />
Me.ViewToolStripMenuItem = New System.Windows.Forms.ToolStripMenuItem<br />
Me.mnuViewDetails = New System.Windows.Forms.ToolStripMenuItem<br />
Me.mnuViewLargeIcons = New System.Windows.Forms.ToolStripMenuItem<br />
Me.mnuViewList = New System.Windows.Forms.ToolStripMenuItem<br />
Me.mnuViewSmallIcons = New System.Windows.Forms.ToolStripMenuItem<br />
Me.mnuViewTile = New System.Windows.Forms.ToolStripMenuItem<br />
Me.lvwBooks = New System.Windows.Forms.ListView<br />
Me.MenuStrip1.SuspendLayout()<br />
Me.SuspendLayout()<br />
"<br />
"MenuStrip1<br />
"<br />
Me.MenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ViewToolStripMenuItem})<br />
Me.MenuStrip1.Location = New System.Drawing.Point(0, 0)<br />
Me.MenuStrip1.Name = "MenuStrip1"<br />
Me.MenuStrip1.Size = New System.Drawing.Size(592, 24)<br />
Me.MenuStrip1.TabIndex = 2<br />
Me.MenuStrip1.Text = "MenuStrip1"<br />
"<br />
"ViewToolStripMenuItem<br />
"<br />
Me.ViewToolStripMenuItem.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.mnuViewDetails, Me.mnuViewLargeIcons, Me.mnuViewList, Me.mnuViewSmallIcons, Me.mnuViewTile})<br />
Me.ViewToolStripMenuItem.Name = "ViewToolStripMenuItem"<br />
Me.ViewToolStripMenuItem.Text = "&View"<br />
"<br />
"mnuViewDetails<br />
"<br />
Me.mnuViewDetails.Name = "mnuViewDetails"<br />
Me.mnuViewDetails.Text = "&Details"<br />
"<br />
"mnuViewLargeIcons<br />
"<br />
Me.mnuViewLargeIcons.Name = "mnuViewLargeIcons"<br />
Me.mnuViewLargeIcons.Text = "Large Icons"<br />
"<br />
"mnuViewList<br />
"<br />
Me.mnuViewList.Name = "mnuViewList"<br />
Me.mnuViewList.Text = "&List"<br />
"<br />
"mnuViewSmallIcons<br />
"<br />
Me.mnuViewSmallIcons.Name = "mnuViewSmallIcons"<br />
Me.mnuViewSmallIcons.Text = "&Small Icons"<br />
"<br />
"mnuViewTile<br />
"<br />
Me.mnuViewTile.Name = "mnuViewTile"<br />
Me.mnuViewTile.Text = "Tile"<br />
"<br />
"lvwBooks<br />
"<br />
Me.lvwBooks.Dock = System.Windows.Forms.DockStyle.Fill<br />
Me.lvwBooks.Location = New System.Drawing.Point(0, 24)<br />
Me.lvwBooks.Name = "lvwBooks"<br />
Me.lvwBooks.Size = New System.Drawing.Size(592, 249)<br />
Me.lvwBooks.TabIndex = 1<br />
Me.lvwBooks.View = System.Windows.Forms.View.Details<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(592, 273)<br />
Me.Controls.Add(Me.lvwBooks)<br />
Me.Controls.Add(Me.MenuStrip1)<br />
Me.Name = "Form1"<br />
Me.Text = "RunTimeListView"<br />
Me.MenuStrip1.ResumeLayout(False)<br />
Me.ResumeLayout(False)<br />
Me.PerformLayout()<br />
End Sub<br />
Friend WithEvents MenuStrip1 As System.Windows.Forms.MenuStrip<br />
Friend WithEvents ViewToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem<br />
Friend WithEvents mnuViewDetails As System.Windows.Forms.ToolStripMenuItem<br />
Friend WithEvents mnuViewLargeIcons As System.Windows.Forms.ToolStripMenuItem<br />
Friend WithEvents mnuViewList As System.Windows.Forms.ToolStripMenuItem<br />
Friend WithEvents mnuViewSmallIcons As System.Windows.Forms.ToolStripMenuItem<br />
Friend WithEvents mnuViewTile As System.Windows.Forms.ToolStripMenuItem<br />
Friend WithEvents lvwBooks As System.Windows.Forms.ListView<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/DateTimePicker&diff=3875
VB.Net Tutorial/GUI/DateTimePicker
2010-05-26T12:57:17Z
<p>Admin: 1 версия</p>
<hr />
<div>==DataTimePicker format==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class DataTimePickerFormat<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
Public Sub New()<br />
MyBase.New()<br />
InitializeComponent()<br />
End Sub<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
Private components As System.ruponentModel.IContainer<br />
Friend WithEvents DateTimePicker1 As System.Windows.Forms.DateTimePicker<br />
Friend WithEvents ComboBox1 As System.Windows.Forms.ruboBox<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.DateTimePicker1 = New System.Windows.Forms.DateTimePicker<br />
Me.ruboBox1 = New System.Windows.Forms.ruboBox<br />
Me.Label1 = New System.Windows.Forms.Label<br />
Me.SuspendLayout()<br />
"<br />
"DateTimePicker1<br />
"<br />
Me.DateTimePicker1.Location = New System.Drawing.Point(40, 24)<br />
Me.DateTimePicker1.Name = "DateTimePicker1"<br />
Me.DateTimePicker1.Size = New System.Drawing.Size(120, 20)<br />
Me.DateTimePicker1.TabIndex = 0<br />
"<br />
"ComboBox1<br />
"<br />
Me.ruboBox1.Items.AddRange(New Object() {"Long", "Short", "Custom", "Time"})<br />
Me.ruboBox1.Location = New System.Drawing.Point(40, 200)<br />
Me.ruboBox1.Name = "ComboBox1"<br />
Me.ruboBox1.Size = New System.Drawing.Size(120, 21)<br />
Me.ruboBox1.TabIndex = 1<br />
"<br />
"Label1<br />
"<br />
Me.Label1.Location = New System.Drawing.Point(40, 160)<br />
Me.Label1.Name = "Label1"<br />
Me.Label1.Size = New System.Drawing.Size(80, 24)<br />
Me.Label1.TabIndex = 2<br />
Me.Label1.Text = "Format"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(292, 266)<br />
Me.Controls.Add(Me.Label1)<br />
Me.Controls.Add(Me.ruboBox1)<br />
Me.Controls.Add(Me.DateTimePicker1)<br />
Me.Name = "Form1"<br />
Me.Text = "DateTimePicker"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged<br />
If ComboBox1.SelectedIndex < 0 Then<br />
Return<br />
End If<br />
Dim caption As String = ComboBox1.SelectedItem.ToString().Chars(0)<br />
Dim format As DateTimePickerFormat<br />
Select Case caption<br />
Case "S"c<br />
format = DateTimePickerFormat.Short<br />
Case "T"c<br />
format = DateTimePickerFormat.Time<br />
Case "C"c<br />
format = DateTimePickerFormat.Custom<br />
Case Else<br />
format = DateTimePickerFormat.Long<br />
End Select<br />
DateTimePicker1.Format = format<br />
End Sub<br />
End Class</source><br />
<br />
==DateTimePicker format: LongDate, LongTime, ShortDate, ShortTime==<br />
<br />
<br />
<br />
<source lang="vbnet">Option Strict On<br />
imports System<br />
imports System.Drawing<br />
imports System.Windows.Forms<br />
public class DTPicker : inherits Form<br />
dim dtp as DateTimePicker<br />
public sub New()<br />
Size = new Size(400,300)<br />
AddHandler me.Load, AddressOf me_Load<br />
dtp = new DateTimePicker()<br />
dtp.Parent = me<br />
dtp.Location = new Point(20,20)<br />
dtp.Size = new Size(ClientSize.Width - 40, dtp.PreferredHeight)<br />
dtp.Anchor = AnchorStyles.Top or AnchorStyles.Left or AnchorStyles.Right<br />
dim fnt as new Font("Times New Roman", 16)<br />
dtp.CalendarFont = new Font(fnt, FontStyle.Bold or FontStyle.Italic)<br />
dtp.CalendarForeColor = Color.Red<br />
dtp.CalendarMonthBackground = Color.Yellow<br />
dtp.CalendarTitleBackColor = Color.Lime<br />
dtp.CalendarTitleForeColor = Color.Blue<br />
dtp.CalendarTrailingForeColor = Color.FromArgb(255,192,192)<br />
dtp.CustomFormat = "dddd,MMMM d, yyyy "at" h:mm:ss tt"<br />
dtp.Format = DateTimePickerFormat.Custom<br />
dtp.DropDownAlign = LeftRightAlignment.Right<br />
dtp.ShowUpDown = false " default<br />
AddHandler dtp.ValueChanged, AddressOf dtp_ValueChanged<br />
end sub<br />
public shared sub Main() <br />
Application.Run(new DTPicker())<br />
end sub<br />
private sub UpdateLabels()<br />
Console.WriteLine(dtp.Value.ToString())<br />
Console.WriteLine(dtp.Value.ToLongDateString())<br />
Console.WriteLine(dtp.Value.ToLongTimeString())<br />
Console.WriteLine(dtp.Value.ToShortDateString())<br />
Console.WriteLine(dtp.Value.ToShortTimeString())<br />
end sub<br />
private sub me_Load(ByVal sender as object,ByVal e as EventArgs)<br />
UpdateLabels()<br />
end sub<br />
private sub dtp_ValueChanged(ByVal sender as object,ByVal e as EventArgs)<br />
UpdateLabels()<br />
end sub<br />
private sub txtCustomString_TextChanged(ByVal sender as object,ByVal e as EventArgs)<br />
UpdateLabels()<br />
end sub<br />
end class</source><br />
<br />
==Get value from DateTimePicker==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class UseMonthCalendarAndDateTimePicker<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged<br />
" ----- Check and display only valid dates.<br />
If (IsDate(TextBox1.Text) = True) Then<br />
Label1.Text = Date.Parse(TextBox1.Text).ToShortDateString<br />
Else<br />
Label1.Text = ""<br />
End If<br />
End Sub<br />
Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged<br />
" ----- Show the selected date.<br />
Label2.Text = DateTimePicker1.Value.ToShortDateString<br />
End Sub<br />
Private Sub MonthCalendar1_DateChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateChanged<br />
" ---- Show the slected date.<br />
Label3.Text = MonthCalendar1.SelectionStart.ToShortDateString<br />
End Sub<br />
End Class<br />
<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.DateTimePicker1 = New System.Windows.Forms.DateTimePicker<br />
Me.MonthCalendar1 = New System.Windows.Forms.MonthCalendar<br />
Me.Label1 = New System.Windows.Forms.Label<br />
Me.Label2 = New System.Windows.Forms.Label<br />
Me.Label3 = New System.Windows.Forms.Label<br />
Me.Label4 = New System.Windows.Forms.Label<br />
Me.Label5 = New System.Windows.Forms.Label<br />
Me.Label6 = New System.Windows.Forms.Label<br />
Me.SuspendLayout()<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(72, 8)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(120, 20)<br />
Me.TextBox1.TabIndex = 0<br />
Me.TextBox1.Text = "2007-12-07"<br />
"<br />
"DateTimePicker1<br />
"<br />
Me.DateTimePicker1.Location = New System.Drawing.Point(72, 48)<br />
Me.DateTimePicker1.Name = "DateTimePicker1"<br />
Me.DateTimePicker1.Size = New System.Drawing.Size(200, 20)<br />
Me.DateTimePicker1.TabIndex = 1<br />
Me.DateTimePicker1.Value = New Date(2007, 12, 7, 0, 0, 0, 0)<br />
"<br />
"MonthCalendar1<br />
"<br />
Me.MonthCalendar1.Location = New System.Drawing.Point(72, 88)<br />
Me.MonthCalendar1.Name = "MonthCalendar1"<br />
Me.MonthCalendar1.TabIndex = 2<br />
"<br />
"Label1<br />
"<br />
Me.Label1.AutoSize = True<br />
Me.Label1.Location = New System.Drawing.Point(296, 16)<br />
Me.Label1.Name = "Label1"<br />
Me.Label1.Size = New System.Drawing.Size(39, 13)<br />
Me.Label1.TabIndex = 3<br />
Me.Label1.Text = "Label1"<br />
"<br />
"Label2<br />
"<br />
Me.Label2.AutoSize = True<br />
Me.Label2.Location = New System.Drawing.Point(296, 48)<br />
Me.Label2.Name = "Label2"<br />
Me.Label2.Size = New System.Drawing.Size(39, 13)<br />
Me.Label2.TabIndex = 4<br />
Me.Label2.Text = "Label2"<br />
"<br />
"Label3<br />
"<br />
Me.Label3.AutoSize = True<br />
Me.Label3.Location = New System.Drawing.Point(296, 88)<br />
Me.Label3.Name = "Label3"<br />
Me.Label3.Size = New System.Drawing.Size(39, 13)<br />
Me.Label3.TabIndex = 5<br />
Me.Label3.Text = "Label3"<br />
"<br />
"Label4<br />
"<br />
Me.Label4.AutoSize = True<br />
Me.Label4.Location = New System.Drawing.Point(8, 10)<br />
Me.Label4.Name = "Label4"<br />
Me.Label4.Size = New System.Drawing.Size(57, 13)<br />
Me.Label4.TabIndex = 6<br />
Me.Label4.Text = "Plain Text:"<br />
"<br />
"Label5<br />
"<br />
Me.Label5.AutoSize = True<br />
Me.Label5.Location = New System.Drawing.Point(8, 50)<br />
Me.Label5.Name = "Label5"<br />
Me.Label5.Size = New System.Drawing.Size(40, 13)<br />
Me.Label5.TabIndex = 7<br />
Me.Label5.Text = "Picker:"<br />
"<br />
"Label6<br />
"<br />
Me.Label6.AutoSize = True<br />
Me.Label6.Location = New System.Drawing.Point(8, 88)<br />
Me.Label6.Name = "Label6"<br />
Me.Label6.Size = New System.Drawing.Size(52, 13)<br />
Me.Label6.TabIndex = 8<br />
Me.Label6.Text = "Calendar:"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(510, 258)<br />
Me.Controls.Add(Me.Label6)<br />
Me.Controls.Add(Me.Label5)<br />
Me.Controls.Add(Me.Label4)<br />
Me.Controls.Add(Me.Label3)<br />
Me.Controls.Add(Me.Label2)<br />
Me.Controls.Add(Me.Label1)<br />
Me.Controls.Add(Me.MonthCalendar1)<br />
Me.Controls.Add(Me.DateTimePicker1)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.Name = "Form1"<br />
Me.Text = "Using Controls to Enter or Select a Date"<br />
Me.ResumeLayout(False)<br />
Me.PerformLayout()<br />
End Sub<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
Friend WithEvents DateTimePicker1 As System.Windows.Forms.DateTimePicker<br />
Friend WithEvents MonthCalendar1 As System.Windows.Forms.MonthCalendar<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
Friend WithEvents Label2 As System.Windows.Forms.Label<br />
Friend WithEvents Label3 As System.Windows.Forms.Label<br />
Friend WithEvents Label4 As System.Windows.Forms.Label<br />
Friend WithEvents Label5 As System.Windows.Forms.Label<br />
Friend WithEvents Label6 As System.Windows.Forms.Label<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/NumericUpDown&diff=3877
VB.Net Tutorial/GUI/NumericUpDown
2010-05-26T12:57:17Z
<p>Admin: 1 версия</p>
<hr />
<div>==Get value from the NumericUpDown control==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class GetValueFromNumericUpDown<br />
public Shared Sub Main<br />
Application.Run(New FrmInterestCalculator)<br />
End Sub<br />
End class<br />
Public Class FrmInterestCalculator<br />
Private Sub btnCalculate_Click(ByVal sender As System.Object, _<br />
ByVal e As System.EventArgs) Handles btnCalculate.Click<br />
<br />
Console.WriteLine(Convert.ToInt32(updYear.Value))<br />
End Sub<br />
End Class<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Class FrmInterestCalculator<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.btnCalculate = New System.Windows.Forms.Button<br />
Me.txtDisplay = New System.Windows.Forms.TextBox<br />
Me.lblBalance = New System.Windows.Forms.Label<br />
Me.updYear = New System.Windows.Forms.NumericUpDown<br />
Me.lblYears = New System.Windows.Forms.Label<br />
Me.txtInterest = New System.Windows.Forms.TextBox<br />
Me.lblInterest = New System.Windows.Forms.Label<br />
Me.txtPrincipal = New System.Windows.Forms.TextBox<br />
Me.lblPrincipal = New System.Windows.Forms.Label<br />
CType(Me.updYear, System.ruponentModel.ISupportInitialize).BeginInit()<br />
Me.SuspendLayout()<br />
"<br />
"btnCalculate<br />
"<br />
Me.btnCalculate.Location = New System.Drawing.Point(197, 14)<br />
Me.btnCalculate.Name = "btnCalculate"<br />
Me.btnCalculate.Size = New System.Drawing.Size(75, 23)<br />
Me.btnCalculate.TabIndex = 17<br />
Me.btnCalculate.Text = "Calculate"<br />
"<br />
"txtDisplay<br />
"<br />
Me.txtDisplay.BackColor = System.Drawing.SystemColors.Control<br />
Me.txtDisplay.Location = New System.Drawing.Point(18, 170)<br />
Me.txtDisplay.Multiline = True<br />
Me.txtDisplay.Name = "txtDisplay"<br />
Me.txtDisplay.ReadOnly = True<br />
Me.txtDisplay.ScrollBars = System.Windows.Forms.ScrollBars.Vertical<br />
Me.txtDisplay.Size = New System.Drawing.Size(254, 104)<br />
Me.txtDisplay.TabIndex = 16<br />
"<br />
"lblBalance<br />
"<br />
Me.lblBalance.AutoSize = True<br />
Me.lblBalance.Location = New System.Drawing.Point(17, 143)<br />
Me.lblBalance.Name = "lblBalance"<br />
Me.lblBalance.Size = New System.Drawing.Size(122, 13)<br />
Me.lblBalance.TabIndex = 15<br />
Me.lblBalance.Text = "Yearly account balance:"<br />
"<br />
"updYear<br />
"<br />
Me.updYear.Location = New System.Drawing.Point(85, 95)<br />
Me.updYear.Maximum = New Decimal(New Integer() {10, 0, 0, 0})<br />
Me.updYear.Minimum = New Decimal(New Integer() {1, 0, 0, 0})<br />
Me.updYear.Name = "updYear"<br />
Me.updYear.ReadOnly = True<br />
Me.updYear.Size = New System.Drawing.Size(100, 20)<br />
Me.updYear.TabIndex = 14<br />
Me.updYear.TextAlign = System.Windows.Forms.HorizontalAlignment.Right<br />
Me.updYear.Value = New Decimal(New Integer() {1, 0, 0, 0})<br />
"<br />
"lblYears<br />
"<br />
Me.lblYears.AutoSize = True<br />
Me.lblYears.Location = New System.Drawing.Point(17, 102)<br />
Me.lblYears.Name = "lblYears"<br />
Me.lblYears.Size = New System.Drawing.Size(37, 13)<br />
Me.lblYears.TabIndex = 13<br />
Me.lblYears.Text = "Years:"<br />
"<br />
"txtInterest<br />
"<br />
Me.txtInterest.Location = New System.Drawing.Point(85, 58)<br />
Me.txtInterest.Name = "txtInterest"<br />
Me.txtInterest.Size = New System.Drawing.Size(100, 20)<br />
Me.txtInterest.TabIndex = 12<br />
Me.txtInterest.TextAlign = System.Windows.Forms.HorizontalAlignment.Right<br />
"<br />
"lblInterest<br />
"<br />
Me.lblInterest.AutoSize = True<br />
Me.lblInterest.Location = New System.Drawing.Point(17, 61)<br />
Me.lblInterest.Name = "lblInterest"<br />
Me.lblInterest.Size = New System.Drawing.Size(71, 13)<br />
Me.lblInterest.TabIndex = 11<br />
Me.lblInterest.Text = "Interest Rate:"<br />
"<br />
"txtPrincipal<br />
"<br />
Me.txtPrincipal.Location = New System.Drawing.Point(85, 17)<br />
Me.txtPrincipal.Name = "txtPrincipal"<br />
Me.txtPrincipal.Size = New System.Drawing.Size(100, 20)<br />
Me.txtPrincipal.TabIndex = 10<br />
Me.txtPrincipal.TextAlign = System.Windows.Forms.HorizontalAlignment.Right<br />
"<br />
"lblPrincipal<br />
"<br />
Me.lblPrincipal.AutoSize = True<br />
Me.lblPrincipal.Location = New System.Drawing.Point(17, 20)<br />
Me.lblPrincipal.Name = "lblPrincipal"<br />
Me.lblPrincipal.Size = New System.Drawing.Size(50, 13)<br />
Me.lblPrincipal.TabIndex = 9<br />
Me.lblPrincipal.Text = "Principal:"<br />
"<br />
"FrmInterestCalculator<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(289, 288)<br />
Me.Controls.Add(Me.btnCalculate)<br />
Me.Controls.Add(Me.txtDisplay)<br />
Me.Controls.Add(Me.lblBalance)<br />
Me.Controls.Add(Me.updYear)<br />
Me.Controls.Add(Me.lblYears)<br />
Me.Controls.Add(Me.txtInterest)<br />
Me.Controls.Add(Me.lblInterest)<br />
Me.Controls.Add(Me.txtPrincipal)<br />
Me.Controls.Add(Me.lblPrincipal)<br />
Me.Name = "FrmInterestCalculator"<br />
Me.Text = "Interest Calculator"<br />
CType(Me.updYear, System.ruponentModel.ISupportInitialize).EndInit()<br />
Me.ResumeLayout(False)<br />
Me.PerformLayout()<br />
End Sub<br />
Friend WithEvents btnCalculate As System.Windows.Forms.Button<br />
Friend WithEvents txtDisplay As System.Windows.Forms.TextBox<br />
Friend WithEvents lblBalance As System.Windows.Forms.Label<br />
Friend WithEvents updYear As System.Windows.Forms.NumericUpDown<br />
Friend WithEvents lblYears As System.Windows.Forms.Label<br />
Friend WithEvents txtInterest As System.Windows.Forms.TextBox<br />
Friend WithEvents lblInterest As System.Windows.Forms.Label<br />
Friend WithEvents txtPrincipal As System.Windows.Forms.TextBox<br />
Friend WithEvents lblPrincipal As System.Windows.Forms.Label<br />
End Class</source><br />
<br />
==ScrollBars - NumericUpDowns==<br />
<br />
<br />
<br />
<source lang="vbnet">imports System<br />
imports System.Drawing<br />
imports System.Windows.Forms<br />
public class NumericUpDowns : inherits Form<br />
dim hbar as HScrollBar<br />
dim vbar as VScrollBar<br />
dim nupdwn as NumericUpDown<br />
public sub New()<br />
Size = new Size(480,580)<br />
hbar = new HScrollBar()<br />
hbar.Parent = me<br />
hbar.Location = new Point(0, 25)<br />
hbar.Size = new Size(300, 25)<br />
hbar.Minimum = 25<br />
hbar.Maximum = 400<br />
hbar.SmallChange = 10<br />
hbar.LargeChange = 100<br />
hbar.Value = 10<br />
AddHandler hbar.ValueChanged, AddressOf hbar_OnValueChanged<br />
vbar = new VScrollBar()<br />
vbar.Parent = me<br />
vbar.Location = new Point(25, 25)<br />
vbar.Size = new Size(25, 300)<br />
vbar.Minimum = 25<br />
vbar.Maximum = 400<br />
vbar.SmallChange = 10<br />
vbar.LargeChange = 100<br />
vbar.Value = 10<br />
AddHandler vbar.ValueChanged, AddressOf vbar_OnValueChanged<br />
nupdwn = new NumericUpDown()<br />
nupdwn.Parent = me<br />
nupdwn.Location = new Point(100,100)<br />
nupdwn.Size = new Size(60,20)<br />
nupdwn.Value = 1<br />
nupdwn.Minimum = -10<br />
nupdwn.Maximum = 10<br />
nupdwn.Increment = .25d " decimal <br />
nupdwn.DecimalPlaces = 2<br />
nupdwn.ReadOnly = true<br />
nupdwn.TextAlign = HorizontalAlignment.Right<br />
AddHandler nupdwn.ValueChanged, AddressOf nupdwn_OnValueChanged<br />
end sub<br />
private sub hbar_OnValueChanged(ByVal sender as object,ByVal e as EventArgs)<br />
Console.WriteLine(hbar.Value)<br />
Console.WriteLine(hbar.LargeChange)<br />
end sub<br />
private sub vbar_OnValueChanged(ByVal sender as object,ByVal e as EventArgs)<br />
Console.WriteLine(vbar.Value)<br />
Console.WriteLine(vbar.LargeChange)<br />
end sub<br />
private sub nupdwn_OnValueChanged(ByVal sender as object,ByVal e as EventArgs)<br />
Console.WriteLine(nupdwn.Value)<br />
end sub<br />
public shared sub Main() <br />
Application.Run(new NumericUpDowns())<br />
end sub<br />
end class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/Password_Field&diff=3879
VB.Net Tutorial/GUI/Password Field
2010-05-26T12:57:17Z
<p>Admin: 1 версия</p>
<hr />
<div>==Get input from a password field==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class PasswordFieldMatch<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
Public Sub New()<br />
MyBase.New()<br />
InitializeComponent()<br />
End Sub<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
Private components As System.ruponentModel.IContainer<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents Button2 As System.Windows.Forms.Button<br />
Friend WithEvents Button3 As System.Windows.Forms.Button<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.Label1 = New System.Windows.Forms.Label<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.Button2 = New System.Windows.Forms.Button<br />
Me.Button3 = New System.Windows.Forms.Button<br />
Me.SuspendLayout()<br />
"<br />
"Label1<br />
"<br />
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.Label1.Location = New System.Drawing.Point(16, 16)<br />
Me.Label1.Name = "Label1"<br />
Me.Label1.Size = New System.Drawing.Size(152, 32)<br />
Me.Label1.TabIndex = 0<br />
Me.Label1.Text = "Password"<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(40, 64)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.PasswordChar = Microsoft.VisualBasic.ChrW(42)<br />
Me.TextBox1.Size = New System.Drawing.Size(160, 20)<br />
Me.TextBox1.TabIndex = 1<br />
Me.TextBox1.Text = ""<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(80, 96)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.Size = New System.Drawing.Size(80, 24)<br />
Me.Button1.TabIndex = 2<br />
Me.Button1.Text = "Input"<br />
"<br />
"Button2<br />
"<br />
Me.Button2.Location = New System.Drawing.Point(80, 136)<br />
Me.Button2.Name = "Button2"<br />
Me.Button2.Size = New System.Drawing.Size(80, 24)<br />
Me.Button2.TabIndex = 3<br />
Me.Button2.Text = "Check"<br />
"<br />
"Button3<br />
"<br />
Me.Button3.Location = New System.Drawing.Point(80, 176)<br />
Me.Button3.Name = "Button3"<br />
Me.Button3.Size = New System.Drawing.Size(80, 24)<br />
Me.Button3.TabIndex = 4<br />
Me.Button3.Text = "Exit"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(256, 222)<br />
Me.Controls.Add(Me.Button3)<br />
Me.Controls.Add(Me.Button2)<br />
Me.Controls.Add(Me.Button1)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.Controls.Add(Me.Label1)<br />
Me.ResumeLayout(False)<br />
End Sub<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
TextBox1.Text = ""<br />
TextBox1.Focus()<br />
End Sub<br />
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click<br />
Dim answer As Object<br />
Dim caption As String<br />
Dim pwd As String<br />
pwd = "Visual Basic"<br />
caption = "Password"<br />
If TextBox1.Text = pwd Then<br />
answer = MsgBox("Match", 1, caption)<br />
Else<br />
answer = MsgBox("Does not Match", 1, caption)<br />
End If<br />
End Sub<br />
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click<br />
End<br />
End Sub<br />
End Class</source><br />
<br />
==Using a textbox, label and button to display the hidden text in a password box.==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class GetTextPasswordField<br />
public Shared Sub Main<br />
Application.Run(New FrmButtonTest)<br />
End Sub<br />
End class<br />
<br />
Public Class FrmButtonTest<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
Friend WithEvents lblOutput As System.Windows.Forms.Label<br />
Friend WithEvents txtInput As System.Windows.Forms.TextBox<br />
Friend WithEvents cmdShow As System.Windows.Forms.Button<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.Container<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.cmdShow = New System.Windows.Forms.Button()<br />
Me.txtInput = New System.Windows.Forms.TextBox()<br />
Me.lblOutput = New System.Windows.Forms.Label()<br />
Me.SuspendLayout()<br />
"<br />
"cmdShow<br />
"<br />
Me.cmdShow.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.cmdShow.Location = New System.Drawing.Point(88, 88)<br />
Me.cmdShow.Name = "cmdShow"<br />
Me.cmdShow.Size = New System.Drawing.Size(96, 40)<br />
Me.cmdShow.TabIndex = 2<br />
Me.cmdShow.Text = "Show Me"<br />
"<br />
"txtInput<br />
"<br />
Me.txtInput.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.txtInput.Location = New System.Drawing.Point(16, 16)<br />
Me.txtInput.Name = "txtInput"<br />
Me.txtInput.PasswordChar = Microsoft.VisualBasic.ChrW(42)<br />
Me.txtInput.Size = New System.Drawing.Size(232, 22)<br />
Me.txtInput.TabIndex = 0<br />
Me.txtInput.Text = ""<br />
"<br />
"lblOutput<br />
"<br />
Me.lblOutput.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D<br />
Me.lblOutput.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.lblOutput.Location = New System.Drawing.Point(16, 56)<br />
Me.lblOutput.Name = "lblOutput"<br />
Me.lblOutput.Size = New System.Drawing.Size(232, 23)<br />
Me.lblOutput.TabIndex = 1<br />
"<br />
"FrmButtonTest<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(264, 141)<br />
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.cmdShow, Me.lblOutput, Me.txtInput})<br />
Me.Name = "FrmButtonTest"<br />
Me.Text = "LabelTextBoxButtonExample"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub cmdShow_Click(ByVal sender As System.Object, _<br />
ByVal e As System.EventArgs) Handles cmdShow.Click<br />
lblOutput.Text = txtInput.Text<br />
End Sub<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/TrackBar&diff=3871
VB.Net Tutorial/GUI/TrackBar
2010-05-26T12:57:16Z
<p>Admin: 1 версия</p>
<hr />
<div>==Get TrackBar value and LargeChange value==<br />
<br />
<br />
<br />
<source lang="vbnet">imports System<br />
imports System.Drawing<br />
imports System.Windows.Forms<br />
public class TrackBars : inherits Form<br />
dim htbar as TrackBar<br />
dim vtbar as TrackBar<br />
public sub New()<br />
Size = new Size(500,520)<br />
htbar = new TrackBar()<br />
htbar.Parent = me<br />
htbar.Orientation = Orientation.Horizontal<br />
htbar.Size = new Size(200, 10)<br />
htbar.Location = new Point(0, 25)<br />
htbar.TickStyle = TickStyle.BottomRight<br />
htbar.TickFrequency = 25<br />
htbar.Minimum = 25<br />
htbar.Maximum = 400<br />
htbar.SmallChange = 10<br />
htbar.LargeChange = 25<br />
htbar.BackColor = Color.Yellow<br />
htbar.Value = 100<br />
AddHandler htbar.ValueChanged, AddressOf htbar_OnValueChanged<br />
vtbar = new TrackBar()<br />
vtbar.Parent = me<br />
vtbar.Orientation = Orientation.Vertical<br />
vtbar.Size = new Size(25, 300)<br />
vtbar.Location = new Point(25, 25)<br />
vtbar.TickStyle = TickStyle.BottomRight<br />
vtbar.SetRange(25,400)<br />
vtbar.SmallChange = 10<br />
vtbar.LargeChange = 50<br />
vtbar.TickFrequency = CInt(vtbar.Maximum / 20)<br />
vtbar.BackColor = Color.Pink<br />
vtbar.Value = 200<br />
AddHandler vtbar.ValueChanged, AddressOf vtbar_OnValueChanged<br />
end sub " close for constructor<br />
private sub htbar_OnValueChanged(ByVal sender as object, _<br />
ByVal e as EventArgs)<br />
Console.WriteLine(htbar.Value)<br />
end sub<br />
private sub vtbar_OnValueChanged(ByVal sender as object, _<br />
ByVal e as EventArgs)<br />
Console.WriteLine(vtbar.Value)<br />
Console.WriteLine(vtbar.LargeChange)<br />
end sub<br />
public shared sub Main() <br />
Application.Run(new TrackBars())<br />
end sub<br />
end class</source><br />
<br />
==Link ProgressBar with a TrackBar==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class TrackBarProgressBarLink<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<br />
Public Class Form1<br />
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll<br />
ProgressBar1.Value = TrackBar1.Value<br />
Label1.Text = ProgressBar1.Value.ToString + "/100"<br />
End Sub<br />
End Class<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.ProgressBar1 = New System.Windows.Forms.ProgressBar<br />
Me.Label1 = New System.Windows.Forms.Label<br />
Me.TrackBar1 = New System.Windows.Forms.TrackBar<br />
CType(Me.TrackBar1, System.ruponentModel.ISupportInitialize).BeginInit()<br />
Me.SuspendLayout()<br />
"<br />
"ProgressBar1<br />
"<br />
Me.ProgressBar1.Location = New System.Drawing.Point(12, 50)<br />
Me.ProgressBar1.Name = "ProgressBar1"<br />
Me.ProgressBar1.Size = New System.Drawing.Size(358, 34)<br />
Me.ProgressBar1.TabIndex = 0<br />
"<br />
"Label1<br />
"<br />
Me.Label1.AutoSize = True<br />
Me.Label1.Location = New System.Drawing.Point(160, 23)<br />
Me.Label1.Name = "Label1"<br />
Me.Label1.Size = New System.Drawing.Size(35, 12)<br />
Me.Label1.TabIndex = 1<br />
Me.Label1.Text = "0/100"<br />
"<br />
"TrackBar1<br />
"<br />
Me.TrackBar1.Location = New System.Drawing.Point(12, 110)<br />
Me.TrackBar1.Maximum = 100<br />
Me.TrackBar1.Name = "TrackBar1"<br />
Me.TrackBar1.Size = New System.Drawing.Size(358, 45)<br />
Me.TrackBar1.TabIndex = 2<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(382, 166)<br />
Me.Controls.Add(Me.TrackBar1)<br />
Me.Controls.Add(Me.Label1)<br />
Me.Controls.Add(Me.ProgressBar1)<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
CType(Me.TrackBar1, System.ruponentModel.ISupportInitialize).EndInit()<br />
Me.ResumeLayout(False)<br />
Me.PerformLayout()<br />
End Sub<br />
Friend WithEvents ProgressBar1 As System.Windows.Forms.ProgressBar<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
Friend WithEvents TrackBar1 As System.Windows.Forms.TrackBar<br />
End Class</source><br />
<br />
==Use TrackBar to control the Scale==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class TrackBarScale<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DisplayScale.Scroll<br />
DrawingArea.Invalidate()<br />
End Sub<br />
Private Sub DrawingArea_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles DrawingArea.Paint<br />
Dim titleFont As Font<br />
Dim mainFont As Font<br />
Dim titleArea As Rectangle<br />
Dim textArea As Rectangle<br />
Dim titleFormat As StringFormat<br />
Const MainTitle As String = "www.vbex.ru"<br />
titleFont = New Font("Arial", 16, FontStyle.Bold)<br />
mainFont = New Font("Arial", 12, FontStyle.Regular)<br />
titleArea = New Rectangle(0, 0, DrawingArea.ClientRectangle.Width, titleFont.Height)<br />
textArea = New Rectangle(0, titleFont.Height * 1.4, DrawingArea.ClientRectangle.Width, DrawingArea.ClientRectangle.Height - (titleFont.Height * 1.4))<br />
e.Graphics.ScaleTransform(DisplayScale.Value, DisplayScale.Value)<br />
titleFormat = New StringFormat()<br />
titleFormat.Alignment = StringAlignment.Center<br />
e.Graphics.DrawString(MainTitle, titleFont, Brushes.Black, titleArea, titleFormat)<br />
titleFormat.Dispose()<br />
mainFont.Dispose()<br />
titleFont.Dispose()<br />
End Sub<br />
End Class<br />
<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.LabelText = New System.Windows.Forms.Label<br />
Me.DisplayText = New System.Windows.Forms.TextBox<br />
Me.LabelScale = New System.Windows.Forms.Label<br />
Me.DisplayScale = New System.Windows.Forms.TrackBar<br />
Me.ActDisplay = New System.Windows.Forms.Button<br />
Me.DrawingArea = New System.Windows.Forms.PictureBox<br />
CType(Me.DisplayScale, System.ruponentModel.ISupportInitialize).BeginInit()<br />
CType(Me.DrawingArea, System.ruponentModel.ISupportInitialize).BeginInit()<br />
Me.SuspendLayout()<br />
"<br />
"LabelText<br />
"<br />
Me.LabelText.AutoSize = True<br />
Me.LabelText.Location = New System.Drawing.Point(8, 8)<br />
Me.LabelText.Name = "LabelText"<br />
Me.LabelText.Size = New System.Drawing.Size(31, 13)<br />
Me.LabelText.TabIndex = 0<br />
Me.LabelText.Text = "&Text:"<br />
"<br />
"LabelScale<br />
"<br />
Me.LabelScale.AutoSize = True<br />
Me.LabelScale.Location = New System.Drawing.Point(8, 144)<br />
Me.LabelScale.Name = "LabelScale"<br />
Me.LabelScale.Size = New System.Drawing.Size(37, 13)<br />
Me.LabelScale.TabIndex = 2<br />
Me.LabelScale.Text = "&Scale:"<br />
"<br />
"DisplayScale<br />
"<br />
Me.DisplayScale.Location = New System.Drawing.Point(48, 136)<br />
Me.DisplayScale.Maximum = 5<br />
Me.DisplayScale.Minimum = 1<br />
Me.DisplayScale.Name = "DisplayScale"<br />
Me.DisplayScale.Size = New System.Drawing.Size(104, 45)<br />
Me.DisplayScale.TabIndex = 3<br />
Me.DisplayScale.Value = 1<br />
"<br />
"DrawingArea<br />
"<br />
Me.DrawingArea.BackColor = System.Drawing.Color.White<br />
Me.DrawingArea.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D<br />
Me.DrawingArea.Location = New System.Drawing.Point(192, 8)<br />
Me.DrawingArea.Name = "DrawingArea"<br />
Me.DrawingArea.Size = New System.Drawing.Size(328, 208)<br />
Me.DrawingArea.TabIndex = 5<br />
Me.DrawingArea.TabStop = False<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(532, 227)<br />
Me.Controls.Add(Me.DrawingArea)<br />
Me.Controls.Add(Me.DisplayScale)<br />
<br />
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle<br />
Me.MaximizeBox = False<br />
Me.Name = "Form1"<br />
Me.Text = "Displaying Scaled Content"<br />
CType(Me.DisplayScale, System.ruponentModel.ISupportInitialize).EndInit()<br />
CType(Me.DrawingArea, System.ruponentModel.ISupportInitialize).EndInit()<br />
Me.ResumeLayout(False)<br />
Me.PerformLayout()<br />
End Sub<br />
Friend WithEvents LabelText As System.Windows.Forms.Label<br />
Friend WithEvents DisplayText As System.Windows.Forms.TextBox<br />
Friend WithEvents LabelScale As System.Windows.Forms.Label<br />
Friend WithEvents DisplayScale As System.Windows.Forms.TrackBar<br />
Friend WithEvents ActDisplay As System.Windows.Forms.Button<br />
Friend WithEvents DrawingArea As System.Windows.Forms.PictureBox<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/Control_Event&diff=3873
VB.Net Tutorial/GUI/Control Event
2010-05-26T12:57:16Z
<p>Admin: 1 версия</p>
<hr />
<div>==A simple event handler==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class GenericEventHandler<br />
public Shared Sub Main<br />
Application.Run(New FrmSimple)<br />
End Sub<br />
End class<br />
<br />
Public Class FrmSimple<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
" This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
<br />
" Add any initialization after the <br />
" InitializeComponent() call<br />
End Sub " New<br />
" Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose( _<br />
ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub " Dispose<br />
Friend WithEvents lblOutput As System.Windows.Forms.Label<br />
" Required by the Windows Form Designer<br />
Private components As System.ruponentModel.Container<br />
" NOTE: The following procedure is required by <br />
" the Windows Form Designer.<br />
" It can be modified using the Windows Form Designer. <br />
" Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.lblOutput = New System.Windows.Forms.Label()<br />
Me.SuspendLayout()<br />
"<br />
"lblOutput<br />
"<br />
Me.lblOutput.Location = New System.Drawing.Point(16, 16)<br />
Me.lblOutput.Name = "lblOutput"<br />
Me.lblOutput.Size = New System.Drawing.Size(152, 80)<br />
Me.lblOutput.TabIndex = 0<br />
Me.lblOutput.Text = "Click Me!"<br />
Me.lblOutput.TextAlign = System.Drawing.ContentAlignment.MiddleCenter<br />
"<br />
"FrmSimple<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(176, 101)<br />
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblOutput})<br />
Me.Name = "FrmSimple"<br />
Me.Text = "SimpleEventExample"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub lblOutput_Click(ByVal sender As Object, _<br />
ByVal e As System.EventArgs) Handles lblOutput.Click<br />
MessageBox.Show("Label was clicked")<br />
End Sub <br />
End Class</source><br />
<br />
==Handle multiple event handlers from different controls==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class HandleMultipleEventsFromDifferentControls<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Private Sub MultipleEvents(ByVal sender As Object, _<br />
ByVal e As System.EventArgs) Handles _<br />
TextBox1.Enter, TextBox2.Enter, TextBox3.Enter, _<br />
TextBox1.TextChanged, TextBox2.TextChanged, TextBox3.TextChanged<br />
<br />
Dim activeControl As TextBox<br />
activeControl = CType(sender, TextBox)<br />
ShowInfo.Text = "TextField #" & _<br />
activeControl.Name & _<br />
", " & activeControl.Text.Length & " character(s)"<br />
End Sub<br />
End Class<br />
<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.Label1 = New System.Windows.Forms.Label<br />
Me.Label2 = New System.Windows.Forms.Label<br />
Me.TextBox2 = New System.Windows.Forms.TextBox<br />
Me.Label3 = New System.Windows.Forms.Label<br />
Me.TextBox3 = New System.Windows.Forms.TextBox<br />
Me.Label4 = New System.Windows.Forms.Label<br />
Me.ShowInfo = New System.Windows.Forms.Label<br />
Me.SuspendLayout()<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(120, 8)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(160, 20)<br />
Me.TextBox1.TabIndex = 1<br />
"<br />
"Label1<br />
"<br />
Me.Label1.AutoSize = True<br />
Me.Label1.Location = New System.Drawing.Point(8, 10)<br />
Me.Label1.Name = "Label1"<br />
Me.Label1.Size = New System.Drawing.Size(93, 13)<br />
Me.Label1.TabIndex = 0<br />
Me.Label1.Text = "Text Box Field #1:"<br />
"<br />
"Label2<br />
"<br />
Me.Label2.AutoSize = True<br />
Me.Label2.Location = New System.Drawing.Point(8, 42)<br />
Me.Label2.Name = "Label2"<br />
Me.Label2.Size = New System.Drawing.Size(93, 13)<br />
Me.Label2.TabIndex = 2<br />
Me.Label2.Text = "Text Box Field #2:"<br />
"<br />
"TextBox2<br />
"<br />
Me.TextBox2.Location = New System.Drawing.Point(120, 40)<br />
Me.TextBox2.Name = "TextBox2"<br />
Me.TextBox2.Size = New System.Drawing.Size(160, 20)<br />
Me.TextBox2.TabIndex = 3<br />
"<br />
"Label3<br />
"<br />
Me.Label3.AutoSize = True<br />
Me.Label3.Location = New System.Drawing.Point(9, 72)<br />
Me.Label3.Name = "Label3"<br />
Me.Label3.Size = New System.Drawing.Size(93, 13)<br />
Me.Label3.TabIndex = 4<br />
Me.Label3.Text = "Text Box Field #3:"<br />
"<br />
"TextBox3<br />
"<br />
Me.TextBox3.Location = New System.Drawing.Point(121, 70)<br />
Me.TextBox3.Name = "TextBox3"<br />
Me.TextBox3.Size = New System.Drawing.Size(159, 20)<br />
Me.TextBox3.TabIndex = 5<br />
"<br />
"Label4<br />
"<br />
Me.Label4.AutoSize = True<br />
Me.Label4.Location = New System.Drawing.Point(8, 104)<br />
Me.Label4.Name = "Label4"<br />
Me.Label4.Size = New System.Drawing.Size(62, 13)<br />
Me.Label4.TabIndex = 6<br />
Me.Label4.Text = "Information:"<br />
"<br />
"ShowInfo<br />
"<br />
Me.ShowInfo.AutoSize = True<br />
Me.ShowInfo.Location = New System.Drawing.Point(120, 104)<br />
Me.ShowInfo.Name = "ShowInfo"<br />
Me.ShowInfo.Size = New System.Drawing.Size(27, 13)<br />
Me.ShowInfo.TabIndex = 7<br />
Me.ShowInfo.Text = "N/A"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(320, 136)<br />
Me.Controls.Add(Me.ShowInfo)<br />
Me.Controls.Add(Me.Label4)<br />
Me.Controls.Add(Me.Label3)<br />
Me.Controls.Add(Me.TextBox3)<br />
Me.Controls.Add(Me.Label2)<br />
Me.Controls.Add(Me.TextBox2)<br />
Me.Controls.Add(Me.Label1)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle<br />
Me.MaximizeBox = False<br />
Me.Name = "Form1"<br />
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen<br />
Me.Text = "Sharing Control Logic"<br />
Me.ResumeLayout(False)<br />
Me.PerformLayout()<br />
End Sub<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
Friend WithEvents Label2 As System.Windows.Forms.Label<br />
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox<br />
Friend WithEvents Label3 As System.Windows.Forms.Label<br />
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox<br />
Friend WithEvents Label4 As System.Windows.Forms.Label<br />
Friend WithEvents ShowInfo As System.Windows.Forms.Label<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/TextBox&diff=3869
VB.Net Tutorial/GUI/TextBox
2010-05-26T12:57:15Z
<p>Admin: 1 версия</p>
<hr />
<div>==Change TextBox font by RadioButton and CheckBox==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class RadioButtonControlFont<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<br />
Public Class Form1<br />
Public mysize As Integer<br />
Public mybold As Boolean<br />
Public myItalic As Boolean<br />
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)<br />
CheckBox1.Checked = 1<br />
End Sub<br />
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged<br />
myItalic = Not myItalic<br />
TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Regular)<br />
If myItalic And mybold Then<br />
TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Italic)<br />
ElseIf myItalic Then<br />
TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Italic)<br />
ElseIf mybold Then<br />
TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Bold)<br />
End If<br />
End Sub<br />
Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter<br />
End Sub<br />
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
mybold = False<br />
myItalic = False<br />
mysize = 25<br />
End Sub<br />
Private Sub RadioButton1_CheckedChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged<br />
mysize = 36<br />
TextBox1.Font = New System.Drawing.Font("", mysize)<br />
End Sub<br />
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged<br />
mysize = 25<br />
TextBox1.Font = New System.Drawing.Font("", mysize)<br />
End Sub<br />
Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged<br />
mybold = Not mybold<br />
TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Regular)<br />
If myItalic And mybold Then<br />
TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Bold)<br />
ElseIf myItalic Then<br />
TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Italic)<br />
ElseIf mybold Then<br />
TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Bold)<br />
End If<br />
End Sub<br />
End Class<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.CheckBox1 = New System.Windows.Forms.CheckBox<br />
Me.CheckBox2 = New System.Windows.Forms.CheckBox<br />
Me.GroupBox1 = New System.Windows.Forms.GroupBox<br />
Me.RadioButton1 = New System.Windows.Forms.RadioButton<br />
Me.RadioButton2 = New System.Windows.Forms.RadioButton<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.GroupBox1.SuspendLayout()<br />
Me.SuspendLayout()<br />
"<br />
"CheckBox1<br />
"<br />
Me.CheckBox1.AutoSize = True<br />
Me.CheckBox1.Location = New System.Drawing.Point(230, 34)<br />
Me.CheckBox1.Name = "CheckBox1"<br />
Me.CheckBox1.Size = New System.Drawing.Size(48, 16)<br />
Me.CheckBox1.TabIndex = 1<br />
Me.CheckBox1.Text = "Italic"<br />
Me.CheckBox1.UseVisualStyleBackColor = True<br />
"<br />
"CheckBox2<br />
"<br />
Me.CheckBox2.AutoSize = True<br />
Me.CheckBox2.Location = New System.Drawing.Point(230, 56)<br />
Me.CheckBox2.Name = "CheckBox2"<br />
Me.CheckBox2.Size = New System.Drawing.Size(48, 16)<br />
Me.CheckBox2.TabIndex = 2<br />
Me.CheckBox2.Text = "Bold"<br />
Me.CheckBox2.UseVisualStyleBackColor = True<br />
"<br />
"GroupBox1<br />
"<br />
Me.GroupBox1.Controls.Add(Me.RadioButton2)<br />
Me.GroupBox1.Controls.Add(Me.RadioButton1)<br />
Me.GroupBox1.Location = New System.Drawing.Point(224, 85)<br />
Me.GroupBox1.Name = "GroupBox1"<br />
Me.GroupBox1.Size = New System.Drawing.Size(132, 77)<br />
Me.GroupBox1.TabIndex = 3<br />
Me.GroupBox1.TabStop = False<br />
Me.GroupBox1.Text = "Font size"<br />
"<br />
"RadioButton1<br />
"<br />
Me.RadioButton1.AutoSize = True<br />
Me.RadioButton1.Location = New System.Drawing.Point(6, 20)<br />
Me.RadioButton1.Name = "RadioButton1"<br />
Me.RadioButton1.Size = New System.Drawing.Size(59, 16)<br />
Me.RadioButton1.TabIndex = 1<br />
Me.RadioButton1.TabStop = True<br />
Me.RadioButton1.Text = "Larger font"<br />
Me.RadioButton1.UseVisualStyleBackColor = True<br />
"<br />
"RadioButton2<br />
"<br />
Me.RadioButton2.AutoSize = True<br />
Me.RadioButton2.Location = New System.Drawing.Point(6, 42)<br />
Me.RadioButton2.Name = "RadioButton2"<br />
Me.RadioButton2.Size = New System.Drawing.Size(59, 16)<br />
Me.RadioButton2.TabIndex = 2<br />
Me.RadioButton2.TabStop = True<br />
Me.RadioButton2.Text = "Smaller font"<br />
Me.RadioButton2.UseVisualStyleBackColor = True<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(12, 12)<br />
Me.TextBox1.Multiline = True<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(195, 150)<br />
Me.TextBox1.TabIndex = 4<br />
Me.TextBox1.Text = "www.vbex.ru"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(368, 174)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.Controls.Add(Me.GroupBox1)<br />
Me.Controls.Add(Me.CheckBox2)<br />
Me.Controls.Add(Me.CheckBox1)<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.GroupBox1.ResumeLayout(False)<br />
Me.GroupBox1.PerformLayout()<br />
Me.ResumeLayout(False)<br />
Me.PerformLayout()<br />
End Sub<br />
Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox<br />
Friend WithEvents CheckBox2 As System.Windows.Forms.CheckBox<br />
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox<br />
Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton<br />
Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
End Class</source><br />
<br />
==Comprehensive Demo for TextBox==<br />
<br />
<br />
<br />
<source lang="vbnet">"Programming .Net Windows Applications [ILLUSTRATED] (Paperback)<br />
"by Jesse Liberty (Author), Dan Hurwitz (Author)<br />
"# Publisher: O"Reilly Media, Inc.; 1 edition (October 28, 2003)<br />
"# Language: English<br />
"# ISBN-10: 0596003218<br />
"# ISBN-13: 978-0596003210<br />
imports System<br />
imports System.Drawing<br />
imports System.Windows.Forms<br />
imports System.Text<br />
namespace ProgrammingWinApps<br />
public class TextBoxes : inherits Form<br />
dim yDelta as integer<br />
dim yPos as integer = 20<br />
dim txtSingle as TextBox<br />
dim txtMulti as TextBox<br />
dim txtDisplay as TextBox<br />
dim btn as Button<br />
dim txtBoxes(1) as TextBox<br />
public sub New()<br />
Text = "TextBoxes"<br />
Size = new Size(450,375)<br />
dim lblSingle as new Label()<br />
lblSingle.Parent = me<br />
lblSingle.Text = "Single Line TextBox:"<br />
lblSingle.Location = new Point(10,yPos)<br />
lblSingle.Size = new Size(150,20)<br />
lblSingle.TextAlign = ContentAlignment.MiddleRight<br />
yDelta = lblSingle.Height + 10<br />
txtSingle = new TextBox()<br />
txtSingle.Parent = me<br />
txtSingle.Text = "Single Line"<br />
txtSingle.Size = new Size(200, txtSingle.PreferredHeight)<br />
txtSingle.Location = new Point(lblSingle.Left + _<br />
lblSingle.Size.Width, yPos)<br />
txtSingle.Multiline = false<br />
txtSingle.BorderStyle = BorderStyle.Fixed3D<br />
dim lblMulti as new Label()<br />
lblMulti.Parent = me<br />
lblMulti.Text = "Multi Line TextBox:"<br />
lblMulti.Location = new Point(10, yPos + yDelta)<br />
lblMulti.Size = new Size(150,20)<br />
lblMulti.TextAlign = ContentAlignment.MiddleRight<br />
txtMulti = new TextBox()<br />
txtMulti.Parent = me<br />
txtMulti.Text = "Multi Line"<br />
txtMulti.Size = new Size(200,100)<br />
txtMulti.Location = new Point(lblMulti.Left + _<br />
lblMulti.Size.Width, yPos + yDelta)<br />
txtMulti.AcceptsTab = true<br />
txtMulti.Multiline = true<br />
txtMulti.BorderStyle = BorderStyle.Fixed3D<br />
txtMulti.ScrollBars = ScrollBars.Vertical<br />
btn = new Button()<br />
btn.Parent = me<br />
btn.Text = "Show MultiLines"<br />
btn.Location = new Point(lblMulti.Left + _<br />
lblMulti.Size.Width, yPos + (5 * yDelta))<br />
AddHandler btn.Click, AddressOf btn_Click<br />
dim xSize as integer = CType((Font.Height * .75) * _<br />
btn.Text.Length, integer)<br />
dim ySize as integer = Font.Height + 10<br />
btn.Size = new Size(xSize, ySize)<br />
txtDisplay = new TextBox()<br />
txtDisplay.Parent = me<br />
txtDisplay.Text = ""<br />
txtDisplay.Size = new Size(200,100)<br />
txtDisplay.Location = new Point(lblMulti.Left + _<br />
lblMulti.Size.Width, yPos + (6 * yDelta))<br />
txtDisplay.Multiline = true<br />
txtDisplay.BorderStyle = BorderStyle.FixedSingle<br />
txtDisplay.BackColor = Color.LightGray<br />
txtDisplay.ScrollBars = ScrollBars.Vertical<br />
txtDisplay.ReadOnly = true<br />
" Fill the array of TextBoxes<br />
txtBoxes(0) = txtSingle<br />
txtBoxes(1) = txtMulti<br />
" Menus<br />
" Edit menu items<br />
dim mnuDash1 as new MenuItem("-")<br />
dim mnuDash2 as new MenuItem("-")<br />
dim mnuUndo as new MenuItem("&Undo", _<br />
new EventHandler(AddressOf mnuUndo_Click), _<br />
Shortcut.CtrlZ)<br />
dim mnuCut as new MenuItem("Cu&t", _<br />
new EventHandler(AddressOf mnuCut_Click), _<br />
Shortcut.CtrlX)<br />
dim mnuCopy as new MenuItem("&Copy", _<br />
new EventHandler(AddressOf mnuCopy_Click), _<br />
Shortcut.CtrlC)<br />
dim mnuPaste as new MenuItem("&Paste", _<br />
new EventHandler(AddressOf mnuPaste_Click), _<br />
Shortcut.CtrlV)<br />
dim mnuDelete as new MenuItem("&Delete", _<br />
new EventHandler(AddressOf mnuDelete_Click))<br />
dim mnuSelectAll as new MenuItem("Select &All", _<br />
new EventHandler(AddressOf mnuSelectAll_Click), _<br />
Shortcut.CtrlA)<br />
dim mnuSelect5 as new MenuItem("Select First &5", _<br />
new EventHandler(AddressOf mnuSelect5_Click), _<br />
Shortcut.Ctrl5)<br />
dim mnuClear as new MenuItem("Clea&r", _<br />
new EventHandler(AddressOf mnuClear_Click))<br />
dim mnuEdit as new MenuItem("&Edit", _<br />
new MenuItem() {mnuUndo, mnuDash1, _<br />
mnuCut, mnuCopy, mnuPaste, mnuDelete, mnuDash2, _<br />
mnuSelectAll, mnuSelect5, mnuClear})<br />
" View Menu items<br />
dim mnuScrollToCaret as new MenuItem("&Scroll to Caret", _<br />
new EventHandler(AddressOf mnuScrollToCaret_Click))<br />
dim mnuView as new MenuItem("&View", _<br />
new MenuItem() {mnuScrollToCaret})<br />
<br />
" Main menu<br />
Menu = new MainMenu(new MenuItem() {mnuEdit, mnuView})<br />
<br />
end sub " close for constructor<br />
public shared sub Main() <br />
Application.Run(new TextBoxes())<br />
end sub<br />
private sub mnuUndo_Click(ByVal sender As Object, _<br />
ByVal e As EventArgs)<br />
dim i as integer<br />
for i = 0 to txtBoxes.Length - 1<br />
if txtBoxes(i).Focused then<br />
dim txt as TextBox = CType(txtBoxes(i), TextBox)<br />
if txt.CanUndo = true then<br />
txt.Undo()<br />
txt.ClearUndo()<br />
end if<br />
end if<br />
next<br />
end sub<br />
private sub mnuCut_Click(ByVal sender As Object, _<br />
ByVal e As EventArgs)<br />
dim i as integer<br />
for i = 0 to txtBoxes.Length - 1<br />
if txtBoxes(i).Focused then<br />
dim txt as TextBox = CType(txtBoxes(i), TextBox)<br />
if txt.SelectedText <> "" then<br />
txt.Cut()<br />
end if<br />
end if<br />
next<br />
end sub<br />
private sub mnuCopy_Click(ByVal sender As Object, _<br />
ByVal e As EventArgs)<br />
dim i as integer<br />
for i = 0 to txtBoxes.Length - 1<br />
if txtBoxes(i).Focused then<br />
dim txt as TextBox = CType(txtBoxes(i), TextBox)<br />
if txt.SelectionLength > 0 then<br />
txt.Copy()<br />
end if<br />
end if<br />
next<br />
end sub<br />
private sub mnuPaste_Click(ByVal sender As Object, _<br />
ByVal e As EventArgs)<br />
if Clipboard.GetDataObject().GetDataPresent(DataFormats.Text) = true then<br />
dim i as integer<br />
for i = 0 to txtBoxes.Length - 1<br />
if txtBoxes(i).Focused then<br />
dim txt as TextBox = CType(txtBoxes(i), TextBox)<br />
if txt.SelectionLength > 0 then<br />
if MessageBox.Show( _<br />
"Do you want to overwrite the currently selected text?", _<br />
"Cut & Paste", MessageBoxButtons.YesNo) = _<br />
DialogResult.No then<br />
txt.SelectionStart = txt.SelectionStart + _<br />
txt.SelectionLength<br />
end if<br />
end if<br />
txt.Paste()<br />
end if<br />
next<br />
end if<br />
end sub<br />
private sub mnuDelete_Click(ByVal sender As Object, _<br />
ByVal e As EventArgs)<br />
dim i as integer<br />
for i = 0 to txtBoxes.Length - 1<br />
if txtBoxes(i).Focused then<br />
dim txt as TextBox = CType(txtBoxes(i), TextBox)<br />
if txt.SelectionLength > 0 then<br />
txt.SelectedText = ""<br />
end if<br />
end if<br />
next<br />
end sub<br />
private sub mnuClear_Click(ByVal sender As Object, _<br />
ByVal e As EventArgs)<br />
dim i as integer<br />
for i = 0 to txtBoxes.Length - 1<br />
if txtBoxes(i).Focused then<br />
dim txt as TextBox = CType(txtBoxes(i), TextBox)<br />
txt.Clear()<br />
end if<br />
next<br />
end sub<br />
private sub mnuSelect5_Click(ByVal sender As Object, _<br />
ByVal e As EventArgs)<br />
dim i as integer<br />
for i = 0 to txtBoxes.Length - 1<br />
if txtBoxes(i).Focused then<br />
dim txt as TextBox = CType(txtBoxes(i), TextBox)<br />
if txt.Text.Length >= 5 then<br />
txt.Select(0,5)<br />
else<br />
txt.Select(0,txt.Text.Length)<br />
end if<br />
end if<br />
next<br />
end sub<br />
private sub mnuSelectAll_Click(ByVal sender As Object, _<br />
ByVal e As EventArgs)<br />
dim i as integer<br />
for i = 0 to txtBoxes.Length - 1<br />
if txtBoxes(i).Focused then<br />
dim txt as TextBox = CType(txtBoxes(i), TextBox)<br />
txt.SelectAll()<br />
end if<br />
next<br />
end sub<br />
private sub mnuScrollToCaret_Click(ByVal sender As Object, _<br />
ByVal e As EventArgs)<br />
dim i as integer<br />
for i = 0 to txtBoxes.Length - 1<br />
if txtBoxes(i).Focused then<br />
dim txt as TextBox = CType(txtBoxes(i), TextBox)<br />
txt.ScrollToCaret()<br />
end if<br />
next<br />
end sub<br />
private sub btn_Click(ByVal sender as object, _<br />
ByVal e as EventArgs)<br />
" Create a string array to hold the Lines property.<br />
dim arLines(txtMulti.Lines.Length - 1) as string<br />
arLines = txtMulti.Lines<br />
" Use stringBuilder for efficiency.<br />
dim str as string = "Line" + vbTab + "String" + vbCrLf<br />
dim sb as new StringBuilder()<br />
sb.Append(str)<br />
" Iterate through the array & display each line.<br />
dim i as integer<br />
for i = 0 to arLines.Length - 1<br />
str = i.ToString() + "." + vbTab + arLines(i) + vbCrLf<br />
sb.Append(str)<br />
next<br />
txtDisplay.Text = sb.ToString()<br />
end sub<br />
end class<br />
end namespace</source><br />
<br />
==Convert input value in a TextField==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Class ConvertForm<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.SourceFahrenheit = New System.Windows.Forms.RadioButton<br />
Me.SourceCelsius = New System.Windows.Forms.RadioButton<br />
Me.SourceKelvin = New System.Windows.Forms.RadioButton<br />
Me.ValueFahrenheit = New System.Windows.Forms.TextBox<br />
Me.ValueCelsius = New System.Windows.Forms.TextBox<br />
Me.ValueKelvin = New System.Windows.Forms.TextBox<br />
Me.ConvertTemperature = New System.Windows.Forms.Button<br />
Me.SuspendLayout()<br />
"<br />
"SourceFahrenheit<br />
"<br />
Me.SourceFahrenheit.AutoSize = True<br />
Me.SourceFahrenheit.Checked = True<br />
Me.SourceFahrenheit.Location = New System.Drawing.Point(16, 24)<br />
Me.SourceFahrenheit.Name = "SourceFahrenheit"<br />
Me.SourceFahrenheit.Size = New System.Drawing.Size(75, 17)<br />
Me.SourceFahrenheit.TabIndex = 0<br />
Me.SourceFahrenheit.TabStop = True<br />
Me.SourceFahrenheit.Text = "&Fahrenheit"<br />
Me.SourceFahrenheit.UseVisualStyleBackColor = True<br />
"<br />
"SourceCelsius<br />
"<br />
Me.SourceCelsius.AutoSize = True<br />
Me.SourceCelsius.Location = New System.Drawing.Point(16, 56)<br />
Me.SourceCelsius.Name = "SourceCelsius"<br />
Me.SourceCelsius.Size = New System.Drawing.Size(58, 17)<br />
Me.SourceCelsius.TabIndex = 2<br />
Me.SourceCelsius.Text = "&Celsius"<br />
Me.SourceCelsius.UseVisualStyleBackColor = True<br />
"<br />
"SourceKelvin<br />
"<br />
Me.SourceKelvin.AutoSize = True<br />
Me.SourceKelvin.Location = New System.Drawing.Point(16, 88)<br />
Me.SourceKelvin.Name = "SourceKelvin"<br />
Me.SourceKelvin.Size = New System.Drawing.Size(53, 17)<br />
Me.SourceKelvin.TabIndex = 4<br />
Me.SourceKelvin.Text = "&kelvin"<br />
Me.SourceKelvin.UseVisualStyleBackColor = True<br />
"<br />
"ValueFahrenheit<br />
"<br />
Me.ValueFahrenheit.Location = New System.Drawing.Point(120, 24)<br />
Me.ValueFahrenheit.Name = "ValueFahrenheit"<br />
Me.ValueFahrenheit.Size = New System.Drawing.Size(100, 20)<br />
Me.ValueFahrenheit.TabIndex = 1<br />
"<br />
"ValueCelsius<br />
"<br />
Me.ValueCelsius.Location = New System.Drawing.Point(120, 56)<br />
Me.ValueCelsius.Name = "ValueCelsius"<br />
Me.ValueCelsius.Size = New System.Drawing.Size(100, 20)<br />
Me.ValueCelsius.TabIndex = 3<br />
"<br />
"ValueKelvin<br />
"<br />
Me.ValueKelvin.Location = New System.Drawing.Point(120, 88)<br />
Me.ValueKelvin.Name = "ValueKelvin"<br />
Me.ValueKelvin.Size = New System.Drawing.Size(100, 20)<br />
Me.ValueKelvin.TabIndex = 5<br />
"<br />
"ConvertTemperature<br />
"<br />
Me.ConvertTemperature.Location = New System.Drawing.Point(144, 128)<br />
Me.ConvertTemperature.Name = "ConvertTemperature"<br />
Me.ConvertTemperature.Size = New System.Drawing.Size(75, 23)<br />
Me.ConvertTemperature.TabIndex = 6<br />
Me.ConvertTemperature.Text = "Convert"<br />
Me.ConvertTemperature.UseVisualStyleBackColor = True<br />
"<br />
"ConvertForm<br />
"<br />
Me.AcceptButton = Me.ConvertTemperature<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(245, 169)<br />
Me.Controls.Add(Me.ConvertTemperature)<br />
Me.Controls.Add(Me.ValueKelvin)<br />
Me.Controls.Add(Me.ValueCelsius)<br />
Me.Controls.Add(Me.ValueFahrenheit)<br />
Me.Controls.Add(Me.SourceKelvin)<br />
Me.Controls.Add(Me.SourceCelsius)<br />
Me.Controls.Add(Me.SourceFahrenheit)<br />
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle<br />
Me.MaximizeBox = False<br />
Me.MinimizeBox = False<br />
Me.Name = "ConvertForm"<br />
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen<br />
Me.Text = "Convert Temperatures"<br />
Me.ResumeLayout(False)<br />
Me.PerformLayout()<br />
End Sub<br />
Friend WithEvents SourceFahrenheit As System.Windows.Forms.RadioButton<br />
Friend WithEvents SourceCelsius As System.Windows.Forms.RadioButton<br />
Friend WithEvents SourceKelvin As System.Windows.Forms.RadioButton<br />
Friend WithEvents ValueFahrenheit As System.Windows.Forms.TextBox<br />
Friend WithEvents ValueCelsius As System.Windows.Forms.TextBox<br />
Friend WithEvents ValueKelvin As System.Windows.Forms.TextBox<br />
Friend WithEvents ConvertTemperature As System.Windows.Forms.Button<br />
End Class<br />
Public Class ConvertForm<br />
Private Sub ConvertTemperature_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConvertTemperature.Click<br />
On Error Resume Next<br />
If (SourceFahrenheit.Checked = True) Then<br />
If (IsNumeric(ValueFahrenheit.Text) = True) Then<br />
ValueCelsius.Text = _<br />
(Val(ValueFahrenheit.Text) - 32) / 1.8<br />
ValueKelvin.Text = _<br />
((Val(ValueFahrenheit.Text) - 32) / 1.8) + 273.15<br />
Else<br />
ValueCelsius.Text = "Error"<br />
ValueKelvin.Text = "Error"<br />
End If<br />
ElseIf (SourceCelsius.Checked = True) Then<br />
If (IsNumeric(ValueCelsius.Text) = True) Then<br />
ValueFahrenheit.Text = _<br />
(Val(ValueCelsius.Text) * 1.8) + 32<br />
ValueKelvin.Text = Val(ValueCelsius.Text) + 273.15<br />
Else<br />
ValueFahrenheit.Text = "Error"<br />
ValueKelvin.Text = "Error"<br />
End If<br />
Else<br />
If (IsNumeric(ValueKelvin.Text) = True) Then<br />
ValueFahrenheit.Text = _<br />
((Val(ValueKelvin.Text) - 273.15) * 1.8) + 32<br />
ValueCelsius.Text = Val(ValueKelvin.Text) - 273.15<br />
Else<br />
ValueFahrenheit.Text = "Error"<br />
ValueCelsius.Text = "Error"<br />
End If<br />
End If<br />
End Sub<br />
End Class<br />
<br />
public class FahrenheitCelsiusConverter<br />
Public Shared Sub Main()<br />
Application.Run(New ConvertForm)<br />
End Sub<br />
End Class</source><br />
<br />
==Copy selection text from a TextBox and paste to another==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class TextBoxCopyPaste<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.Label1 = New System.Windows.Forms.Label<br />
Me.TextBox2 = New System.Windows.Forms.TextBox<br />
Me.SuspendLayout()<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(128, 72)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(112, 20)<br />
Me.TextBox1.TabIndex = 0<br />
Me.TextBox1.Text = ""<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(128, 120)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.Size = New System.Drawing.Size(112, 23)<br />
Me.Button1.TabIndex = 1<br />
Me.Button1.Text = "Copy Selected Text"<br />
"<br />
"Label1<br />
"<br />
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 24.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.Label1.Location = New System.Drawing.Point(0, 0)<br />
Me.Label1.Name = "Label1"<br />
Me.Label1.Size = New System.Drawing.Size(344, 48)<br />
Me.Label1.TabIndex = 2<br />
Me.Label1.Text = "Copying Selected Text"<br />
"<br />
"TextBox2<br />
"<br />
Me.TextBox2.Location = New System.Drawing.Point(128, 168)<br />
Me.TextBox2.Name = "TextBox2"<br />
Me.TextBox2.Size = New System.Drawing.Size(112, 20)<br />
Me.TextBox2.TabIndex = 3<br />
Me.TextBox2.Text = ""<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(360, 253)<br />
Me.Controls.Add(Me.TextBox2)<br />
Me.Controls.Add(Me.Label1)<br />
Me.Controls.Add(Me.Button1)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
TextBox1.Copy()<br />
TextBox2.Paste()<br />
End Sub<br />
End Class</source><br />
<br />
==Create PasswordField by setting the TextBox.PasswordChar==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class PasswordFieldByTextBox<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.TextBox2 = New System.Windows.Forms.TextBox<br />
Me.Label1 = New System.Windows.Forms.Label<br />
Me.SuspendLayout()<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(96, 56)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.PasswordChar = Microsoft.VisualBasic.ChrW(42)<br />
Me.TextBox1.TabIndex = 0<br />
Me.TextBox1.Text = ""<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(104, 104)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.TabIndex = 1<br />
Me.Button1.Text = "Read Text"<br />
"<br />
"TextBox2<br />
"<br />
Me.TextBox2.Location = New System.Drawing.Point(96, 160)<br />
Me.TextBox2.Name = "TextBox2"<br />
Me.TextBox2.TabIndex = 2<br />
Me.TextBox2.Text = ""<br />
"<br />
"Label1<br />
"<br />
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 24.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.Label1.Location = New System.Drawing.Point(0, 0)<br />
Me.Label1.Name = "Label1"<br />
Me.Label1.Size = New System.Drawing.Size(184, 40)<br />
Me.Label1.TabIndex = 3<br />
Me.Label1.Text = "Passwords"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(292, 273)<br />
Me.Controls.Add(Me.Label1)<br />
Me.Controls.Add(Me.TextBox2)<br />
Me.Controls.Add(Me.Button1)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
TextBox2.Text = TextBox1.Text<br />
End Sub<br />
End Class</source><br />
<br />
==Disable TextBox Context Menu==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class DisableTextBoxContextMenu<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load<br />
Dim text_box As New NoCtxMnuTextBox<br />
text_box.Location = New Point(TextBox1.Left, TextBox1.Top + TextBox1.Height + 4)<br />
text_box.Size = TextBox1.Size<br />
Me.Controls.Add(text_box)<br />
End Sub<br />
End Class<br />
Public Class NoCtxMnuTextBox<br />
Inherits System.Windows.Forms.TextBox<br />
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)<br />
Const WM_CONTEXTMENU As Integer = &H7B<br />
If m.Msg <> WM_CONTEXTMENU Then<br />
MyBase.WndProc(m)<br />
End If<br />
End Sub<br />
End Class<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.SuspendLayout()<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(16, 16)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(120, 20)<br />
Me.TextBox1.TabIndex = 0<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(156, 102)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.ResumeLayout(False)<br />
Me.PerformLayout()<br />
End Sub<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
End Class</source><br />
<br />
==Display text file in a TextBox==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.IO<br />
Imports System.Windows.Forms<br />
public class TextFileDisplayTextBox<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.Button1 = New System.Windows.Forms.Button()<br />
Me.TextBox1 = New System.Windows.Forms.TextBox()<br />
Me.SuspendLayout()<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(104, 24)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.TabIndex = 0<br />
Me.Button1.Text = "Select a File"<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(20, 80)<br />
Me.TextBox1.Multiline = True<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(250, 150)<br />
Me.TextBox1.TabIndex = 1<br />
Me.TextBox1.Text = ""<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(292, 273)<br />
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1, Me.TextBox1})<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
Dim FileDB As New OpenFileDialog()<br />
FileDB.Filter = "All files | *.* | Word files | *.doc | Text files | *.txt"<br />
FileDB.FilterIndex = 3<br />
FileDB.InitialDirectory = "C:\Temp"<br />
If (FileDB.ShowDialog() = DialogResult.OK) Then<br />
Dim FS As FileStream<br />
Try<br />
FS = FileDB.OpenFile()<br />
Catch<br />
MsgBox("Error opening " & FileDB.FileName)<br />
End Try<br />
Dim TextData(1025) As Byte<br />
Dim BytesRead As Integer<br />
Dim I As Integer<br />
Dim NewText As String<br />
Do<br />
Try<br />
BytesRead = FS.Read(TextData, 1, 1024)<br />
NewText = ""<br />
For I = 1 To BytesRead<br />
NewText = NewText & Chr(TextData(I))<br />
Next<br />
TextBox1.AppendText(NewText)<br />
Catch<br />
MsgBox("Error reading file")<br />
End Try<br />
Loop While (BytesRead <> 0)<br />
FS.Close()<br />
Else<br />
MsgBox("User selected Cancel")<br />
End If<br />
End Sub<br />
End Class</source><br />
<br />
==Get input from TextBox and Set to Label==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class GetTextInTextBoxAndSetToLabel<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
Public Sub New()<br />
MyBase.New()<br />
InitializeComponent()<br />
End Sub<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
Private components As System.ruponentModel.IContainer<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.Label1 = New System.Windows.Forms.Label<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.SuspendLayout()<br />
"<br />
"Label1<br />
"<br />
Me.Label1.Location = New System.Drawing.Point(48, 16)<br />
Me.Label1.Name = "Label1"<br />
Me.Label1.Size = New System.Drawing.Size(160, 32)<br />
Me.Label1.TabIndex = 0<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(64, 64)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(120, 20)<br />
Me.TextBox1.TabIndex = 1<br />
Me.TextBox1.Text = ""<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(88, 104)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.Size = New System.Drawing.Size(72, 24)<br />
Me.Button1.TabIndex = 2<br />
Me.Button1.Text = "Display"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(256, 166)<br />
Me.Controls.Add(Me.Button1)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.Controls.Add(Me.Label1)<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
Label1.Text = "Hello," + TextBox1.Text + ""<br />
End Sub<br />
End Class</source><br />
<br />
==Get selected text in TextBox==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
Imports System.Drawing.Text<br />
Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
public class TextBoxSelectionLength<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
If TextBox1.SelectionLength = 0 Then<br />
MessageBox.Show(TextBox1.Text)<br />
Else<br />
MessageBox.Show(TextBox1.SelectedText)<br />
End If<br />
End Sub<br />
End Class<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.SuspendLayout()<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(12, 12)<br />
Me.TextBox1.Multiline = True<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(410, 137)<br />
Me.TextBox1.TabIndex = 0<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(150, 173)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.Size = New System.Drawing.Size(131, 23)<br />
Me.Button1.TabIndex = 1<br />
Me.Button1.Text = "Display selected text"<br />
Me.Button1.UseVisualStyleBackColor = True<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(434, 208)<br />
Me.Controls.Add(Me.Button1)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.ResumeLayout(False)<br />
Me.PerformLayout()<br />
End Sub<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
End Class</source><br />
<br />
==Inherit TextBox to create custom control based on TextBox==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System<br />
Imports System.Collections<br />
Imports System.IO<br />
Imports System.Windows.Forms<br />
Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Public Class FileTextBox<br />
Inherits TextBox<br />
#Region " Component Designer generated code "<br />
Public Sub New(ByVal Container As System.ruponentModel.IContainer)<br />
MyClass.New()<br />
"Required for Windows.Forms Class Composition Designer support<br />
Container.Add(Me)<br />
End Sub<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Component Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Component overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Component Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Component Designer<br />
"It can be modified using the Component Designer.<br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
components = New System.ruponentModel.Container()<br />
End Sub<br />
#End Region<br />
<br />
Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)<br />
If Not File.Exists(Me.Text) Then<br />
Me.ForeColor = Color.Red<br />
Else<br />
Me.ForeColor = Color.Black<br />
End If<br />
MyBase.OnTextChanged(e)<br />
End Sub<br />
End Class</source><br />
<br />
==Multiline Text Boxes==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class TextBoxMultiline<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.Label1 = New System.Windows.Forms.Label<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.SuspendLayout()<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(5, 5)<br />
Me.TextBox1.Multiline = True<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both<br />
Me.TextBox1.Size = New System.Drawing.Size(200, 150)<br />
Me.TextBox1.TabIndex = 2<br />
Me.TextBox1.Text = ""<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(288, 189)<br />
Me.Controls.Add(Me.TextBox1)<br />
Me.Controls.Add(Me.Label1)<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
End Class</source><br />
<br />
==Numeric TextBox==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class NumericTextBoxDemo<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents NumTextBox1 As NumTextBox<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.Button1 = New System.Windows.Forms.Button()<br />
Me.NumTextBox1 = New NumTextBox()<br />
Me.SuspendLayout()<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(144, 120)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.TabIndex = 1<br />
Me.Button1.Text = "Do It!"<br />
"<br />
"NumTextBox1<br />
"<br />
Me.NumTextBox1.Location = New System.Drawing.Point(32, 56)<br />
Me.NumTextBox1.Name = "NumTextBox1"<br />
Me.NumTextBox1.TabIndex = 3<br />
Me.NumTextBox1.Text = "NumTextBox1"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(292, 266)<br />
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.NumTextBox1, Me.Button1})<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
<br />
End Class<br />
<br />
Public Class NumTextBox<br />
Inherits System.Windows.Forms.TextBox<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"UserControl1 overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
"<br />
"NumTextBox<br />
"<br />
End Sub<br />
#End Region<br />
<br />
Protected Overrides Sub OnLeave(ByVal e As System.EventArgs)<br />
If Not IsNumeric(Me.Text) Then<br />
MessageBox.Show("You must enter a numeric value!", _<br />
"Please try again....", MessageBoxButtons.OK, _<br />
MessageBoxIcon.Exclamation)<br />
Me.Focus()<br />
End If<br />
MyBase.OnLeave(e)<br />
End Sub<br />
End Class</source><br />
<br />
==Save text in TextBox to a file==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.IO<br />
Imports System.Windows.Forms<br />
public class SaveTextBoxToFile<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.Button1 = New System.Windows.Forms.Button()<br />
Me.TextBox1 = New System.Windows.Forms.TextBox()<br />
Me.SuspendLayout()<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(104, 24)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.TabIndex = 0<br />
Me.Button1.Text = "Save to File"<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(20, 80)<br />
Me.TextBox1.Multiline = True<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(250, 150)<br />
Me.TextBox1.TabIndex = 1<br />
Me.TextBox1.Text = ""<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(292, 273)<br />
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1, Me.TextBox1})<br />
Me.Name = "Form1"<br />
Me.Text = "SaveTextToFile"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
Dim FileDB As New SaveFileDialog()<br />
FileDB.Filter = "All files | *.* | Word files | *.doc | Text files | *.txt"<br />
FileDB.FilterIndex = 3<br />
FileDB.InitialDirectory = "C:\Temp"<br />
FileDB.AddExtension = True<br />
FileDB.DefaultExt = "txt"<br />
If (FileDB.ShowDialog() = DialogResult.OK) Then<br />
Dim FS As FileStream<br />
Try<br />
FS = New FileStream(FileDB.FileName, FileMode.Create)<br />
Dim I As Integer<br />
For I = 0 To TextBox1.Text.Length - 1<br />
FS.WriteByte(Asc(TextBox1.Text.Chars(I)))<br />
Next<br />
Catch<br />
Console.WriteLine("Error writing file")<br />
End Try<br />
FS.Close()<br />
MsgBox("Text saved to " & FileDB.FileName)<br />
Else<br />
MsgBox("User selected Cancel")<br />
End If<br />
End Sub<br />
End Class</source><br />
<br />
==TextBox Text Changed Event==<br />
<br />
<br />
<br />
<source lang="vbnet">imports System<br />
imports System.Drawing<br />
imports System.Windows.Forms<br />
public class TextBoxTextChanged : inherits Form<br />
dim txt as TextBox<br />
dim btn as Button<br />
dim strOriginal as string<br />
public sub New()<br />
Text = "TextBox Modified and TextChanged"<br />
Size = new Size(300, 375)<br />
txt = new TextBox()<br />
txt.Parent = me<br />
txt.Text = "Enter text here."<br />
txt.Size = new Size(280, 275)<br />
txt.Location = new Point(10,10)<br />
AddHandler txt.TextChanged, AddressOf txt_TextChanged<br />
txt.Multiline = true<br />
txt.BorderStyle = BorderStyle.Fixed3D<br />
txt.ScrollBars = ScrollBars.Vertical<br />
txt.Anchor = AnchorStyles.Left or AnchorStyles.Right or AnchorStyles.Top or AnchorStyles.Bottom<br />
strOriginal = txt.Text<br />
btn = new Button()<br />
btn.Parent = me<br />
btn.Text = "Check "<br />
btn.Location = new Point(20,320)<br />
AddHandler btn.Click, AddressOf btn_Click<br />
btn.Anchor = AnchorStyles.Bottom<br />
end sub<br />
public shared sub Main() <br />
Application.Run(new TextBoxTextChanged())<br />
end sub<br />
private sub txt_TextChanged(ByVal sender as object,ByVal e as EventArgs)<br />
Console.WriteLine("txt_TextChanged")<br />
if strOriginal = txt.Text then<br />
txt.Modified = false<br />
else<br />
txt.Modified = true<br />
end if<br />
end sub<br />
private sub btn_Click(ByVal sender as object,ByVal e as EventArgs)<br />
if txt.Modified then<br />
Console.WriteLine("modified.")<br />
strOriginal = txt.Text<br />
txt.Modified = false<br />
else<br />
Console.WriteLine("not been modified." )<br />
end if<br />
end sub<br />
end class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/StatusStrip&diff=3867
VB.Net Tutorial/GUI/StatusStrip
2010-05-26T12:57:14Z
<p>Admin: 1 версия</p>
<hr />
<div>==StatusStrip Demo==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class StatusStripDemo<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<br />
Public Class Form1<br />
Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem1.Click<br />
ToolStripProgressBar1.Value = 50<br />
ToolStripStatusLabel1.Text = ToolStripProgressBar1.Value<br />
End Sub<br />
Private Sub ToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem2.Click<br />
ToolStripProgressBar1.Value = 0<br />
ToolStripStatusLabel1.Text = ToolStripProgressBar1.Value<br />
End Sub<br />
End Class<br />
<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.StatusStrip1 = New System.Windows.Forms.StatusStrip<br />
Me.ToolStripStatusLabel1 = New System.Windows.Forms.ToolStripStatusLabel<br />
Me.ToolStripProgressBar1 = New System.Windows.Forms.ToolStripProgressBar<br />
Me.ToolStripDropDownButton1 = New System.Windows.Forms.ToolStripDropDownButton<br />
Me.ToolStripSplitButton1 = New System.Windows.Forms.ToolStripSplitButton<br />
Me.ToolStripMenuItem1 = New System.Windows.Forms.ToolStripMenuItem<br />
Me.ToolStripMenuItem2 = New System.Windows.Forms.ToolStripMenuItem<br />
Me.StatusStrip1.SuspendLayout()<br />
Me.SuspendLayout()<br />
"<br />
"StatusStrip1<br />
"<br />
Me.StatusStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ToolStripStatusLabel1, Me.ToolStripProgressBar1, Me.ToolStripDropDownButton1, Me.ToolStripSplitButton1})<br />
Me.StatusStrip1.Location = New System.Drawing.Point(0, 168)<br />
Me.StatusStrip1.Name = "StatusStrip1"<br />
Me.StatusStrip1.Size = New System.Drawing.Size(481, 22)<br />
Me.StatusStrip1.TabIndex = 0<br />
Me.StatusStrip1.Text = "StatusStrip1"<br />
"<br />
"ToolStripStatusLabel1<br />
"<br />
Me.ToolStripStatusLabel1.Name = "ToolStripStatusLabel1"<br />
Me.ToolStripStatusLabel1.Size = New System.Drawing.Size(131, 17)<br />
Me.ToolStripStatusLabel1.Text = "ToolStripStatusLabel1"<br />
"<br />
"ToolStripProgressBar1<br />
"<br />
Me.ToolStripProgressBar1.Name = "ToolStripProgressBar1"<br />
Me.ToolStripProgressBar1.Size = New System.Drawing.Size(100, 16)<br />
"<br />
"ToolStripDropDownButton1<br />
"<br />
Me.ToolStripDropDownButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image<br />
Me.ToolStripDropDownButton1.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ToolStripMenuItem1})<br />
Me.ToolStripDropDownButton1.ImageTransparentColor = System.Drawing.Color.Magenta<br />
Me.ToolStripDropDownButton1.Name = "ToolStripDropDownButton1"<br />
Me.ToolStripDropDownButton1.Size = New System.Drawing.Size(29, 20)<br />
Me.ToolStripDropDownButton1.Text = "ToolStripDropDownButton1"<br />
"<br />
"ToolStripSplitButton1<br />
"<br />
Me.ToolStripSplitButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image<br />
Me.ToolStripSplitButton1.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ToolStripMenuItem2})<br />
Me.ToolStripSplitButton1.ImageTransparentColor = System.Drawing.Color.Magenta<br />
Me.ToolStripSplitButton1.Name = "ToolStripSplitButton1"<br />
Me.ToolStripSplitButton1.Size = New System.Drawing.Size(32, 20)<br />
Me.ToolStripSplitButton1.Text = "ToolStripSplitButton1"<br />
"<br />
"ToolStripMenuItem1<br />
"<br />
Me.ToolStripMenuItem1.Name = "ToolStripMenuItem1"<br />
Me.ToolStripMenuItem1.Size = New System.Drawing.Size(178, 22)<br />
Me.ToolStripMenuItem1.Text = "ToolStripMenuItem1"<br />
"<br />
"ToolStripMenuItem2<br />
"<br />
Me.ToolStripMenuItem2.Name = "ToolStripMenuItem2"<br />
Me.ToolStripMenuItem2.Size = New System.Drawing.Size(178, 22)<br />
Me.ToolStripMenuItem2.Text = "ToolStripMenuItem2"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(481, 190)<br />
Me.Controls.Add(Me.StatusStrip1)<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.StatusStrip1.ResumeLayout(False)<br />
Me.StatusStrip1.PerformLayout()<br />
Me.ResumeLayout(False)<br />
Me.PerformLayout()<br />
End Sub<br />
Friend WithEvents StatusStrip1 As System.Windows.Forms.StatusStrip<br />
Friend WithEvents ToolStripStatusLabel1 As System.Windows.Forms.ToolStripStatusLabel<br />
Friend WithEvents ToolStripProgressBar1 As System.Windows.Forms.ToolStripProgressBar<br />
Friend WithEvents ToolStripDropDownButton1 As System.Windows.Forms.ToolStripDropDownButton<br />
Friend WithEvents ToolStripSplitButton1 As System.Windows.Forms.ToolStripSplitButton<br />
Friend WithEvents ToolStripMenuItem1 As System.Windows.Forms.ToolStripMenuItem<br />
Friend WithEvents ToolStripMenuItem2 As System.Windows.Forms.ToolStripMenuItem<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/MenuItem&diff=3865
VB.Net Tutorial/GUI/MenuItem
2010-05-26T12:57:13Z
<p>Admin: 1 версия</p>
<hr />
<div>==Add Menu and MenuItem in your code==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.IO<br />
Imports System.Windows.Forms<br />
public class MenuAddDynamically<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
Private ourMenu As MainMenu<br />
Private ourTop As MenuItem<br />
Private WithEvents ourItem As MenuItem<br />
Private Sub menuClick(ByVal sender As Object, ByVal e As System.EventArgs) <br />
MessageBox.Show("You clicked " & sender.text & ".", _<br />
"Interactive Menu Creator!")<br />
End Sub<br />
<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
Friend WithEvents btnMainMenu As System.Windows.Forms.Button<br />
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox<br />
Friend WithEvents btnTopMnu As System.Windows.Forms.Button<br />
Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox<br />
Friend WithEvents btnAddItem As System.Windows.Forms.Button<br />
Friend WithEvents lstTopLevel As System.Windows.Forms.ListBox<br />
Friend WithEvents Label5 As System.Windows.Forms.Label<br />
Friend WithEvents txtItemText As System.Windows.Forms.TextBox<br />
Friend WithEvents txtTopLevel As System.Windows.Forms.TextBox<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.btnMainMenu = New System.Windows.Forms.Button()<br />
Me.GroupBox1 = New System.Windows.Forms.GroupBox()<br />
Me.txtTopLevel = New System.Windows.Forms.TextBox()<br />
Me.btnTopMnu = New System.Windows.Forms.Button()<br />
Me.GroupBox2 = New System.Windows.Forms.GroupBox()<br />
Me.Label5 = New System.Windows.Forms.Label()<br />
Me.lstTopLevel = New System.Windows.Forms.ListBox()<br />
Me.btnAddItem = New System.Windows.Forms.Button()<br />
Me.txtItemText = New System.Windows.Forms.TextBox()<br />
Me.GroupBox1.SuspendLayout()<br />
Me.GroupBox2.SuspendLayout()<br />
Me.SuspendLayout()<br />
"<br />
"btnMainMenu<br />
"<br />
Me.btnMainMenu.Location = New System.Drawing.Point(40, 16)<br />
Me.btnMainMenu.Name = "btnMainMenu"<br />
Me.btnMainMenu.Size = New System.Drawing.Size(128, 40)<br />
Me.btnMainMenu.TabIndex = 0<br />
Me.btnMainMenu.Text = "Create the MainMenu"<br />
"<br />
"GroupBox1<br />
"<br />
Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.txtTopLevel, Me.btnTopMnu})<br />
Me.GroupBox1.Location = New System.Drawing.Point(40, 80)<br />
Me.GroupBox1.Name = "GroupBox1"<br />
Me.GroupBox1.Size = New System.Drawing.Size(344, 104)<br />
Me.GroupBox1.TabIndex = 1<br />
Me.GroupBox1.TabStop = False<br />
Me.GroupBox1.Text = "Add top-level Menu text:"<br />
"<br />
"txtTopLevel<br />
"<br />
Me.txtTopLevel.Location = New System.Drawing.Point(24, 24)<br />
Me.txtTopLevel.Name = "txtTopLevel"<br />
Me.txtTopLevel.Size = New System.Drawing.Size(272, 20)<br />
Me.txtTopLevel.TabIndex = 5<br />
Me.txtTopLevel.Text = ""<br />
"<br />
"btnTopMnu<br />
"<br />
Me.btnTopMnu.Location = New System.Drawing.Point(200, 64)<br />
Me.btnTopMnu.Name = "btnTopMnu"<br />
Me.btnTopMnu.Size = New System.Drawing.Size(88, 24)<br />
Me.btnTopMnu.TabIndex = 4<br />
Me.btnTopMnu.Text = "Make it so!"<br />
"<br />
"GroupBox2<br />
"<br />
Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label5, Me.lstTopLevel, Me.btnAddItem, Me.txtItemText})<br />
Me.GroupBox2.Location = New System.Drawing.Point(40, 216)<br />
Me.GroupBox2.Name = "GroupBox2"<br />
Me.GroupBox2.Size = New System.Drawing.Size(344, 248)<br />
Me.GroupBox2.TabIndex = 2<br />
Me.GroupBox2.TabStop = False<br />
Me.GroupBox2.Text = "Add menu item text:"<br />
"<br />
"Label5<br />
"<br />
Me.Label5.Location = New System.Drawing.Point(32, 64)<br />
Me.Label5.Name = "Label5"<br />
Me.Label5.Size = New System.Drawing.Size(256, 16)<br />
Me.Label5.TabIndex = 6<br />
Me.Label5.Text = "Select menu the item goes on:"<br />
"<br />
"lstTopLevel<br />
"<br />
Me.lstTopLevel.Location = New System.Drawing.Point(16, 88)<br />
Me.lstTopLevel.Name = "lstTopLevel"<br />
Me.lstTopLevel.Size = New System.Drawing.Size(288, 108)<br />
Me.lstTopLevel.TabIndex = 5<br />
"<br />
"btnAddItem<br />
"<br />
Me.btnAddItem.Location = New System.Drawing.Point(216, 208)<br />
Me.btnAddItem.Name = "btnAddItem"<br />
Me.btnAddItem.Size = New System.Drawing.Size(88, 24)<br />
Me.btnAddItem.TabIndex = 4<br />
Me.btnAddItem.Text = "Add Item!"<br />
"<br />
"txtItemText<br />
"<br />
Me.txtItemText.Location = New System.Drawing.Point(56, 32)<br />
Me.txtItemText.Name = "txtItemText"<br />
Me.txtItemText.Size = New System.Drawing.Size(200, 20)<br />
Me.txtItemText.TabIndex = 3<br />
Me.txtItemText.Text = ""<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(440, 510)<br />
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.GroupBox2, Me.GroupBox1, Me.btnMainMenu})<br />
Me.Name = "Form1"<br />
Me.Text = "Interactive menu creator"<br />
Me.GroupBox1.ResumeLayout(False)<br />
Me.GroupBox2.ResumeLayout(False)<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub btnMainMenu_Click(ByVal sender As System.Object, _<br />
ByVal e As System.EventArgs) Handles btnMainMenu.Click<br />
ourMenu = New MainMenu()<br />
Me.Menu = ourMenu<br />
End Sub<br />
Private Sub btnTopMnu_Click(ByVal sender As System.Object, _<br />
ByVal e As System.EventArgs) Handles btnTopMnu.Click<br />
Dim itemString As String = txtTopLevel.Text<br />
ourTop = New MenuItem(itemString)<br />
ourMenu.MenuItems.Add(ourTop)<br />
lstTopLevel.Items.Add(itemString)<br />
End Sub<br />
Private Sub btnAddItem_Click(ByVal sender As System.Object, _<br />
ByVal e As System.EventArgs) Handles btnAddItem.Click<br />
Dim i As Integer<br />
i = 0<br />
ourItem = New MenuItem(txtItemText.Text, New System.EventHandler (AddressOf Me.menuClick))<br />
ourMenu.MenuItems(i).MenuItems.Add(ourItem)<br />
End Sub<br />
End Class</source><br />
<br />
==Add submenu to menu==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class OwnerDrawMenuAndSubmenu<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu<br />
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem6 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem7 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem8 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem9 As System.Windows.Forms.MenuItem<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.MainMenu1 = New System.Windows.Forms.MainMenu<br />
Me.MenuItem1 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem2 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem7 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem8 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem9 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem3 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem4 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem5 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem6 = New System.Windows.Forms.MenuItem<br />
Me.SuspendLayout()<br />
"<br />
"MainMenu1<br />
"<br />
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1})<br />
"<br />
"MenuItem1<br />
"<br />
Me.MenuItem1.Index = 0<br />
Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem2, Me.MenuItem3, Me.MenuItem4, Me.MenuItem5, Me.MenuItem6})<br />
Me.MenuItem1.Text = "&File"<br />
"<br />
"MenuItem2<br />
"<br />
Me.MenuItem2.Index = 0<br />
Me.MenuItem2.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem7, Me.MenuItem8, Me.MenuItem9})<br />
Me.MenuItem2.Text = "Item 1"<br />
"<br />
"MenuItem7<br />
"<br />
Me.MenuItem7.Index = 0<br />
Me.MenuItem7.OwnerDraw = True<br />
Me.MenuItem7.Text = "Item 5"<br />
"<br />
"MenuItem8<br />
"<br />
Me.MenuItem8.Checked = True<br />
Me.MenuItem8.Index = 1<br />
Me.MenuItem8.Text = "Item 6"<br />
"<br />
"MenuItem9<br />
"<br />
Me.MenuItem9.Index = 2<br />
Me.MenuItem9.Text = "Item 7"<br />
"<br />
"MenuItem3<br />
"<br />
Me.MenuItem3.Index = 1<br />
Me.MenuItem3.Text = "Item 2"<br />
"<br />
"MenuItem4<br />
"<br />
Me.MenuItem4.Index = 2<br />
Me.MenuItem4.Text = "Item 3"<br />
"<br />
"MenuItem5<br />
"<br />
Me.MenuItem5.Index = 3<br />
Me.MenuItem5.Text = "-"<br />
"<br />
"MenuItem6<br />
"<br />
Me.MenuItem6.Index = 4<br />
Me.MenuItem6.Shortcut = System.Windows.Forms.Shortcut.CtrlX<br />
Me.MenuItem6.Text = "E&xit"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(292, 273)<br />
Me.Menu = Me.MainMenu1<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Private Sub MenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem6.Click<br />
End<br />
End Sub<br />
Private Sub MenuItem9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem9.Click<br />
MsgBox("You clicked Item 7.")<br />
End Sub<br />
Private Sub MenuItem8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem8.Click<br />
MenuItem8.Checked = Not MenuItem8.Checked<br />
End Sub<br />
Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click<br />
MenuItem4.Visible = False<br />
End Sub<br />
Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click<br />
MenuItem3.Enabled = False<br />
End Sub<br />
Private Sub MenuItem7_MeasureItem(ByVal sender As Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles MenuItem7.MeasureItem<br />
e.ItemHeight = 15<br />
e.ItemWidth = 60<br />
End Sub<br />
Private Sub MenuItem7_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles MenuItem7.DrawItem<br />
Dim penRed As New Pen(Color.Red)<br />
e.Graphics.DrawEllipse(penRed, e.Bounds)<br />
End Sub<br />
End Class</source><br />
<br />
==Owner Draw MenuItem==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class OwnerDrawMenu<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
Private files() As String = {"yourfile.jpg", "yourfile.jpg"}<br />
<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents mainMenu1 As System.Windows.Forms.MainMenu<br />
Friend WithEvents mnuFile As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuNew As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuFileOpen As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuFileClose As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuFileSave As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuFileSaveAs As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuEdit As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuEditCopy As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuEditPaste As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuOptions As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuOption1 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuOption2 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuOption3 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuRadioOptions As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuRadioOption1 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuRadioOption2 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuRadioOption3 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuWindow As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu1 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu11 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu12 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu13 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu14 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMerge As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu2 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu21 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu22 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu23 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuMenu24 As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuSpecial As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuODVote As System.Windows.Forms.MenuItem<br />
Friend WithEvents mnuODShazam As System.Windows.Forms.MenuItem<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.mainMenu1 = New System.Windows.Forms.MainMenu()<br />
Me.mnuFile = New System.Windows.Forms.MenuItem()<br />
Me.mnuNew = New System.Windows.Forms.MenuItem()<br />
Me.mnuFileOpen = New System.Windows.Forms.MenuItem()<br />
Me.mnuFileClose = New System.Windows.Forms.MenuItem()<br />
Me.mnuFileSave = New System.Windows.Forms.MenuItem()<br />
Me.mnuFileSaveAs = New System.Windows.Forms.MenuItem()<br />
Me.mnuEdit = New System.Windows.Forms.MenuItem()<br />
Me.mnuEditCopy = New System.Windows.Forms.MenuItem()<br />
Me.mnuEditPaste = New System.Windows.Forms.MenuItem()<br />
Me.mnuOptions = New System.Windows.Forms.MenuItem()<br />
Me.mnuOption1 = New System.Windows.Forms.MenuItem()<br />
Me.mnuOption2 = New System.Windows.Forms.MenuItem()<br />
Me.mnuOption3 = New System.Windows.Forms.MenuItem()<br />
Me.mnuRadioOptions = New System.Windows.Forms.MenuItem()<br />
Me.mnuRadioOption1 = New System.Windows.Forms.MenuItem()<br />
Me.mnuRadioOption2 = New System.Windows.Forms.MenuItem()<br />
Me.mnuRadioOption3 = New System.Windows.Forms.MenuItem()<br />
Me.mnuWindow = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu1 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu11 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu12 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu13 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu14 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMerge = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu2 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu21 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu22 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu23 = New System.Windows.Forms.MenuItem()<br />
Me.mnuMenu24 = New System.Windows.Forms.MenuItem()<br />
Me.mnuSpecial = New System.Windows.Forms.MenuItem()<br />
Me.mnuODVote = New System.Windows.Forms.MenuItem()<br />
Me.mnuODShazam = New System.Windows.Forms.MenuItem()<br />
"<br />
"mainMenu1<br />
"<br />
Me.mainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuFile, Me.mnuEdit, Me.mnuOptions, Me.mnuRadioOptions, Me.mnuWindow, Me.mnuMenu1, Me.mnuMenu2, Me.mnuSpecial})<br />
"<br />
"mnuFile<br />
"<br />
Me.mnuFile.Index = 0<br />
Me.mnuFile.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuNew, Me.mnuFileOpen, Me.mnuFileClose, Me.mnuFileSave, Me.mnuFileSaveAs})<br />
Me.mnuFile.Text = "File"<br />
"<br />
"mnuNew<br />
"<br />
Me.mnuNew.Index = 0<br />
Me.mnuNew.Shortcut = System.Windows.Forms.Shortcut.CtrlN<br />
Me.mnuNew.Text = "&New"<br />
"<br />
"mnuFileOpen<br />
"<br />
Me.mnuFileOpen.Index = 1<br />
Me.mnuFileOpen.Text = "Open"<br />
"<br />
"mnuFileClose<br />
"<br />
Me.mnuFileClose.Index = 2<br />
Me.mnuFileClose.Text = "Close"<br />
"<br />
"mnuFileSave<br />
"<br />
Me.mnuFileSave.Index = 3<br />
Me.mnuFileSave.Text = "Save"<br />
"<br />
"mnuFileSaveAs<br />
"<br />
Me.mnuFileSaveAs.Index = 4<br />
Me.mnuFileSaveAs.Text = "Save&As"<br />
"<br />
"mnuEdit<br />
"<br />
Me.mnuEdit.Index = 1<br />
Me.mnuEdit.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuEditCopy, Me.mnuEditPaste})<br />
Me.mnuEdit.Text = "Edit"<br />
"<br />
"mnuEditCopy<br />
"<br />
Me.mnuEditCopy.Index = 0<br />
Me.mnuEditCopy.Text = "&Copy"<br />
"<br />
"mnuEditPaste<br />
"<br />
Me.mnuEditPaste.Index = 1<br />
Me.mnuEditPaste.Text = "Paste"<br />
"<br />
"mnuOptions<br />
"<br />
Me.mnuOptions.Index = 2<br />
Me.mnuOptions.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuOption1, Me.mnuOption2, Me.mnuOption3})<br />
Me.mnuOptions.Text = "Options"<br />
"<br />
"mnuOption1<br />
"<br />
Me.mnuOption1.Index = 0<br />
Me.mnuOption1.Text = "Option1"<br />
"<br />
"mnuOption2<br />
"<br />
Me.mnuOption2.Index = 1<br />
Me.mnuOption2.Text = "Option2"<br />
"<br />
"mnuOption3<br />
"<br />
Me.mnuOption3.Index = 2<br />
Me.mnuOption3.Text = "Option3"<br />
"<br />
"mnuRadioOptions<br />
"<br />
Me.mnuRadioOptions.Index = 3<br />
Me.mnuRadioOptions.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuRadioOption1, Me.mnuRadioOption2, Me.mnuRadioOption3})<br />
Me.mnuRadioOptions.Text = "Radio Options"<br />
"<br />
"mnuRadioOption1<br />
"<br />
Me.mnuRadioOption1.Index = 0<br />
Me.mnuRadioOption1.RadioCheck = True<br />
Me.mnuRadioOption1.Text = "Radio Option 1"<br />
"<br />
"mnuRadioOption2<br />
"<br />
Me.mnuRadioOption2.Index = 1<br />
Me.mnuRadioOption2.RadioCheck = True<br />
Me.mnuRadioOption2.Text = "Radio Option 2"<br />
"<br />
"mnuRadioOption3<br />
"<br />
Me.mnuRadioOption3.Index = 2<br />
Me.mnuRadioOption3.RadioCheck = True<br />
Me.mnuRadioOption3.Text = "Radio Option 3"<br />
"<br />
"mnuWindow<br />
"<br />
Me.mnuWindow.Index = 4<br />
Me.mnuWindow.MdiList = True<br />
Me.mnuWindow.MergeOrder = 99<br />
Me.mnuWindow.Text = "&Window"<br />
"<br />
"mnuMenu1<br />
"<br />
Me.mnuMenu1.Index = 5<br />
Me.mnuMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuMenu11, Me.mnuMenu12, Me.mnuMenu13, Me.mnuMenu14, Me.mnuMerge})<br />
Me.mnuMenu1.Text = "Menu 1"<br />
"<br />
"mnuMenu11<br />
"<br />
Me.mnuMenu11.Index = 0<br />
Me.mnuMenu11.MergeOrder = 1<br />
Me.mnuMenu11.Text = "Menu 1.1"<br />
"<br />
"mnuMenu12<br />
"<br />
Me.mnuMenu12.Index = 1<br />
Me.mnuMenu12.MergeOrder = 2<br />
Me.mnuMenu12.Text = "Menu 1.2"<br />
"<br />
"mnuMenu13<br />
"<br />
Me.mnuMenu13.Index = 2<br />
Me.mnuMenu13.MergeOrder = 3<br />
Me.mnuMenu13.Text = "Menu 1.3"<br />
"<br />
"mnuMenu14<br />
"<br />
Me.mnuMenu14.Index = 3<br />
Me.mnuMenu14.MergeOrder = 4<br />
Me.mnuMenu14.Text = "Menu 1.4"<br />
"<br />
"mnuMerge<br />
"<br />
Me.mnuMerge.Index = 4<br />
Me.mnuMerge.MergeOrder = 99<br />
Me.mnuMerge.Text = "Merge!"<br />
"<br />
"mnuMenu2<br />
"<br />
Me.mnuMenu2.Index = 6<br />
Me.mnuMenu2.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuMenu21, Me.mnuMenu22, Me.mnuMenu23, Me.mnuMenu24})<br />
Me.mnuMenu2.Text = "Menu 2"<br />
"<br />
"mnuMenu21<br />
"<br />
Me.mnuMenu21.Index = 0<br />
Me.mnuMenu21.MergeOrder = 1<br />
Me.mnuMenu21.Text = "Menu 2.1"<br />
"<br />
"mnuMenu22<br />
"<br />
Me.mnuMenu22.Index = 1<br />
Me.mnuMenu22.MergeOrder = 2<br />
Me.mnuMenu22.MergeType = System.Windows.Forms.MenuMerge.Replace<br />
Me.mnuMenu22.Text = "Menu 2.2"<br />
"<br />
"mnuMenu23<br />
"<br />
Me.mnuMenu23.Index = 2<br />
Me.mnuMenu23.MergeOrder = 3<br />
Me.mnuMenu23.MergeType = System.Windows.Forms.MenuMerge.Remove<br />
Me.mnuMenu23.Text = "Menu 2.3"<br />
"<br />
"mnuMenu24<br />
"<br />
Me.mnuMenu24.Index = 3<br />
Me.mnuMenu24.MergeOrder = 5<br />
Me.mnuMenu24.Text = "Menu 2.4"<br />
"<br />
"mnuSpecial<br />
"<br />
Me.mnuSpecial.Index = 7<br />
Me.mnuSpecial.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuODVote, Me.mnuODShazam})<br />
Me.mnuSpecial.Text = "Special"<br />
"<br />
"mnuODVote<br />
"<br />
Me.mnuODVote.Index = 0<br />
Me.mnuODVote.OwnerDraw = True<br />
Me.mnuODVote.Text = "Vote"<br />
"<br />
"mnuODShazam<br />
"<br />
Me.mnuODShazam.Index = 1<br />
Me.mnuODShazam.OwnerDraw = True<br />
Me.mnuODShazam.Text = "Shazam"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(456, 106)<br />
Me.IsMdiContainer = True<br />
Me.Menu = Me.mainMenu1<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
End Sub<br />
#End Region<br />
Private Sub mnuODVote_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) _<br />
Handles mnuODVote.DrawItem, mnuODShazam.DrawItem<br />
Dim img As Image<br />
img = Image.FromFile(files(e.Index))<br />
Dim r As Rectangle<br />
r = e.Bounds<br />
Dim p As Pen = New Pen(e.BackColor, 2)<br />
r.Inflate(-6, -6)<br />
e.Graphics.DrawRectangle(p, r)<br />
e.Graphics.DrawImage(img, r)<br />
End Sub<br />
Private Sub mnuODVote_MeasureItem(ByVal sender As Object, _<br />
ByVal e As System.Windows.Forms.MeasureItemEventArgs) _<br />
Handles mnuODVote.MeasureItem, mnuODShazam.MeasureItem<br />
Dim img As Image<br />
img = Image.FromFile(files(e.Index))<br />
e.ItemHeight = img.Height<br />
e.ItemWidth = img.Width<br />
End Sub<br />
Private Sub mnuODDraw_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) _<br />
Handles mnuODVote.Click, mnuODShazam.Click<br />
Dim item As MenuItem = CType(sender, MenuItem)<br />
Dim choice As String = item.Text<br />
MessageBox.Show("You clicked " & choice,"Menu Event Tester", MessageBoxButtons.OK, _<br />
MessageBoxIcon.Asterisk)<br />
End Sub<br />
End Class</source><br />
<br />
==Set MenuItem to RadioCheck/Checked==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class DynamicMenu<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
Public Sub New()<br />
MyBase.New()<br />
InitializeComponent()<br />
End Sub<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
Private components As System.ruponentModel.IContainer<br />
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu<br />
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem6 As System.Windows.Forms.MenuItem<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents Button2 As System.Windows.Forms.Button<br />
Friend WithEvents Button3 As System.Windows.Forms.Button<br />
Friend WithEvents Button4 As System.Windows.Forms.Button<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.MainMenu1 = New System.Windows.Forms.MainMenu<br />
Me.MenuItem1 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem2 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem3 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem4 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem5 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem6 = New System.Windows.Forms.MenuItem<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.Button2 = New System.Windows.Forms.Button<br />
Me.Button3 = New System.Windows.Forms.Button<br />
Me.Button4 = New System.Windows.Forms.Button<br />
Me.SuspendLayout()<br />
"<br />
"MainMenu1<br />
"<br />
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem3})<br />
"<br />
"MenuItem1<br />
"<br />
Me.MenuItem1.Index = 0<br />
Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem2})<br />
Me.MenuItem1.Text = "File"<br />
"<br />
"MenuItem2<br />
"<br />
Me.MenuItem2.Index = 0<br />
Me.MenuItem2.Text = "Open"<br />
"<br />
"MenuItem3<br />
"<br />
Me.MenuItem3.Index = 1<br />
Me.MenuItem3.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem4, Me.MenuItem5, Me.MenuItem6})<br />
Me.MenuItem3.Text = "Edit"<br />
"<br />
"MenuItem4<br />
"<br />
Me.MenuItem4.Index = 0<br />
Me.MenuItem4.Text = "Cut"<br />
"<br />
"MenuItem5<br />
"<br />
Me.MenuItem5.Index = 1<br />
Me.MenuItem5.Text = "Copy"<br />
"<br />
"MenuItem6<br />
"<br />
Me.MenuItem6.Index = 2<br />
Me.MenuItem6.Text = "Paste"<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(200, 8)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.Size = New System.Drawing.Size(72, 24)<br />
Me.Button1.TabIndex = 3<br />
Me.Button1.Text = "Select"<br />
"<br />
"Button2<br />
"<br />
Me.Button2.Location = New System.Drawing.Point(200, 48)<br />
Me.Button2.Name = "Button2"<br />
Me.Button2.Size = New System.Drawing.Size(72, 24)<br />
Me.Button2.TabIndex = 4<br />
Me.Button2.Text = "Disable"<br />
"<br />
"Button3<br />
"<br />
Me.Button3.Location = New System.Drawing.Point(200, 88)<br />
Me.Button3.Name = "Button3"<br />
Me.Button3.Size = New System.Drawing.Size(72, 24)<br />
Me.Button3.TabIndex = 5<br />
Me.Button3.Text = "RadioButton"<br />
"<br />
"Button4<br />
"<br />
Me.Button4.Location = New System.Drawing.Point(200, 136)<br />
Me.Button4.Name = "Button4"<br />
Me.Button4.Size = New System.Drawing.Size(72, 24)<br />
Me.Button4.TabIndex = 6<br />
Me.Button4.Text = "Hide"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(328, 225)<br />
Me.Controls.Add(Me.Button4)<br />
Me.Controls.Add(Me.Button3)<br />
Me.Controls.Add(Me.Button2)<br />
Me.Controls.Add(Me.Button1)<br />
Me.Menu = Me.MainMenu1<br />
Me.ResumeLayout(False)<br />
End Sub<br />
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
MenuItem4.RadioCheck = False<br />
MenuItem5.RadioCheck = False<br />
MenuItem6.RadioCheck = False<br />
MenuItem6.Checked = MenuItem4.Checked<br />
MenuItem4.Checked = Not MenuItem4.Checked<br />
MenuItem5.Checked = Not MenuItem5.Checked<br />
MenuItem6.Checked = Not MenuItem6.Checked<br />
End Sub<br />
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click<br />
MenuItem4.RadioCheck = False<br />
MenuItem5.RadioCheck = False<br />
MenuItem6.RadioCheck = False<br />
MenuItem6.Checked = MenuItem4.Checked<br />
MenuItem4.Enabled = Not MenuItem4.Enabled<br />
MenuItem5.Enabled = Not MenuItem5.Enabled<br />
MenuItem6.Enabled = Not MenuItem6.Enabled<br />
End Sub<br />
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click<br />
MenuItem4.Checked = False<br />
MenuItem5.Checked = False<br />
MenuItem6.Checked = True<br />
MenuItem6.RadioCheck = True<br />
End Sub<br />
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click<br />
MenuItem6.Visible = Not MenuItem6.Visible<br />
End Sub<br />
End Class</source><br />
<br />
==Set MenuItem visible and invisible==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class DynamicMenu<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
Public Sub New()<br />
MyBase.New()<br />
InitializeComponent()<br />
End Sub<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
Private components As System.ruponentModel.IContainer<br />
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu<br />
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem<br />
Friend WithEvents MenuItem6 As System.Windows.Forms.MenuItem<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents Button2 As System.Windows.Forms.Button<br />
Friend WithEvents Button3 As System.Windows.Forms.Button<br />
Friend WithEvents Button4 As System.Windows.Forms.Button<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.MainMenu1 = New System.Windows.Forms.MainMenu<br />
Me.MenuItem1 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem2 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem3 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem4 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem5 = New System.Windows.Forms.MenuItem<br />
Me.MenuItem6 = New System.Windows.Forms.MenuItem<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.Button2 = New System.Windows.Forms.Button<br />
Me.Button3 = New System.Windows.Forms.Button<br />
Me.Button4 = New System.Windows.Forms.Button<br />
Me.SuspendLayout()<br />
"<br />
"MainMenu1<br />
"<br />
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem3})<br />
"<br />
"MenuItem1<br />
"<br />
Me.MenuItem1.Index = 0<br />
Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem2})<br />
Me.MenuItem1.Text = "File"<br />
"<br />
"MenuItem2<br />
"<br />
Me.MenuItem2.Index = 0<br />
Me.MenuItem2.Text = "Open"<br />
"<br />
"MenuItem3<br />
"<br />
Me.MenuItem3.Index = 1<br />
Me.MenuItem3.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem4, Me.MenuItem5, Me.MenuItem6})<br />
Me.MenuItem3.Text = "Edit"<br />
"<br />
"MenuItem4<br />
"<br />
Me.MenuItem4.Index = 0<br />
Me.MenuItem4.Text = "Cut"<br />
"<br />
"MenuItem5<br />
"<br />
Me.MenuItem5.Index = 1<br />
Me.MenuItem5.Text = "Copy"<br />
"<br />
"MenuItem6<br />
"<br />
Me.MenuItem6.Index = 2<br />
Me.MenuItem6.Text = "Paste"<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(200, 8)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.Size = New System.Drawing.Size(72, 24)<br />
Me.Button1.TabIndex = 3<br />
Me.Button1.Text = "Select"<br />
"<br />
"Button2<br />
"<br />
Me.Button2.Location = New System.Drawing.Point(200, 48)<br />
Me.Button2.Name = "Button2"<br />
Me.Button2.Size = New System.Drawing.Size(72, 24)<br />
Me.Button2.TabIndex = 4<br />
Me.Button2.Text = "Disable"<br />
"<br />
"Button3<br />
"<br />
Me.Button3.Location = New System.Drawing.Point(200, 88)<br />
Me.Button3.Name = "Button3"<br />
Me.Button3.Size = New System.Drawing.Size(72, 24)<br />
Me.Button3.TabIndex = 5<br />
Me.Button3.Text = "RadioButton"<br />
"<br />
"Button4<br />
"<br />
Me.Button4.Location = New System.Drawing.Point(200, 136)<br />
Me.Button4.Name = "Button4"<br />
Me.Button4.Size = New System.Drawing.Size(72, 24)<br />
Me.Button4.TabIndex = 6<br />
Me.Button4.Text = "Hide"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(328, 225)<br />
Me.Controls.Add(Me.Button4)<br />
Me.Controls.Add(Me.Button3)<br />
Me.Controls.Add(Me.Button2)<br />
Me.Controls.Add(Me.Button1)<br />
Me.Menu = Me.MainMenu1<br />
Me.ResumeLayout(False)<br />
End Sub<br />
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
MenuItem4.RadioCheck = False<br />
MenuItem5.RadioCheck = False<br />
MenuItem6.RadioCheck = False<br />
MenuItem6.Checked = MenuItem4.Checked<br />
MenuItem4.Checked = Not MenuItem4.Checked<br />
MenuItem5.Checked = Not MenuItem5.Checked<br />
MenuItem6.Checked = Not MenuItem6.Checked<br />
End Sub<br />
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click<br />
MenuItem4.RadioCheck = False<br />
MenuItem5.RadioCheck = False<br />
MenuItem6.RadioCheck = False<br />
MenuItem6.Checked = MenuItem4.Checked<br />
MenuItem4.Enabled = Not MenuItem4.Enabled<br />
MenuItem5.Enabled = Not MenuItem5.Enabled<br />
MenuItem6.Enabled = Not MenuItem6.Enabled<br />
End Sub<br />
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click<br />
MenuItem4.Checked = False<br />
MenuItem5.Checked = False<br />
MenuItem6.Checked = True<br />
MenuItem6.RadioCheck = True<br />
End Sub<br />
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click<br />
MenuItem6.Visible = Not MenuItem6.Visible<br />
End Sub<br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/TabControl&diff=3861
VB.Net Tutorial/GUI/TabControl
2010-05-26T12:57:12Z
<p>Admin: 1 версия</p>
<hr />
<div>==Add new Tab==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class AddNewTab<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
Friend WithEvents TabControl1 As System.Windows.Forms.TabControl<br />
Friend WithEvents TabPage1 As System.Windows.Forms.TabPage<br />
Friend WithEvents TabPage2 As System.Windows.Forms.TabPage<br />
Friend WithEvents TabPage3 As System.Windows.Forms.TabPage<br />
Friend WithEvents Label2 As System.Windows.Forms.Label<br />
Friend WithEvents Label3 As System.Windows.Forms.Label<br />
Friend WithEvents Label4 As System.Windows.Forms.Label<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.TabControl1 = New System.Windows.Forms.TabControl<br />
Me.TabPage1 = New System.Windows.Forms.TabPage<br />
Me.TabPage2 = New System.Windows.Forms.TabPage<br />
Me.TabPage3 = New System.Windows.Forms.TabPage<br />
Me.Label2 = New System.Windows.Forms.Label<br />
Me.Label3 = New System.Windows.Forms.Label<br />
Me.Label4 = New System.Windows.Forms.Label<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.TabControl1.SuspendLayout()<br />
Me.TabPage1.SuspendLayout()<br />
Me.TabPage2.SuspendLayout()<br />
Me.TabPage3.SuspendLayout()<br />
Me.SuspendLayout()<br />
"<br />
"TabControl1<br />
"<br />
Me.TabControl1.Controls.Add(Me.TabPage1)<br />
Me.TabControl1.Controls.Add(Me.TabPage2)<br />
Me.TabControl1.Controls.Add(Me.TabPage3)<br />
Me.TabControl1.Dock = System.Windows.Forms.DockStyle.Bottom<br />
Me.TabControl1.HotTrack = True<br />
Me.TabControl1.Location = New System.Drawing.Point(0, 89)<br />
Me.TabControl1.Name = "TabControl1"<br />
Me.TabControl1.SelectedIndex = 0<br />
Me.TabControl1.Size = New System.Drawing.Size(292, 184)<br />
Me.TabControl1.TabIndex = 1<br />
"<br />
"TabPage1<br />
"<br />
Me.TabPage1.Controls.Add(Me.Label2)<br />
Me.TabPage1.Location = New System.Drawing.Point(4, 22)<br />
Me.TabPage1.Name = "TabPage1"<br />
Me.TabPage1.Size = New System.Drawing.Size(284, 158)<br />
Me.TabPage1.TabIndex = 0<br />
Me.TabPage1.Text = "Tab Page 1"<br />
"<br />
"TabPage2<br />
"<br />
Me.TabPage2.Controls.Add(Me.Label3)<br />
Me.TabPage2.Location = New System.Drawing.Point(4, 22)<br />
Me.TabPage2.Name = "TabPage2"<br />
Me.TabPage2.Size = New System.Drawing.Size(284, 158)<br />
Me.TabPage2.TabIndex = 1<br />
Me.TabPage2.Text = "Tab Page 2"<br />
"<br />
"TabPage3<br />
"<br />
Me.TabPage3.Controls.Add(Me.Label4)<br />
Me.TabPage3.Location = New System.Drawing.Point(4, 22)<br />
Me.TabPage3.Name = "TabPage3"<br />
Me.TabPage3.Size = New System.Drawing.Size(284, 158)<br />
Me.TabPage3.TabIndex = 2<br />
Me.TabPage3.Text = "Tab Page 3"<br />
"<br />
"Label2<br />
"<br />
Me.Label2.Dock = System.Windows.Forms.DockStyle.Fill<br />
Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 24.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.Label2.Location = New System.Drawing.Point(0, 0)<br />
Me.Label2.Name = "Label2"<br />
Me.Label2.Size = New System.Drawing.Size(284, 158)<br />
Me.Label2.TabIndex = 0<br />
Me.Label2.Text = "Tab Page 1"<br />
"<br />
"Label3<br />
"<br />
Me.Label3.Dock = System.Windows.Forms.DockStyle.Fill<br />
Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 24.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.Label3.Location = New System.Drawing.Point(0, 0)<br />
Me.Label3.Name = "Label3"<br />
Me.Label3.Size = New System.Drawing.Size(284, 158)<br />
Me.Label3.TabIndex = 0<br />
Me.Label3.Text = "Tab Page 2"<br />
"<br />
"Label4<br />
"<br />
Me.Label4.Dock = System.Windows.Forms.DockStyle.Fill<br />
Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 24.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.Label4.Location = New System.Drawing.Point(0, 0)<br />
Me.Label4.Name = "Label4"<br />
Me.Label4.Size = New System.Drawing.Size(284, 158)<br />
Me.Label4.TabIndex = 0<br />
Me.Label4.Text = "Tab Page 3"<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(96, 48)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.Size = New System.Drawing.Size(88, 23)<br />
Me.Button1.TabIndex = 2<br />
Me.Button1.Text = "Add New Tab"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(292, 273)<br />
Me.Controls.Add(Me.Button1)<br />
Me.Controls.Add(Me.TabControl1)<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.TabControl1.ResumeLayout(False)<br />
Me.TabPage1.ResumeLayout(False)<br />
Me.TabPage2.ResumeLayout(False)<br />
Me.TabPage3.ResumeLayout(False)<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
Dim tabPage4 As New TabPage<br />
Dim lblLabel1 As New Label<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
tabPage4.Text = "Tab Page 4"<br />
TabControl1.TabPages.Add(tabPage4)<br />
lblLabel1.Dock = DockStyle.Fill<br />
lblLabel1.Text = "Tab Page 4"<br />
lblLabel1.Font = New Font("Microsoft San Serif", 24)<br />
TabControl1.TabPages(3).Controls.Add(lblLabel1)<br />
End Sub<br />
End Class</source><br />
<br />
==Custom Tab==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
Imports System.Drawing<br />
public class CustomTabControl<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
" Draw ellipses in the tabs.<br />
Private Sub tabProject_DrawItem(ByVal sender As Object, _<br />
ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles tabProject.DrawItem<br />
" Get the drawing bounds.<br />
Dim rect As Rectangle = e.Bounds<br />
If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then<br />
" Allow extra room for the selected tab.<br />
rect.X += 4<br />
rect.Y += 4<br />
rect.Width -= 8<br />
rect.Height -= 8<br />
Else<br />
rect.X += 2<br />
rect.Y += 2<br />
rect.Width -= 4<br />
rect.Height -= 4<br />
End If<br />
" Fill the ellipse with the right color.<br />
Select Case e.Index<br />
Case 0<br />
e.Graphics.FillEllipse(Brushes.Green, rect)<br />
Case 1<br />
e.Graphics.FillEllipse(Brushes.Yellow, rect)<br />
Case 2<br />
e.Graphics.FillEllipse(Brushes.Red, rect)<br />
End Select<br />
" Outline the ellipse in black.<br />
If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then<br />
" Use a thick line for the selected tab.<br />
e.Graphics.DrawEllipse( _<br />
New Pen(Color.Black, 3), _<br />
rect)<br />
Else<br />
e.Graphics.DrawEllipse(Pens.Black, rect)<br />
End If<br />
End Sub<br />
End Class<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.tabProject = New System.Windows.Forms.TabControl<br />
Me.TabPage1 = New System.Windows.Forms.TabPage<br />
Me.TabPage2 = New System.Windows.Forms.TabPage<br />
Me.TabPage3 = New System.Windows.Forms.TabPage<br />
Me.tabProject.SuspendLayout()<br />
Me.SuspendLayout()<br />
"<br />
"tabProject<br />
"<br />
Me.tabProject.Controls.Add(Me.TabPage1)<br />
Me.tabProject.Controls.Add(Me.TabPage2)<br />
Me.tabProject.Controls.Add(Me.TabPage3)<br />
Me.tabProject.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed<br />
Me.tabProject.Location = New System.Drawing.Point(8, 8)<br />
Me.tabProject.Name = "tabProject"<br />
Me.tabProject.SelectedIndex = 0<br />
Me.tabProject.Size = New System.Drawing.Size(272, 200)<br />
Me.tabProject.TabIndex = 1<br />
"<br />
"TabPage1<br />
"<br />
Me.TabPage1.Location = New System.Drawing.Point(4, 22)<br />
Me.TabPage1.Name = "TabPage1"<br />
Me.TabPage1.Padding = New System.Windows.Forms.Padding(3)<br />
Me.TabPage1.Size = New System.Drawing.Size(264, 174)<br />
Me.TabPage1.TabIndex = 0<br />
Me.TabPage1.Text = "TabPage1"<br />
"<br />
"TabPage2<br />
"<br />
Me.TabPage2.Location = New System.Drawing.Point(4, 22)<br />
Me.TabPage2.Name = "TabPage2"<br />
Me.TabPage2.Padding = New System.Windows.Forms.Padding(3)<br />
Me.TabPage2.Size = New System.Drawing.Size(264, 174)<br />
Me.TabPage2.TabIndex = 1<br />
Me.TabPage2.Text = "TabPage2"<br />
"<br />
"TabPage3<br />
"<br />
Me.TabPage3.Location = New System.Drawing.Point(4, 22)<br />
Me.TabPage3.Name = "TabPage3"<br />
Me.TabPage3.Size = New System.Drawing.Size(264, 174)<br />
Me.TabPage3.TabIndex = 2<br />
Me.TabPage3.Text = "TabPage3"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(289, 217)<br />
Me.Controls.Add(Me.tabProject)<br />
Me.Name = "Form1"<br />
Me.Text = "UseTabControlOwnerDrawn"<br />
Me.tabProject.ResumeLayout(False)<br />
Me.ResumeLayout(False)<br />
End Sub<br />
Friend WithEvents tabProject As System.Windows.Forms.TabControl<br />
Friend WithEvents TabPage1 As System.Windows.Forms.TabPage<br />
Friend WithEvents TabPage2 As System.Windows.Forms.TabPage<br />
Friend WithEvents TabPage3 As System.Windows.Forms.TabPage<br />
End Class</source><br />
<br />
==Put RadioButtons to a Tab Control==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class TabControlRadioButton<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
<br />
Public Class Form1<br />
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
End Sub<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
If RadioButton1.Checked = True Then<br />
Me.BackColor = System.Drawing.Color.Red<br />
End If<br />
If RadioButton2.Checked = True Then<br />
Me.BackColor = System.Drawing.Color.Blue<br />
End If<br />
End Sub<br />
End Class<br />
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _<br />
Partial Class Form1<br />
Inherits System.Windows.Forms.Form<br />
"Form overrides dispose to clean up the component list.<br />
<System.Diagnostics.DebuggerNonUserCode()> _<br />
Protected Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing AndAlso components IsNot Nothing Then<br />
components.Dispose()<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.IContainer<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> _<br />
Private Sub InitializeComponent()<br />
Me.TabControl1 = New System.Windows.Forms.TabControl<br />
Me.myscreensave = New System.Windows.Forms.TabPage<br />
Me.mybackground = New System.Windows.Forms.TabPage<br />
Me.TextBox1 = New System.Windows.Forms.TextBox<br />
Me.Label1 = New System.Windows.Forms.Label<br />
Me.RadioButton1 = New System.Windows.Forms.RadioButton<br />
Me.RadioButton2 = New System.Windows.Forms.RadioButton<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.Button2 = New System.Windows.Forms.Button<br />
Me.TabControl1.SuspendLayout()<br />
Me.myscreensave.SuspendLayout()<br />
Me.mybackground.SuspendLayout()<br />
Me.SuspendLayout()<br />
"<br />
"TabControl1<br />
"<br />
Me.TabControl1.Controls.Add(Me.myscreensave)<br />
Me.TabControl1.Controls.Add(Me.mybackground)<br />
Me.TabControl1.Location = New System.Drawing.Point(17, 12)<br />
Me.TabControl1.Name = "TabControl1"<br />
Me.TabControl1.SelectedIndex = 0<br />
Me.TabControl1.Size = New System.Drawing.Size(379, 161)<br />
Me.TabControl1.TabIndex = 0<br />
"<br />
"myscreensave<br />
"<br />
Me.myscreensave.Controls.Add(Me.TextBox1)<br />
Me.myscreensave.Location = New System.Drawing.Point(4, 21)<br />
Me.myscreensave.Name = "myscreensave"<br />
Me.myscreensave.Padding = New System.Windows.Forms.Padding(3)<br />
Me.myscreensave.Size = New System.Drawing.Size(371, 136)<br />
Me.myscreensave.TabIndex = 0<br />
Me.myscreensave.Text = "Screen Saver"<br />
Me.myscreensave.UseVisualStyleBackColor = True<br />
"<br />
"mybackground<br />
"<br />
Me.mybackground.Controls.Add(Me.RadioButton2)<br />
Me.mybackground.Controls.Add(Me.RadioButton1)<br />
Me.mybackground.Controls.Add(Me.Label1)<br />
Me.mybackground.Location = New System.Drawing.Point(4, 21)<br />
Me.mybackground.Name = "mybackground"<br />
Me.mybackground.Padding = New System.Windows.Forms.Padding(3)<br />
Me.mybackground.Size = New System.Drawing.Size(371, 156)<br />
Me.mybackground.TabIndex = 1<br />
Me.mybackground.Text = "Color"<br />
Me.mybackground.UseVisualStyleBackColor = True<br />
"<br />
"TextBox1<br />
"<br />
Me.TextBox1.Location = New System.Drawing.Point(6, 101)<br />
Me.TextBox1.Name = "TextBox1"<br />
Me.TextBox1.Size = New System.Drawing.Size(260, 21)<br />
Me.TextBox1.TabIndex = 0<br />
Me.TextBox1.Text = "Function"<br />
"<br />
"Label1<br />
"<br />
Me.Label1.AutoSize = True<br />
Me.Label1.Location = New System.Drawing.Point(23, 16)<br />
Me.Label1.Name = "Label1"<br />
Me.Label1.Size = New System.Drawing.Size(89, 12)<br />
Me.Label1.TabIndex = 0<br />
Me.Label1.Text = "Select"<br />
"<br />
"RadioButton1<br />
"<br />
Me.RadioButton1.AutoSize = True<br />
Me.RadioButton1.Location = New System.Drawing.Point(25, 49)<br />
Me.RadioButton1.Name = "RadioButton1"<br />
Me.RadioButton1.Size = New System.Drawing.Size(47, 16)<br />
Me.RadioButton1.TabIndex = 1<br />
Me.RadioButton1.TabStop = True<br />
Me.RadioButton1.Text = "Red"<br />
Me.RadioButton1.UseVisualStyleBackColor = True<br />
"<br />
"RadioButton2<br />
"<br />
Me.RadioButton2.AutoSize = True<br />
Me.RadioButton2.Location = New System.Drawing.Point(25, 71)<br />
Me.RadioButton2.Name = "RadioButton2"<br />
Me.RadioButton2.Size = New System.Drawing.Size(47, 16)<br />
Me.RadioButton2.TabIndex = 2<br />
Me.RadioButton2.TabStop = True<br />
Me.RadioButton2.Text = "Blue"<br />
Me.RadioButton2.UseVisualStyleBackColor = True<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(58, 179)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.Size = New System.Drawing.Size(75, 23)<br />
Me.Button1.TabIndex = 1<br />
Me.Button1.Text = "OK"<br />
Me.Button1.UseVisualStyleBackColor = True<br />
"<br />
"Button2<br />
"<br />
Me.Button2.Location = New System.Drawing.Point(250, 179)<br />
Me.Button2.Name = "Button2"<br />
Me.Button2.Size = New System.Drawing.Size(75, 23)<br />
Me.Button2.TabIndex = 2<br />
Me.Button2.Text = "Cancel"<br />
Me.Button2.UseVisualStyleBackColor = True<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)<br />
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font<br />
Me.ClientSize = New System.Drawing.Size(407, 214)<br />
Me.Controls.Add(Me.Button2)<br />
Me.Controls.Add(Me.Button1)<br />
Me.Controls.Add(Me.TabControl1)<br />
Me.Name = "Form1"<br />
Me.Text = "TabControl Demo"<br />
Me.TabControl1.ResumeLayout(False)<br />
Me.myscreensave.ResumeLayout(False)<br />
Me.myscreensave.PerformLayout()<br />
Me.mybackground.ResumeLayout(False)<br />
Me.mybackground.PerformLayout()<br />
Me.ResumeLayout(False)<br />
End Sub<br />
Friend WithEvents TabControl1 As System.Windows.Forms.TabControl<br />
Friend WithEvents myscreensave As System.Windows.Forms.TabPage<br />
Friend WithEvents mybackground As System.Windows.Forms.TabPage<br />
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox<br />
Friend WithEvents Label1 As System.Windows.Forms.Label<br />
Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton<br />
Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents Button2 As System.Windows.Forms.Button<br />
End Class</source><br />
<br />
==Tab Control==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
public class TabControl<br />
public Shared Sub Main<br />
Application.Run(New Form1)<br />
End Sub<br />
End class<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
Public Sub New()<br />
MyBase.New()<br />
InitializeComponent()<br />
End Sub<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
Private components As System.ruponentModel.IContainer<br />
Friend WithEvents TabControl1 As System.Windows.Forms.TabControl<br />
Friend WithEvents TabPage1 As System.Windows.Forms.TabPage<br />
Friend WithEvents TabPage2 As System.Windows.Forms.TabPage<br />
Friend WithEvents TabPage3 As System.Windows.Forms.TabPage<br />
Friend WithEvents TabPage4 As System.Windows.Forms.TabPage<br />
Friend WithEvents TabPage5 As System.Windows.Forms.TabPage<br />
Friend WithEvents TabPage6 As System.Windows.Forms.TabPage<br />
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox<br />
Friend WithEvents Button1 As System.Windows.Forms.Button<br />
Friend WithEvents Button2 As System.Windows.Forms.Button<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.TabControl1 = New System.Windows.Forms.TabControl<br />
Me.TabPage1 = New System.Windows.Forms.TabPage<br />
Me.TabPage2 = New System.Windows.Forms.TabPage<br />
Me.TabPage3 = New System.Windows.Forms.TabPage<br />
Me.TabPage4 = New System.Windows.Forms.TabPage<br />
Me.TabPage5 = New System.Windows.Forms.TabPage<br />
Me.TabPage6 = New System.Windows.Forms.TabPage<br />
Me.ListBox1 = New System.Windows.Forms.ListBox<br />
Me.Button1 = New System.Windows.Forms.Button<br />
Me.Button2 = New System.Windows.Forms.Button<br />
Me.TabControl1.SuspendLayout()<br />
Me.TabPage1.SuspendLayout()<br />
Me.SuspendLayout()<br />
"<br />
"TabControl1<br />
"<br />
Me.TabControl1.Controls.Add(Me.TabPage1)<br />
Me.TabControl1.Controls.Add(Me.TabPage3)<br />
Me.TabControl1.Controls.Add(Me.TabPage2)<br />
Me.TabControl1.Controls.Add(Me.TabPage4)<br />
Me.TabControl1.Controls.Add(Me.TabPage5)<br />
Me.TabControl1.Controls.Add(Me.TabPage6)<br />
Me.TabControl1.Location = New System.Drawing.Point(40, 24)<br />
Me.TabControl1.Multiline = True<br />
Me.TabControl1.Name = "TabControl1"<br />
Me.TabControl1.SelectedIndex = 0<br />
Me.TabControl1.Size = New System.Drawing.Size(208, 208)<br />
Me.TabControl1.TabIndex = 0<br />
"<br />
"TabPage1<br />
"<br />
Me.TabPage1.Controls.Add(Me.Button2)<br />
Me.TabPage1.Controls.Add(Me.Button1)<br />
Me.TabPage1.Controls.Add(Me.ListBox1)<br />
Me.TabPage1.Location = New System.Drawing.Point(4, 40)<br />
Me.TabPage1.Name = "TabPage1"<br />
Me.TabPage1.Size = New System.Drawing.Size(200, 164)<br />
Me.TabPage1.TabIndex = 0<br />
Me.TabPage1.Text = "A"<br />
"<br />
"TabPage2<br />
"<br />
Me.TabPage2.Location = New System.Drawing.Point(4, 22)<br />
Me.TabPage2.Name = "TabPage2"<br />
Me.TabPage2.Size = New System.Drawing.Size(232, 182)<br />
Me.TabPage2.TabIndex = 1<br />
Me.TabPage2.Text = "B"<br />
"<br />
"TabPage3<br />
"<br />
Me.TabPage3.Location = New System.Drawing.Point(4, 40)<br />
Me.TabPage3.Name = "TabPage3"<br />
Me.TabPage3.Size = New System.Drawing.Size(200, 164)<br />
Me.TabPage3.TabIndex = 2<br />
Me.TabPage3.Text = "C"<br />
"<br />
"TabPage4<br />
"<br />
Me.TabPage4.Location = New System.Drawing.Point(4, 40)<br />
Me.TabPage4.Name = "TabPage4"<br />
Me.TabPage4.Size = New System.Drawing.Size(232, 164)<br />
Me.TabPage4.TabIndex = 3<br />
Me.TabPage4.Text = "D"<br />
"<br />
"TabPage5<br />
"<br />
Me.TabPage5.Location = New System.Drawing.Point(4, 40)<br />
Me.TabPage5.Name = "TabPage5"<br />
Me.TabPage5.Size = New System.Drawing.Size(232, 164)<br />
Me.TabPage5.TabIndex = 4<br />
Me.TabPage5.Text = "E"<br />
"<br />
"TabPage6<br />
"<br />
Me.TabPage6.Location = New System.Drawing.Point(4, 40)<br />
Me.TabPage6.Name = "TabPage6"<br />
Me.TabPage6.Size = New System.Drawing.Size(200, 164)<br />
Me.TabPage6.TabIndex = 5<br />
Me.TabPage6.Text = "F"<br />
"<br />
"ListBox1<br />
"<br />
Me.ListBox1.Items.AddRange(New Object() {"A", "B", "C"})<br />
Me.ListBox1.Location = New System.Drawing.Point(16, 16)<br />
Me.ListBox1.Name = "ListBox1"<br />
Me.ListBox1.Size = New System.Drawing.Size(88, 108)<br />
Me.ListBox1.TabIndex = 0<br />
"<br />
"Button1<br />
"<br />
Me.Button1.Location = New System.Drawing.Point(120, 32)<br />
Me.Button1.Name = "Button1"<br />
Me.Button1.Size = New System.Drawing.Size(56, 24)<br />
Me.Button1.TabIndex = 1<br />
Me.Button1.Text = "Add"<br />
"<br />
"Button2<br />
"<br />
Me.Button2.Location = New System.Drawing.Point(120, 88)<br />
Me.Button2.Name = "Button2"<br />
Me.Button2.Size = New System.Drawing.Size(56, 24)<br />
Me.Button2.TabIndex = 2<br />
Me.Button2.Text = "Delete"<br />
"<br />
"Form1<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(292, 266)<br />
Me.Controls.Add(Me.TabControl1)<br />
Me.TabControl1.ResumeLayout(False)<br />
Me.TabPage1.ResumeLayout(False)<br />
Me.ResumeLayout(False)<br />
End Sub<br />
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
ListBox1.Items.Add("str")<br />
End Sub<br />
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click<br />
ListBox1.Items.Remove(ListBox1.SelectedItem)<br />
End Sub<br />
End Class</source><br />
<br />
==TabControl and TabPages==<br />
<br />
<br />
<br />
<source lang="vbnet">imports System<br />
imports System.Drawing<br />
imports System.Windows.Forms<br />
<br />
public class TabControls : inherits Form<br />
public sub New()<br />
Size = new Size(325,375)<br />
dim tc as new TabControl()<br />
tc.Parent = me<br />
tc.Size = new Size(275,300)<br />
tc.Location = new Point(25,25)<br />
tc.Anchor = AnchorStyles.Top or AnchorStyles.Bottom or AnchorStyles.Left or AnchorStyles.Right<br />
tc.Alignment = TabAlignment.Top<br />
tc.Appearance = TabAppearance.Normal<br />
tc.HotTrack = true<br />
tc.Multiline = true<br />
tc.Padding = new Point(20,3)<br />
tc.SizeMode = TabSizeMode.FillToRight<br />
AddHandler tc.SelectedIndexChanged, AddressOf tc_Changed<br />
tc.Text = "Some text"<br />
dim img as Image = Image.FromFile("1.ico")<br />
dim imgList as new ImageList()<br />
imgList.Images.Add(img)<br />
tc.ImageList = imgList<br />
dim tpAddress as new TabPage()<br />
tpAddress.Parent = tc<br />
tpAddress.Text = "Address Book"<br />
dim tpDates as new TabPage()<br />
tpDates.Parent = tc<br />
tpDates.Text = "Date Book"<br />
dim tpToDo as new TabPage()<br />
tpToDo.Parent = tc<br />
tpToDo.Text = "ToDo List"<br />
dim tpMisc as new TabPage()<br />
tpMisc.Parent = tc<br />
tpMisc.Text = "A Really Long Tab"<br />
tpMisc.ImageIndex = 0<br />
dim lbl as new Label()<br />
lbl.Parent = tpAddress<br />
lbl.Text = "Put the Address book controls on this page."<br />
lbl.AutoSize = true<br />
lbl.Location = new Point(10,25)<br />
dim pnl as new Panel()<br />
pnl.Parent = tpDates<br />
pnl.BorderStyle = BorderStyle.Fixed3D<br />
pnl.Location = new Point(10,10)<br />
pnl.Anchor = AnchorStyles.Top or AnchorStyles.Bottom or _<br />
AnchorStyles.Left or AnchorStyles.Right<br />
pnl.Size = new Size(tpDates.Width - 20, tpDates.Height - 20)<br />
dim cal as new MonthCalendar()<br />
cal.Parent = pnl<br />
cal.Location = new Point(25,25)<br />
dim rtxt as new RichTextBox()<br />
rtxt.Parent = tpToDo<br />
rtxt.Dock = DockStyle.Fill<br />
rtxt.BorderStyle = BorderStyle.FixedSingle<br />
end sub<br />
public shared sub Main() <br />
Application.Run(new TabControls())<br />
end sub<br />
private sub tc_Changed(ByVal sender as object,ByVal e as EventArgs)<br />
dim tc as TabControl = CType(sender,TabControl)<br />
Console.WriteLine("Button " + tc.SelectedIndex.ToString())<br />
end sub<br />
end class</source><br />
<br />
==Using TabControl to display various font settings==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Windows.Forms<br />
Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
public class FormTabControl<br />
public Shared Sub Main<br />
Application.Run(New FrmTabs)<br />
End Sub<br />
End class<br />
<br />
Public Class FrmTabs<br />
Inherits Form<br />
#Region " Windows Form Designer generated code "<br />
Public Sub New()<br />
MyBase.New()<br />
"This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
"Add any initialization after the InitializeComponent() call<br />
End Sub<br />
"Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
" output label reflects text changes<br />
Friend WithEvents lblDisplay As Label<br />
" table control containing table pages tbpColor,<br />
" tbpSize, tbpMessage and tbpAbout<br />
Friend WithEvents tbcTextOptions As TabControl<br />
" table page containing color options<br />
Friend WithEvents tbpColor As TabPage<br />
Friend WithEvents radBlack As RadioButton<br />
Friend WithEvents radRed As RadioButton<br />
Friend WithEvents radGreen As RadioButton<br />
" table page containing font size options<br />
Friend WithEvents tbpSize As TabPage<br />
Friend WithEvents radSize12 As RadioButton<br />
Friend WithEvents radSize16 As RadioButton<br />
Friend WithEvents radSize20 As RadioButton<br />
" table page containing text display options<br />
Friend WithEvents tbpMessage As TabPage<br />
Friend WithEvents radHello As RadioButton<br />
Friend WithEvents radGoodbye As RadioButton<br />
" table page containing about message<br />
Friend WithEvents tbpAbout As TabPage<br />
Friend WithEvents lblMessage As Label<br />
"Required by the Windows Form Designer<br />
Private components As System.ruponentModel.Container<br />
"NOTE: The following procedure is required by the Windows Form Designer<br />
"It can be modified using the Windows Form Designer. <br />
"Do not modify it using the code editor.<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me.radSize12 = New System.Windows.Forms.RadioButton()<br />
Me.radSize20 = New System.Windows.Forms.RadioButton()<br />
Me.radHello = New System.Windows.Forms.RadioButton()<br />
Me.lblDisplay = New System.Windows.Forms.Label()<br />
Me.tbpMessage = New System.Windows.Forms.TabPage()<br />
Me.radGoodbye = New System.Windows.Forms.RadioButton()<br />
Me.tbpAbout = New System.Windows.Forms.TabPage()<br />
Me.lblMessage = New System.Windows.Forms.Label()<br />
Me.radSize16 = New System.Windows.Forms.RadioButton()<br />
Me.tbpColor = New System.Windows.Forms.TabPage()<br />
Me.radGreen = New System.Windows.Forms.RadioButton()<br />
Me.radRed = New System.Windows.Forms.RadioButton()<br />
Me.radBlack = New System.Windows.Forms.RadioButton()<br />
Me.tbcTextOptions = New System.Windows.Forms.TabControl()<br />
Me.tbpSize = New System.Windows.Forms.TabPage()<br />
Me.tbpMessage.SuspendLayout()<br />
Me.tbpAbout.SuspendLayout()<br />
Me.tbpColor.SuspendLayout()<br />
Me.tbcTextOptions.SuspendLayout()<br />
Me.tbpSize.SuspendLayout()<br />
Me.SuspendLayout()<br />
"<br />
"radSize12<br />
"<br />
Me.radSize12.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.radSize12.Location = New System.Drawing.Point(16, 24)<br />
Me.radSize12.Name = "radSize12"<br />
Me.radSize12.TabIndex = 0<br />
Me.radSize12.Text = "12 point"<br />
"<br />
"radSize20<br />
"<br />
Me.radSize20.Location = New System.Drawing.Point(16, 104)<br />
Me.radSize20.Name = "radSize20"<br />
Me.radSize20.TabIndex = 2<br />
Me.radSize20.Text = "20 point"<br />
"<br />
"radHello<br />
"<br />
Me.radHello.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.radHello.Location = New System.Drawing.Point(16, 24)<br />
Me.radHello.Name = "radHello"<br />
Me.radHello.TabIndex = 0<br />
Me.radHello.Text = "Hello!"<br />
"<br />
"lblDisplay<br />
"<br />
Me.lblDisplay.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.lblDisplay.Location = New System.Drawing.Point(16, 184)<br />
Me.lblDisplay.Name = "lblDisplay"<br />
Me.lblDisplay.Size = New System.Drawing.Size(272, 40)<br />
Me.lblDisplay.TabIndex = 1<br />
Me.lblDisplay.Text = "Hello!"<br />
Me.lblDisplay.TextAlign = System.Drawing.ContentAlignment.MiddleCenter<br />
"<br />
"tbpMessage<br />
"<br />
Me.tbpMessage.Controls.AddRange(New System.Windows.Forms.Control() {Me.radGoodbye, Me.radHello})<br />
Me.tbpMessage.Location = New System.Drawing.Point(4, 22)<br />
Me.tbpMessage.Name = "tbpMessage"<br />
Me.tbpMessage.TabIndex = 2<br />
Me.tbpMessage.Text = "Message"<br />
"<br />
"radGoodbye<br />
"<br />
Me.radGoodbye.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.radGoodbye.Location = New System.Drawing.Point(16, 64)<br />
Me.radGoodbye.Name = "radGoodbye"<br />
Me.radGoodbye.TabIndex = 1<br />
Me.radGoodbye.Text = "Goodbye!"<br />
"<br />
"tbpAbout<br />
"<br />
Me.tbpAbout.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblMessage})<br />
Me.tbpAbout.Location = New System.Drawing.Point(4, 22)<br />
Me.tbpAbout.Name = "tbpAbout"<br />
Me.tbpAbout.TabIndex = 3<br />
Me.tbpAbout.Text = "About"<br />
"<br />
"lblMessage<br />
"<br />
Me.lblMessage.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.lblMessage.Location = New System.Drawing.Point(16, 16)<br />
Me.lblMessage.Name = "lblMessage"<br />
Me.lblMessage.Size = New System.Drawing.Size(248, 104)<br />
Me.lblMessage.TabIndex = 0<br />
Me.lblMessage.Text = "Tabs are used to organize controls and conserve screen space."<br />
"<br />
"radSize16<br />
"<br />
Me.radSize16.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.radSize16.Location = New System.Drawing.Point(16, 64)<br />
Me.radSize16.Name = "radSize16"<br />
Me.radSize16.TabIndex = 1<br />
Me.radSize16.Text = "16 point"<br />
"<br />
"tbpColor<br />
"<br />
Me.tbpColor.Controls.AddRange(New System.Windows.Forms.Control() {Me.radGreen, Me.radRed, Me.radBlack})<br />
Me.tbpColor.Location = New System.Drawing.Point(4, 22)<br />
Me.tbpColor.Name = "tbpColor"<br />
Me.tbpColor.TabIndex = 0<br />
Me.tbpColor.Text = "Color"<br />
"<br />
"radGreen<br />
"<br />
Me.radGreen.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.radGreen.Location = New System.Drawing.Point(16, 104)<br />
Me.radGreen.Name = "radGreen"<br />
Me.radGreen.TabIndex = 2<br />
Me.radGreen.Text = "Green"<br />
"<br />
"radRed<br />
"<br />
Me.radRed.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.radRed.Location = New System.Drawing.Point(16, 64)<br />
Me.radRed.Name = "radRed"<br />
Me.radRed.TabIndex = 1<br />
Me.radRed.Text = "Red"<br />
"<br />
"radBlack<br />
"<br />
Me.radBlack.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))<br />
Me.radBlack.Location = New System.Drawing.Point(16, 24)<br />
Me.radBlack.Name = "radBlack"<br />
Me.radBlack.TabIndex = 0<br />
Me.radBlack.Text = "Black"<br />
"<br />
"tbcTextOptions<br />
"<br />
Me.tbcTextOptions.Controls.AddRange(New System.Windows.Forms.Control() {Me.tbpColor, Me.tbpSize, Me.tbpMessage, Me.tbpAbout})<br />
Me.tbcTextOptions.Location = New System.Drawing.Point(8, 8)<br />
Me.tbcTextOptions.Name = "tbcTextOptions"<br />
Me.tbcTextOptions.SelectedIndex = 0<br />
Me.tbcTextOptions.Size = New System.Drawing.Size(280, 168)<br />
Me.tbcTextOptions.TabIndex = 0<br />
"<br />
"tbpSize<br />
"<br />
Me.tbpSize.Controls.AddRange(New System.Windows.Forms.Control() {Me.radSize20, Me.radSize16, Me.radSize12})<br />
Me.tbpSize.Location = New System.Drawing.Point(4, 22)<br />
Me.tbpSize.Name = "tbpSize"<br />
Me.tbpSize.TabIndex = 1<br />
Me.tbpSize.Text = "Size"<br />
"<br />
"FrmTabs<br />
"<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(292, 229)<br />
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblDisplay, Me.tbcTextOptions})<br />
Me.Name = "FrmTabs"<br />
Me.Text = "Using Tabs"<br />
Me.tbpMessage.ResumeLayout(False)<br />
Me.tbpAbout.ResumeLayout(False)<br />
Me.tbpColor.ResumeLayout(False)<br />
Me.tbcTextOptions.ResumeLayout(False)<br />
Me.tbpSize.ResumeLayout(False)<br />
Me.ResumeLayout(False)<br />
End Sub<br />
#End Region<br />
" event handler for black color radio button<br />
Private Sub radBlack_CheckedChanged _<br />
(ByVal sender As System.Object, ByVal e As System.EventArgs) _<br />
Handles radBlack.CheckedChanged<br />
lblDisplay.ForeColor = Color.Black<br />
End Sub <br />
<br />
Private Sub radRed_CheckedChanged _<br />
(ByVal sender As System.Object, ByVal e As System.EventArgs) _<br />
Handles radRed.CheckedChanged<br />
lblDisplay.ForeColor = Color.Red<br />
End Sub <br />
<br />
Private Sub radGreen_CheckedChanged _<br />
(ByVal sender As System.Object, ByVal e As System.EventArgs) _<br />
Handles radGreen.CheckedChanged<br />
lblDisplay.ForeColor = Color.Green<br />
End Sub <br />
<br />
Private Sub radSize12_CheckedChanged( _<br />
ByVal sender As System.Object, ByVal e As System.EventArgs) _<br />
Handles radSize12.CheckedChanged<br />
lblDisplay.Font = New Font("Microsoft Sans Serif", 12)<br />
End Sub <br />
Private Sub radSize16_CheckedChanged _<br />
(ByVal sender As System.Object, ByVal e As System.EventArgs) _<br />
Handles radSize16.CheckedChanged<br />
lblDisplay.Font = New Font("Microsoft Sans Serif", 16)<br />
End Sub <br />
Private Sub radSize20_CheckedChanged _<br />
(ByVal sender As System.Object, ByVal e As System.EventArgs) _<br />
Handles radSize20.CheckedChanged<br />
lblDisplay.Font = New Font("Microsoft Sans Serif", 20)<br />
End Sub <br />
Private Sub radHello_CheckedChanged _<br />
(ByVal sender As System.Object, ByVal e As System.EventArgs) _<br />
Handles radHello.CheckedChanged<br />
lblDisplay.Text = "Microsoft Sans Serif"<br />
End Sub<br />
<br />
Private Sub radGoodbye_CheckedChanged _<br />
(ByVal sender As System.Object, ByVal e As System.EventArgs) _<br />
Handles radGoodbye.CheckedChanged<br />
lblDisplay.Text = "Font Size 20"<br />
End Sub <br />
End Class</source></div>
Admin
http://vbex.ru/index.php?title=VB.Net_Tutorial/GUI/InputBox&diff=3863
VB.Net Tutorial/GUI/InputBox
2010-05-26T12:57:12Z
<p>Admin: 1 версия</p>
<hr />
<div>==Get input from InputBox==<br />
<br />
<br />
<br />
<source lang="vbnet">Imports System.Drawing<br />
Imports System.Drawing.Drawing2D<br />
Imports System.Windows.Forms<br />
public class PasswordFieldMatch<br />
public Shared Sub Main<br />
Dim Filename As String<br />
Filename = InputBox("Your Value", "Title", "c:\document")<br />
End Sub<br />
End class</source><br />
<br />
==InputBox Demo==<br />
<br />
<br />
<br />
<source lang="vbnet">public class InputBoxDemo<br />
public Shared Sub Main<br />
Dim PASSWORD As String<br />
PASSWORD = InputBox("Password", "Password Dialog")<br />
Do While PASSWORD <> "12345"<br />
PASSWORD = InputBox("Password", "Password Dialog")<br />
Loop<br />
End Sub<br />
End class</source><br />
<br />
==Read Integer value from Keyboard==<br />
<br />
<br />
<br />
<source lang="vbnet">Module Module1<br />
Sub Main()<br />
Dim Age As Integer<br />
Console.Write("Age: ")<br />
Age = Console.ReadLine()<br />
Console.WriteLine(Age)<br />
End Sub<br />
End Module</source><br />
<pre class=codeResult>Age: 12<br />
12</pre><br />
<br />
==Use InputBox to read Double value==<br />
<br />
<br />
<br />
<source lang="vbnet">Module Module1<br />
Sub Main()<br />
Dim Salary As Double<br />
Salary = InputBox("Enter salary")<br />
Console.WriteLine(Salary)<br />
End Sub<br />
End Module</source><br />
<br />
==Use InputBox to read Integer value==<br />
<br />
<br />
<br />
<source lang="vbnet">Module Module1<br />
Sub Main()<br />
Dim Age As Integer<br />
Age = InputBox("Enter age", 21)<br />
Console.WriteLine(Age)<br />
End Sub<br />
End Module</source><br />
<br />
==Use InputBox to read string value==<br />
<br />
<br />
<br />
<source lang="vbnet">Module Module1<br />
Sub Main()<br />
Dim Name As String<br />
Name = InputBox("Enter name")<br />
Console.WriteLine(Name)<br />
End Sub<br />
End Module</source><br />
<pre class=codeResult>asdf</pre></div>
Admin