VB.Net by API/System.Windows.Forms/TextBox — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 12:52, 26 мая 2010
Содержание
- 1 Inherits TextBox
- 2 TextBox.AppendText
- 3 TextBox.BorderStyle
- 4 TextBox.Copy()
- 5 TextBox.DataBindings.Add
- 6 TextBox.DoDragDrop
- 7 TextBox.Enter
- 8 TextBox.Font
- 9 TextBox.KeyPress
- 10 TextBox.Modified
- 11 TextBox.Multiline
- 12 TextBox.PasswordChar
- 13 TextBox.Paste()
- 14 TextBox.ScrollBars
- 15 TextBox.SelectedText
- 16 TextBox.SelectionLength
- 17 TextBox.TextChanged
- 18 TextBox.Validating
Inherits TextBox
Imports System
Imports System.Runtime.InteropServices
Imports System.Drawing
Imports System.ruponentModel
Imports System.Windows.Forms
Imports System.IO
Public Class MainClass
Shared Sub Main(ByVal args As String())
Dim myform As Form = New Form1()
Application.Run(myform)
End Sub
End Class
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim text_box As New NoContextMenuTextBox
text_box.Location = New Point(TextBox1.Left, TextBox1.Top + TextBox1.Height + 4)
text_box.Size = TextBox1.Size
Me.Controls.Add(text_box)
End Sub
End Class
Public Class NoContextMenuTextBox
Inherits System.Windows.Forms.TextBox
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Const WM_CONTEXTMENU As Integer = &H7B
If m.Msg <> WM_CONTEXTMENU Then
MyBase.WndProc(m)
End If
End Sub
End Class
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Public Class Form1
Inherits System.Windows.Forms.Form
"Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
"
"TextBox1
"
Me.TextBox1.Location = New System.Drawing.Point(16, 16)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(120, 20)
Me.TextBox1.TabIndex = 0
"
"Form1
"
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(156, 102)
Me.Controls.Add(Me.TextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
End Class
TextBox.AppendText
Imports System.Windows.Forms
Module Module1
Sub Main()
Application.Run(New Form1)
End Sub
End Module
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
"This call is required by the Windows Form Designer.
InitializeComponent()
"Add any initialization after the InitializeComponent() call
End Sub
"Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents DateTimePicker1 As System.Windows.Forms.DateTimePicker
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.DateTimePicker1 = New System.Windows.Forms.DateTimePicker()
Me.Button1 = New System.Windows.Forms.Button()
Me.SuspendLayout()
"
"TextBox1
"
Me.TextBox1.Location = New System.Drawing.Point(32, 40)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(408, 208)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = ""
"
"DateTimePicker1
"
Me.DateTimePicker1.Location = New System.Drawing.Point(128, 264)
Me.DateTimePicker1.Name = "DateTimePicker1"
Me.DateTimePicker1.TabIndex = 1
"
"Button1
"
Me.Button1.Location = New System.Drawing.Point(168, 312)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(112, 23)
Me.Button1.TabIndex = 2
Me.Button1.Text = "Get Time"
"
"Form1
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(472, 349)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1, Me.DateTimePicker1, Me.TextBox1})
Me.Name = "Form1"
Me.Text = "FilesSince"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.AppendText(DateTimePicker1.Value.ToString & " ")
End Sub
End Class
TextBox.BorderStyle
imports System
imports System.Drawing
imports System.Windows.Forms
public class TextBoxTextChanged : inherits Form
dim txt as TextBox
dim btn as Button
dim strOriginal as string
public sub New()
Text = "TextBox Modified and TextChanged"
Size = new Size(300, 375)
txt = new TextBox()
txt.Parent = me
txt.Text = "Enter text here."
txt.Size = new Size(280, 275)
txt.Location = new Point(10,10)
AddHandler txt.TextChanged, AddressOf txt_TextChanged
txt.Multiline = true
txt.BorderStyle = BorderStyle.Fixed3D
txt.ScrollBars = ScrollBars.Vertical
txt.Anchor = AnchorStyles.Left or AnchorStyles.Right or AnchorStyles.Top or AnchorStyles.Bottom
strOriginal = txt.Text
btn = new Button()
btn.Parent = me
btn.Text = "Check "
btn.Location = new Point(20,320)
AddHandler btn.Click, AddressOf btn_Click
btn.Anchor = AnchorStyles.Bottom
end sub
public shared sub Main()
Application.Run(new TextBoxTextChanged())
end sub
private sub txt_TextChanged(ByVal sender as object,ByVal e as EventArgs)
Console.WriteLine("txt_TextChanged")
if strOriginal = txt.Text then
txt.Modified = false
else
txt.Modified = true
end if
end sub
private sub btn_Click(ByVal sender as object,ByVal e as EventArgs)
if txt.Modified then
Console.WriteLine("modified.")
strOriginal = txt.Text
txt.Modified = false
else
Console.WriteLine("not been modified." )
end if
end sub
end class
TextBox.Copy()
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class TextBoxCopyPaste
public Shared Sub Main
Application.Run(New Form1)
End Sub
End class
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
"This call is required by the Windows Form Designer.
InitializeComponent()
"Add any initialization after the InitializeComponent() call
End Sub
"Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
"
"TextBox1
"
Me.TextBox1.Location = New System.Drawing.Point(128, 72)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(112, 20)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = ""
"
"Button1
"
Me.Button1.Location = New System.Drawing.Point(128, 120)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(112, 23)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Copy Selected Text"
"
"Label1
"
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 24.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(0, 0)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(344, 48)
Me.Label1.TabIndex = 2
Me.Label1.Text = "Copying Selected Text"
"
"TextBox2
"
Me.TextBox2.Location = New System.Drawing.Point(128, 168)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(112, 20)
Me.TextBox2.TabIndex = 3
Me.TextBox2.Text = ""
"
"Form1
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(360, 253)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Copy()
TextBox2.Paste()
End Sub
End Class
TextBox.DataBindings.Add
Public Class Form2
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
"This call is required by the Windows Form Designer.
InitializeComponent()
"Add any initialization after the InitializeComponent() call
End Sub
"Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
"Required by the Windows Form Designer
Private components As System.ruponentModel.Container
Private WithEvents textBox1 As System.Windows.Forms.TextBox
Private WithEvents button1 As System.Windows.Forms.Button
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.textBox1 = New System.Windows.Forms.TextBox()
Me.button1 = New System.Windows.Forms.Button()
Me.SuspendLayout()
"
"textBox1
"
Me.textBox1.Location = New System.Drawing.Point(48, 56)
Me.textBox1.Name = "textBox1"
Me.textBox1.TabIndex = 0
Me.textBox1.Text = "textBox1"
"
"button1
"
Me.button1.Location = New System.Drawing.Point(56, 96)
Me.button1.Name = "button1"
Me.button1.TabIndex = 1
Me.button1.Text = "button1"
"
"Form2
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.button1, Me.textBox1})
Me.Name = "Form2"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.Click
Dim sConnection As String = _
"Provider=SQLOLEDB.1;" & _
"Password=sqlpassword;" & _
"Persist Security Info=True;" & _
"User ID=sa;" & _
"Initial Catalog=CD;" & _
"Data Source=(local)"
Dim sSQL As String
sSQL = "SELECT ArtistID, ArtistName From Artist"
Dim objConn _
As New OleDb.OleDbConnection(sConnection)
Dim objDataAdapter _
As New OleDb.OleDbDataAdapter(sSQL, objConn)
Dim objDS _
As New DataSet("Artists")
Dim objDV _
As DataView
Try
objConn.Open()
Catch myException As System.Exception
Windows.Forms.MessageBox.Show(myException.Message)
End Try
If objConn.State = ConnectionState.Open Then
Try
objDataAdapter.Fill(objDS, "Disc")
objConn.Close()
Dim objTable As DataTable
objTable = objDS.Tables("Disc")
objDV = objTable.DefaultView
textBox1.DataBindings.Add("Text", objDV, "ArtistName")
Catch myexception As Exception
Windows.Forms.MessageBox.Show(myException.Message)
End Try
End If
End Sub
End Class
TextBox.DoDragDrop
Imports System
Imports System.Drawing
Imports System.Reflection
Imports System.Windows.Forms
public class MainClass
Shared Sub Main()
Dim form1 As Form = New Form1
Application.Run(form1)
End Sub
End Class
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
"This call is required by the Windows Form Designer.
InitializeComponent()
"Add any initialization after the InitializeComponent() call
End Sub
"Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
Friend WithEvents TreeView1 As System.Windows.Forms.TreeView
Friend WithEvents DestinationTextBox As System.Windows.Forms.TextBox
Friend WithEvents SourceTextBox As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.DestinationTextBox = New System.Windows.Forms.TextBox()
Me.SourceTextBox = New System.Windows.Forms.TextBox()
Me.ListBox1 = New System.Windows.Forms.ListBox()
Me.TreeView1 = New System.Windows.Forms.TreeView()
Me.SuspendLayout()
"
"DestinationTextBox
"
Me.DestinationTextBox.AllowDrop = True
Me.DestinationTextBox.Font = New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.DestinationTextBox.Location = New System.Drawing.Point(4, 166)
Me.DestinationTextBox.Multiline = True
Me.DestinationTextBox.Name = "DestinationTextBox"
Me.DestinationTextBox.Size = New System.Drawing.Size(354, 195)
Me.DestinationTextBox.TabIndex = 1
Me.DestinationTextBox.Text = ""
"
"SourceTextBox
"
Me.SourceTextBox.Font = New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.SourceTextBox.Location = New System.Drawing.Point(4, 4)
Me.SourceTextBox.Multiline = True
Me.SourceTextBox.Name = "SourceTextBox"
Me.SourceTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.SourceTextBox.Size = New System.Drawing.Size(354, 144)
Me.SourceTextBox.TabIndex = 2
Me.SourceTextBox.Text = "Use your right or left key to drag and drop item in left ListBox or Tree to the bottom TextBox."
"
"ListBox1
"
Me.ListBox1.Font = New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.ListBox1.ItemHeight = 14
Me.ListBox1.Items.AddRange(New Object() {"Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10", "Item 11", "Item 12", "Item 13", "Item 14", "Item 15"})
Me.ListBox1.Location = New System.Drawing.Point(370, 4)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended
Me.ListBox1.Size = New System.Drawing.Size(190, 144)
Me.ListBox1.TabIndex = 3
"
"TreeView1
"
Me.TreeView1.Font = New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.TreeView1.ImageIndex = -1
Me.TreeView1.Location = New System.Drawing.Point(370, 166)
Me.TreeView1.Name = "TreeView1"
Me.TreeView1.Nodes.AddRange(New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node0", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node1"), New System.Windows.Forms.TreeNode("Node12", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node13")}), New System.Windows.Forms.TreeNode("Node14"), New System.Windows.Forms.TreeNode("Node15", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node16"), New System.Windows.Forms.TreeNode("Node17")})}), New System.Windows.Forms.TreeNode("Node2", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node3", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node4"), New System.Windows.Forms.TreeNode("Node5"), New System.Windows.Forms.TreeNode("Node6")}), New System.Windows.Forms.TreeNode("Node7"), New System.Windows.Forms.TreeNode("Node8", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node10"), New System.Windows.Forms.TreeNode("Node11")}), New System.Windows.Forms.TreeNode("Node9")})})
Me.TreeView1.SelectedImageIndex = -1
Me.TreeView1.Size = New System.Drawing.Size(187, 195)
Me.TreeView1.TabIndex = 4
"
"Form1
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.AutoScroll = True
Me.ClientSize = New System.Drawing.Size(564, 367)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TreeView1, Me.ListBox1, Me.SourceTextBox, Me.DestinationTextBox})
Me.Name = "Form1"
Me.Text = "Drag and Drop Demo"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Destination_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DestinationTextBox.DragDrop
DestinationTextBox.Text = e.Data.GetData(DataFormats.Text).ToString
DestinationTextBox.BackColor = Color.White
End Sub
Private Sub Destination_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DestinationTextBox.DragEnter
DestinationTextBox.BackColor = Color.Yellow
e.Effect = DragDropEffects.Copy
End Sub
Private Sub SourceTextBox_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles SourceTextBox.MouseDown
SourceTextBox.DoDragDrop(SourceTextBox.SelectedText, DragDropEffects.Copy Or DragDropEffects.Move)
End Sub
Private Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown
Dim i As Integer, selItems As String
For i = 0 To ListBox1.SelectedItems.Count - 1
selItems = selItems & ListBox1.SelectedItems.Item(i) & vbCrLf
Next
SourceTextBox.DoDragDrop(selItems, DragDropEffects.Copy Or DragDropEffects.Move)
End Sub
Private Sub Destination_DragLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DestinationTextBox.DragLeave
DestinationTextBox.BackColor = Color.White
End Sub
Private Sub TreeView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeView1.MouseDown
If e.Button = MouseButtons.Right Then
TreeView1.DoDragDrop(TreeView1.SelectedNode.Text, DragDropEffects.Copy Or DragDropEffects.Move)
End If
End Sub
End Class
TextBox.Enter
Imports System.Windows.Forms
public class HandleMultipleEventsFromDifferentControls
public Shared Sub Main
Application.Run(New Form1)
End Sub
End class
Public Class Form1
Private Sub MultipleEvents(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles _
TextBox1.Enter, TextBox2.Enter, TextBox3.Enter, _
TextBox1.TextChanged, TextBox2.TextChanged, TextBox3.TextChanged
Dim activeControl As TextBox
activeControl = CType(sender, TextBox)
ShowInfo.Text = "TextField #" & _
activeControl.Name & _
", " & activeControl.Text.Length & " character(s)"
End Sub
End Class
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
"Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Label3 = New System.Windows.Forms.Label
Me.TextBox3 = New System.Windows.Forms.TextBox
Me.Label4 = New System.Windows.Forms.Label
Me.ShowInfo = New System.Windows.Forms.Label
Me.SuspendLayout()
"
"TextBox1
"
Me.TextBox1.Location = New System.Drawing.Point(120, 8)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(160, 20)
Me.TextBox1.TabIndex = 1
"
"Label1
"
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(8, 10)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(93, 13)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Text Box Field #1:"
"
"Label2
"
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(8, 42)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(93, 13)
Me.Label2.TabIndex = 2
Me.Label2.Text = "Text Box Field #2:"
"
"TextBox2
"
Me.TextBox2.Location = New System.Drawing.Point(120, 40)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(160, 20)
Me.TextBox2.TabIndex = 3
"
"Label3
"
Me.Label3.AutoSize = True
Me.Label3.Location = New System.Drawing.Point(9, 72)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(93, 13)
Me.Label3.TabIndex = 4
Me.Label3.Text = "Text Box Field #3:"
"
"TextBox3
"
Me.TextBox3.Location = New System.Drawing.Point(121, 70)
Me.TextBox3.Name = "TextBox3"
Me.TextBox3.Size = New System.Drawing.Size(159, 20)
Me.TextBox3.TabIndex = 5
"
"Label4
"
Me.Label4.AutoSize = True
Me.Label4.Location = New System.Drawing.Point(8, 104)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(62, 13)
Me.Label4.TabIndex = 6
Me.Label4.Text = "Information:"
"
"ShowInfo
"
Me.ShowInfo.AutoSize = True
Me.ShowInfo.Location = New System.Drawing.Point(120, 104)
Me.ShowInfo.Name = "ShowInfo"
Me.ShowInfo.Size = New System.Drawing.Size(27, 13)
Me.ShowInfo.TabIndex = 7
Me.ShowInfo.Text = "N/A"
"
"Form1
"
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(320, 136)
Me.Controls.Add(Me.ShowInfo)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.TextBox3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.TextBox1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.MaximizeBox = False
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Sharing Control Logic"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents ShowInfo As System.Windows.Forms.Label
End Class
TextBox.Font
Imports System.Windows.Forms
public class RadioButtonControlFont
public Shared Sub Main
Application.Run(New Form1)
End Sub
End class
Public Class Form1
Public mysize As Integer
Public mybold As Boolean
Public myItalic As Boolean
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
CheckBox1.Checked = 1
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
myItalic = Not myItalic
TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Regular)
If myItalic And mybold Then
TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Italic)
ElseIf myItalic Then
TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Italic)
ElseIf mybold Then
TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Bold)
End If
End Sub
Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
mybold = False
myItalic = False
mysize = 25
End Sub
Private Sub RadioButton1_CheckedChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
mysize = 36
TextBox1.Font = New System.Drawing.Font("", mysize)
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
mysize = 25
TextBox1.Font = New System.Drawing.Font("", mysize)
End Sub
Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
mybold = Not mybold
TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Regular)
If myItalic And mybold Then
TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Bold)
ElseIf myItalic Then
TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Italic)
ElseIf mybold Then
TextBox1.Font = New System.Drawing.Font("", mysize, Drawing.FontStyle.Bold)
End If
End Sub
End Class
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
"Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.CheckBox1 = New System.Windows.Forms.CheckBox
Me.CheckBox2 = New System.Windows.Forms.CheckBox
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.RadioButton1 = New System.Windows.Forms.RadioButton
Me.RadioButton2 = New System.Windows.Forms.RadioButton
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
"
"CheckBox1
"
Me.CheckBox1.AutoSize = True
Me.CheckBox1.Location = New System.Drawing.Point(230, 34)
Me.CheckBox1.Name = "CheckBox1"
Me.CheckBox1.Size = New System.Drawing.Size(48, 16)
Me.CheckBox1.TabIndex = 1
Me.CheckBox1.Text = "Italic"
Me.CheckBox1.UseVisualStyleBackColor = True
"
"CheckBox2
"
Me.CheckBox2.AutoSize = True
Me.CheckBox2.Location = New System.Drawing.Point(230, 56)
Me.CheckBox2.Name = "CheckBox2"
Me.CheckBox2.Size = New System.Drawing.Size(48, 16)
Me.CheckBox2.TabIndex = 2
Me.CheckBox2.Text = "Bold"
Me.CheckBox2.UseVisualStyleBackColor = True
"
"GroupBox1
"
Me.GroupBox1.Controls.Add(Me.RadioButton2)
Me.GroupBox1.Controls.Add(Me.RadioButton1)
Me.GroupBox1.Location = New System.Drawing.Point(224, 85)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(132, 77)
Me.GroupBox1.TabIndex = 3
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "Font size"
"
"RadioButton1
"
Me.RadioButton1.AutoSize = True
Me.RadioButton1.Location = New System.Drawing.Point(6, 20)
Me.RadioButton1.Name = "RadioButton1"
Me.RadioButton1.Size = New System.Drawing.Size(59, 16)
Me.RadioButton1.TabIndex = 1
Me.RadioButton1.TabStop = True
Me.RadioButton1.Text = "Larger font"
Me.RadioButton1.UseVisualStyleBackColor = True
"
"RadioButton2
"
Me.RadioButton2.AutoSize = True
Me.RadioButton2.Location = New System.Drawing.Point(6, 42)
Me.RadioButton2.Name = "RadioButton2"
Me.RadioButton2.Size = New System.Drawing.Size(59, 16)
Me.RadioButton2.TabIndex = 2
Me.RadioButton2.TabStop = True
Me.RadioButton2.Text = "Smaller font"
Me.RadioButton2.UseVisualStyleBackColor = True
"
"TextBox1
"
Me.TextBox1.Location = New System.Drawing.Point(12, 12)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(195, 150)
Me.TextBox1.TabIndex = 4
Me.TextBox1.Text = "www.vbex.ru"
"
"Form1
"
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(368, 174)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.GroupBox1)
Me.Controls.Add(Me.CheckBox2)
Me.Controls.Add(Me.CheckBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox1.PerformLayout()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox
Friend WithEvents CheckBox2 As System.Windows.Forms.CheckBox
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton
Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
End Class
TextBox.KeyPress
Imports System
Imports System.Collections
Imports System.Data
Imports System.IO
Imports System.Xml.Serialization
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Drawing.Printing
Public Class MainClass
Shared Sub Main()
Dim form1 As Form = New Form1()
Application.Run(form1)
End Sub
End Class
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
"This call is required by the Windows Form Designer.
InitializeComponent()
"Add any initialization after the InitializeComponent() call
End Sub
"Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
"Required by the Windows Form Designer
Private components As System.ruponentModel.Container
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.Label1 = New System.Windows.Forms.Label()
Me.SuspendLayout()
"
"TextBox1
"
Me.TextBox1.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.TextBox1.Location = New System.Drawing.Point(48, 104)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(192, 27)
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = ""
"
"Label1
"
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(24, 24)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(232, 48)
Me.Label1.TabIndex = 2
Me.Label1.Text = "Type somthing"
"
"Form1
"
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15)
Me.ClientSize = New System.Drawing.Size(292, 268)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label1, Me.TextBox1})
Me.Name = "Form1"
Me.Text = "Key Event Examples"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyPressEventArgs) _
Handles TextBox1.KeyPress
If e.KeyChar < "0" Or e.KeyChar > "9" Then
MessageBox.Show("only digits allowed")
e.Handled = True
End If
End Sub
End Class
TextBox.Modified
imports System
imports System.Drawing
imports System.Windows.Forms
public class TextBoxTextChanged : inherits Form
dim txt as TextBox
dim btn as Button
dim strOriginal as string
public sub New()
Text = "TextBox Modified and TextChanged"
Size = new Size(300, 375)
txt = new TextBox()
txt.Parent = me
txt.Text = "Enter text here."
txt.Size = new Size(280, 275)
txt.Location = new Point(10,10)
AddHandler txt.TextChanged, AddressOf txt_TextChanged
txt.Multiline = true
txt.BorderStyle = BorderStyle.Fixed3D
txt.ScrollBars = ScrollBars.Vertical
txt.Anchor = AnchorStyles.Left or AnchorStyles.Right or AnchorStyles.Top or AnchorStyles.Bottom
strOriginal = txt.Text
btn = new Button()
btn.Parent = me
btn.Text = "Check "
btn.Location = new Point(20,320)
AddHandler btn.Click, AddressOf btn_Click
btn.Anchor = AnchorStyles.Bottom
end sub
public shared sub Main()
Application.Run(new TextBoxTextChanged())
end sub
private sub txt_TextChanged(ByVal sender as object,ByVal e as EventArgs)
Console.WriteLine("txt_TextChanged")
if strOriginal = txt.Text then
txt.Modified = false
else
txt.Modified = true
end if
end sub
private sub btn_Click(ByVal sender as object,ByVal e as EventArgs)
if txt.Modified then
Console.WriteLine("modified.")
strOriginal = txt.Text
txt.Modified = false
else
Console.WriteLine("not been modified." )
end if
end sub
end class
TextBox.Multiline
imports System
imports System.Drawing
imports System.Windows.Forms
public class TextBoxTextChanged : inherits Form
dim txt as TextBox
dim btn as Button
dim strOriginal as string
public sub New()
Text = "TextBox Modified and TextChanged"
Size = new Size(300, 375)
txt = new TextBox()
txt.Parent = me
txt.Text = "Enter text here."
txt.Size = new Size(280, 275)
txt.Location = new Point(10,10)
AddHandler txt.TextChanged, AddressOf txt_TextChanged
txt.Multiline = true
txt.BorderStyle = BorderStyle.Fixed3D
txt.ScrollBars = ScrollBars.Vertical
txt.Anchor = AnchorStyles.Left or AnchorStyles.Right or AnchorStyles.Top or AnchorStyles.Bottom
strOriginal = txt.Text
btn = new Button()
btn.Parent = me
btn.Text = "Check "
btn.Location = new Point(20,320)
AddHandler btn.Click, AddressOf btn_Click
btn.Anchor = AnchorStyles.Bottom
end sub
public shared sub Main()
Application.Run(new TextBoxTextChanged())
end sub
private sub txt_TextChanged(ByVal sender as object,ByVal e as EventArgs)
Console.WriteLine("txt_TextChanged")
if strOriginal = txt.Text then
txt.Modified = false
else
txt.Modified = true
end if
end sub
private sub btn_Click(ByVal sender as object,ByVal e as EventArgs)
if txt.Modified then
Console.WriteLine("modified.")
strOriginal = txt.Text
txt.Modified = false
else
Console.WriteLine("not been modified." )
end if
end sub
end class
TextBox.PasswordChar
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class PasswordFieldByTextBox
public Shared Sub Main
Application.Run(New Form1)
End Sub
End class
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
"This call is required by the Windows Form Designer.
InitializeComponent()
"Add any initialization after the InitializeComponent() call
End Sub
"Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.SuspendLayout()
"
"TextBox1
"
Me.TextBox1.Location = New System.Drawing.Point(96, 56)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = ""
"
"Button1
"
Me.Button1.Location = New System.Drawing.Point(104, 104)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 1
Me.Button1.Text = "Read Text"
"
"TextBox2
"
Me.TextBox2.Location = New System.Drawing.Point(96, 160)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.TabIndex = 2
Me.TextBox2.Text = ""
"
"Label1
"
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 24.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(0, 0)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(184, 40)
Me.Label1.TabIndex = 3
Me.Label1.Text = "Passwords"
"
"Form1
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox2.Text = TextBox1.Text
End Sub
End Class
TextBox.Paste()
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class TextBoxCopyPaste
public Shared Sub Main
Application.Run(New Form1)
End Sub
End class
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
"This call is required by the Windows Form Designer.
InitializeComponent()
"Add any initialization after the InitializeComponent() call
End Sub
"Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
"
"TextBox1
"
Me.TextBox1.Location = New System.Drawing.Point(128, 72)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(112, 20)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = ""
"
"Button1
"
Me.Button1.Location = New System.Drawing.Point(128, 120)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(112, 23)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Copy Selected Text"
"
"Label1
"
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 24.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(0, 0)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(344, 48)
Me.Label1.TabIndex = 2
Me.Label1.Text = "Copying Selected Text"
"
"TextBox2
"
Me.TextBox2.Location = New System.Drawing.Point(128, 168)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(112, 20)
Me.TextBox2.TabIndex = 3
Me.TextBox2.Text = ""
"
"Form1
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(360, 253)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Copy()
TextBox2.Paste()
End Sub
End Class
TextBox.ScrollBars
imports System
imports System.Drawing
imports System.Windows.Forms
public class TextBoxTextChanged : inherits Form
dim txt as TextBox
dim btn as Button
dim strOriginal as string
public sub New()
Text = "TextBox Modified and TextChanged"
Size = new Size(300, 375)
txt = new TextBox()
txt.Parent = me
txt.Text = "Enter text here."
txt.Size = new Size(280, 275)
txt.Location = new Point(10,10)
AddHandler txt.TextChanged, AddressOf txt_TextChanged
txt.Multiline = true
txt.BorderStyle = BorderStyle.Fixed3D
txt.ScrollBars = ScrollBars.Vertical
txt.Anchor = AnchorStyles.Left or AnchorStyles.Right or AnchorStyles.Top or AnchorStyles.Bottom
strOriginal = txt.Text
btn = new Button()
btn.Parent = me
btn.Text = "Check "
btn.Location = new Point(20,320)
AddHandler btn.Click, AddressOf btn_Click
btn.Anchor = AnchorStyles.Bottom
end sub
public shared sub Main()
Application.Run(new TextBoxTextChanged())
end sub
private sub txt_TextChanged(ByVal sender as object,ByVal e as EventArgs)
Console.WriteLine("txt_TextChanged")
if strOriginal = txt.Text then
txt.Modified = false
else
txt.Modified = true
end if
end sub
private sub btn_Click(ByVal sender as object,ByVal e as EventArgs)
if txt.Modified then
Console.WriteLine("modified.")
strOriginal = txt.Text
txt.Modified = false
else
Console.WriteLine("not been modified." )
end if
end sub
end class
TextBox.SelectedText
Imports System.Windows.Forms
Imports System.Drawing.Text
Imports System.Drawing
Imports System.Drawing.Drawing2D
public class TextBoxSelectionLength
public Shared Sub Main
Application.Run(New Form1)
End Sub
End class
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.SelectionLength = 0 Then
MessageBox.Show(TextBox1.Text)
Else
MessageBox.Show(TextBox1.SelectedText)
End If
End Sub
End Class
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
"Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
"
"TextBox1
"
Me.TextBox1.Location = New System.Drawing.Point(12, 12)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(410, 137)
Me.TextBox1.TabIndex = 0
"
"Button1
"
Me.Button1.Location = New System.Drawing.Point(150, 173)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(131, 23)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Display selected text"
Me.Button1.UseVisualStyleBackColor = True
"
"Form1
"
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(434, 208)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
End Class
TextBox.SelectionLength
Imports System.Windows.Forms
Imports System.Drawing.Text
Imports System.Drawing
Imports System.Drawing.Drawing2D
public class TextBoxSelectionLength
public Shared Sub Main
Application.Run(New Form1)
End Sub
End class
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.SelectionLength = 0 Then
MessageBox.Show(TextBox1.Text)
Else
MessageBox.Show(TextBox1.SelectedText)
End If
End Sub
End Class
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
"Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
"
"TextBox1
"
Me.TextBox1.Location = New System.Drawing.Point(12, 12)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(410, 137)
Me.TextBox1.TabIndex = 0
"
"Button1
"
Me.Button1.Location = New System.Drawing.Point(150, 173)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(131, 23)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Display selected text"
Me.Button1.UseVisualStyleBackColor = True
"
"Form1
"
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(434, 208)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
End Class
TextBox.TextChanged
Imports System.Windows.Forms
public class HandleMultipleEventsFromDifferentControls
public Shared Sub Main
Application.Run(New Form1)
End Sub
End class
Public Class Form1
Private Sub MultipleEvents(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles _
TextBox1.Enter, TextBox2.Enter, TextBox3.Enter, _
TextBox1.TextChanged, TextBox2.TextChanged, TextBox3.TextChanged
Dim activeControl As TextBox
activeControl = CType(sender, TextBox)
ShowInfo.Text = "TextField #" & _
activeControl.Name & _
", " & activeControl.Text.Length & " character(s)"
End Sub
End Class
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
"Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Label3 = New System.Windows.Forms.Label
Me.TextBox3 = New System.Windows.Forms.TextBox
Me.Label4 = New System.Windows.Forms.Label
Me.ShowInfo = New System.Windows.Forms.Label
Me.SuspendLayout()
"
"TextBox1
"
Me.TextBox1.Location = New System.Drawing.Point(120, 8)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(160, 20)
Me.TextBox1.TabIndex = 1
"
"Label1
"
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(8, 10)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(93, 13)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Text Box Field #1:"
"
"Label2
"
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(8, 42)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(93, 13)
Me.Label2.TabIndex = 2
Me.Label2.Text = "Text Box Field #2:"
"
"TextBox2
"
Me.TextBox2.Location = New System.Drawing.Point(120, 40)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(160, 20)
Me.TextBox2.TabIndex = 3
"
"Label3
"
Me.Label3.AutoSize = True
Me.Label3.Location = New System.Drawing.Point(9, 72)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(93, 13)
Me.Label3.TabIndex = 4
Me.Label3.Text = "Text Box Field #3:"
"
"TextBox3
"
Me.TextBox3.Location = New System.Drawing.Point(121, 70)
Me.TextBox3.Name = "TextBox3"
Me.TextBox3.Size = New System.Drawing.Size(159, 20)
Me.TextBox3.TabIndex = 5
"
"Label4
"
Me.Label4.AutoSize = True
Me.Label4.Location = New System.Drawing.Point(8, 104)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(62, 13)
Me.Label4.TabIndex = 6
Me.Label4.Text = "Information:"
"
"ShowInfo
"
Me.ShowInfo.AutoSize = True
Me.ShowInfo.Location = New System.Drawing.Point(120, 104)
Me.ShowInfo.Name = "ShowInfo"
Me.ShowInfo.Size = New System.Drawing.Size(27, 13)
Me.ShowInfo.TabIndex = 7
Me.ShowInfo.Text = "N/A"
"
"Form1
"
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(320, 136)
Me.Controls.Add(Me.ShowInfo)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.TextBox3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.TextBox1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.MaximizeBox = False
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Sharing Control Logic"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents ShowInfo As System.Windows.Forms.Label
End Class
TextBox.Validating
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Public Class MainClass
Shared Sub Main()
Dim form1 As Form = New Form1
Application.Run(form1)
End Sub
End Class
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
"This call is required by the Windows Form Designer.
InitializeComponent()
"Add any initialization after the InitializeComponent() call
End Sub
"Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
"Required by the Windows Form Designer
Private components As System.ruponentModel.IContainer
"NOTE: The following procedure is required by the Windows Form Designer
"It can be modified using the Windows Form Designer.
"Do not modify it using the code editor.
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents txtFirstName As System.Windows.Forms.TextBox
Friend WithEvents txtLastName As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents errProvider As System.Windows.Forms.ErrorProvider
Friend WithEvents txtEmail As System.Windows.Forms.TextBox
Friend WithEvents Label3 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.GroupBox1 = New System.Windows.Forms.GroupBox()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label1 = New System.Windows.Forms.Label()
Me.txtFirstName = New System.Windows.Forms.TextBox()
Me.txtLastName = New System.Windows.Forms.TextBox()
Me.Button1 = New System.Windows.Forms.Button()
Me.errProvider = New System.Windows.Forms.ErrorProvider()
Me.txtEmail = New System.Windows.Forms.TextBox()
Me.Label3 = New System.Windows.Forms.Label()
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
"
"GroupBox1
"
Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label3, Me.txtEmail, Me.Label2, Me.Label1, Me.txtFirstName, Me.txtLastName})
Me.GroupBox1.Location = New System.Drawing.Point(8, 8)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(368, 124)
Me.GroupBox1.TabIndex = 11
Me.GroupBox1.TabStop = False
"
"Label2
"
Me.Label2.Location = New System.Drawing.Point(16, 52)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(64, 16)
Me.Label2.TabIndex = 8
Me.Label2.Text = "Last Name:"
"
"Label1
"
Me.Label1.Location = New System.Drawing.Point(16, 28)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(64, 16)
Me.Label1.TabIndex = 7
Me.Label1.Text = "First Name:"
"
"txtFirstName
"
Me.txtFirstName.Location = New System.Drawing.Point(84, 24)
Me.txtFirstName.Name = "txtFirstName"
Me.txtFirstName.Size = New System.Drawing.Size(152, 21)
Me.txtFirstName.TabIndex = 4
Me.txtFirstName.Text = ""
"
"txtLastName
"
Me.txtLastName.Location = New System.Drawing.Point(84, 48)
Me.txtLastName.Name = "txtLastName"
Me.txtLastName.Size = New System.Drawing.Size(152, 21)
Me.txtLastName.TabIndex = 5
Me.txtLastName.Text = ""
"
"Button1
"
Me.Button1.Location = New System.Drawing.Point(152, 204)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(76, 24)
Me.Button1.TabIndex = 10
Me.Button1.Text = "OK"
"
"txtEmail
"
Me.txtEmail.Location = New System.Drawing.Point(84, 84)
Me.txtEmail.Name = "txtEmail"
Me.txtEmail.Size = New System.Drawing.Size(152, 21)
Me.txtEmail.TabIndex = 9
Me.txtEmail.Text = ""
"
"Label3
"
Me.Label3.Location = New System.Drawing.Point(16, 88)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(64, 16)
Me.Label3.TabIndex = 10
Me.Label3.Text = "Email:"
"
"ErrorProviderValidation
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
Me.ClientSize = New System.Drawing.Size(388, 238)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.GroupBox1, Me.Button1})
Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Name = "ErrorProviderValidation"
Me.Text = "ErrorProvider Validation"
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub txtName_Validating(ByVal sender As Object, ByVal e As System.ruponentModel.CancelEventArgs) Handles txtFirstName.Validating, txtLastName.Validating
If CType(sender, TextBox).Text = "" Then
errProvider.SetError(sender, "You must enter a first and last name.")
Else
errProvider.SetError(sender, "")
End If
End Sub
End Class