VB.Net/Application/Text Editor — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 12:41, 26 мая 2010
Simple Text Editor
Imports System
Imports System.Collections
Imports System.ruponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Configuration
Imports System.Resources
Imports System.Drawing
Imports System.Drawing.Drawing2D
Public Class MainClass
Shared Sub Main()
Dim myform As Form = New TextEditor()
Application.Run(myform)
End Sub
End Class
Public Class TextEditor
Public Property StatusText() As String
Get
Return sspStatus.Text
End Get
Set(ByVal value As String)
sspStatus.Text = value
End Set
End Property
Public Property EditText() As String
Get
Return txtEdit.Text
End Get
Set(ByVal value As String)
txtEdit.Text = value
End Set
End Property
Public Sub ClearEditBox()
EditText = String.Empty
txtEdit.ForeColor = Color.Black
StatusText = "Text box cleared"
End Sub
Private Sub txtEdit_TextChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles txtEdit.TextChanged
"Reset the status bar text
StatusText = "Ready"
End Sub
Private Sub tbrClear_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles tbrClear.Click
ClearEditBox()
End Sub
Public Sub RedText()
txtEdit.ForeColor = Color.Red
StatusText = "The text is red"
End Sub
Private Sub tbrRed_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles tbrRed.Click
RedText()
End Sub
Public Sub BlueText()
txtEdit.ForeColor = Color.Blue
StatusText = "The text is blue"
End Sub
Private Sub tbrBlue_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles tbrBlue.Click
BlueText()
End Sub
Public Sub UppercaseText()
EditText = EditText.ToUpper
StatusText = "The text is all uppercase"
End Sub
Private Sub tbrUpperCase_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles tbrUpperCase.Click
UppercaseText()
End Sub
Public Sub LowercaseText()
EditText = EditText.ToLower
StatusText = "The text is all lowercase"
End Sub
Private Sub tbrLowerCase_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles tbrLowerCase.Click
LowercaseText()
End Sub
Public Sub ShowAboutBox()
End Sub
Private Sub tbrHelpAbout_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles tbrHelpAbout.Click
ShowAboutBox()
End Sub
End Class
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Public Class TextEditor
Inherits System.Windows.Forms.Form
"Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overloads 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()
" Dim resources As System.ruponentModel.ruponentResourceManager = New System.ruponentModel.ruponentResourceManager(GetType(TextEditor))
Me.ToolStrip1 = New System.Windows.Forms.ToolStrip
Me.tbrClear = New System.Windows.Forms.ToolStripButton
Me.ToolStripSeparator1 = New System.Windows.Forms.ToolStripSeparator
Me.tbrRed = New System.Windows.Forms.ToolStripButton
Me.tbrBlue = New System.Windows.Forms.ToolStripButton
Me.ToolStripSeparator2 = New System.Windows.Forms.ToolStripSeparator
Me.tbrUpperCase = New System.Windows.Forms.ToolStripButton
Me.tbrLowerCase = New System.Windows.Forms.ToolStripButton
Me.ToolStripSeparator3 = New System.Windows.Forms.ToolStripSeparator
Me.tbrHelpAbout = New System.Windows.Forms.ToolStripButton
Me.StatusStrip1 = New System.Windows.Forms.StatusStrip
Me.sspStatus = New System.Windows.Forms.ToolStripStatusLabel
Me.txtEdit = New System.Windows.Forms.TextBox
Me.ToolStrip1.SuspendLayout()
Me.StatusStrip1.SuspendLayout()
Me.SuspendLayout()
"
"ToolStrip1
"
Me.ToolStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.tbrClear, Me.ToolStripSeparator1, Me.tbrRed, Me.tbrBlue, Me.ToolStripSeparator2, Me.tbrUpperCase, Me.tbrLowerCase, Me.ToolStripSeparator3, Me.tbrHelpAbout})
Me.ToolStrip1.Location = New System.Drawing.Point(0, 0)
Me.ToolStrip1.Name = "ToolStrip1"
Me.ToolStrip1.Size = New System.Drawing.Size(592, 25)
Me.ToolStrip1.Stretch = True
Me.ToolStrip1.TabIndex = 0
Me.ToolStrip1.Text = "ToolStrip1"
"
"tbrClear
"
Me.tbrClear.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image
"Me.tbrClear.Image = CType(resources.GetObject("tbrClear.Image"), System.Drawing.Image)
Me.tbrClear.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None
Me.tbrClear.ImageTransparentColor = System.Drawing.Color.Magenta
Me.tbrClear.Name = "tbrClear"
Me.tbrClear.Text = "New"
Me.tbrClear.ToolTipText = "New"
"
"ToolStripSeparator1
"
Me.ToolStripSeparator1.Name = "ToolStripSeparator1"
"
"tbrRed
"
Me.tbrRed.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image
"Me.tbrRed.Image = CType(resources.GetObject("tbrRed.Image"), System.Drawing.Image)
Me.tbrRed.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None
Me.tbrRed.ImageTransparentColor = System.Drawing.Color.Magenta
Me.tbrRed.Name = "tbrRed"
Me.tbrRed.Text = "Red"
Me.tbrRed.ToolTipText = "Red"
"
"tbrBlue
"
Me.tbrBlue.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image
"Me.tbrBlue.Image = CType(resources.GetObject("tbrBlue.Image"), System.Drawing.Image)
Me.tbrBlue.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None
Me.tbrBlue.ImageTransparentColor = System.Drawing.Color.Magenta
Me.tbrBlue.Name = "tbrBlue"
Me.tbrBlue.Text = "Blue"
Me.tbrBlue.ToolTipText = "Blue"
"
"ToolStripSeparator2
"
Me.ToolStripSeparator2.Name = "ToolStripSeparator2"
"
"tbrUpperCase
"
Me.tbrUpperCase.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image
"Me.tbrUpperCase.Image = CType(resources.GetObject("tbrUpperCase.Image"), System.Drawing.Image)
Me.tbrUpperCase.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None
Me.tbrUpperCase.ImageTransparentColor = System.Drawing.Color.Magenta
Me.tbrUpperCase.Name = "tbrUpperCase"
Me.tbrUpperCase.Text = "Upper Case"
Me.tbrUpperCase.ToolTipText = "Upper Case"
"
"tbrLowerCase
"
Me.tbrLowerCase.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image
"Me.tbrLowerCase.Image = CType(resources.GetObject("tbrLowerCase.Image"), System.Drawing.Image)
Me.tbrLowerCase.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.None
Me.tbrLowerCase.ImageTransparentColor = System.Drawing.Color.Magenta
Me.tbrLowerCase.Name = "tbrLowerCase"
Me.tbrLowerCase.Text = "Lower Case"
Me.tbrLowerCase.ToolTipText = "Lower Case"
"
"ToolStripSeparator3
"
Me.ToolStripSeparator3.Name = "ToolStripSeparator3"
"
"tbrHelpAbout
"
Me.tbrHelpAbout.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image
"Me.tbrHelpAbout.Image = CType(resources.GetObject("tbrHelpAbout.Image"), System.Drawing.Image)
Me.tbrHelpAbout.ImageTransparentColor = System.Drawing.Color.Magenta
Me.tbrHelpAbout.Name = "tbrHelpAbout"
Me.tbrHelpAbout.Text = "About"
Me.tbrHelpAbout.ToolTipText = "About"
"
"StatusStrip1
"
Me.StatusStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.sspStatus})
Me.StatusStrip1.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.Table
Me.StatusStrip1.Location = New System.Drawing.Point(0, 411)
Me.StatusStrip1.Name = "StatusStrip1"
Me.StatusStrip1.Size = New System.Drawing.Size(592, 22)
Me.StatusStrip1.TabIndex = 1
Me.StatusStrip1.Text = "StatusStrip1"
"
"sspStatus
"
Me.sspStatus.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text
Me.sspStatus.Name = "sspStatus"
Me.sspStatus.Text = "Ready"
"
"txtEdit
"
Me.txtEdit.Dock = System.Windows.Forms.DockStyle.Fill
Me.txtEdit.Location = New System.Drawing.Point(0, 25)
Me.txtEdit.Multiline = True
Me.txtEdit.Name = "txtEdit"
Me.txtEdit.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.txtEdit.Size = New System.Drawing.Size(592, 386)
Me.txtEdit.TabIndex = 2
"
"TextEditor
"
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(592, 433)
Me.Controls.Add(Me.txtEdit)
Me.Controls.Add(Me.ToolStrip1)
Me.Controls.Add(Me.StatusStrip1)
Me.Name = "TextEditor"
Me.Text = "Text Editor"
Me.ToolStrip1.ResumeLayout(False)
Me.StatusStrip1.ResumeLayout(False)
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents ToolStrip1 As System.Windows.Forms.ToolStrip
Friend WithEvents tbrClear As System.Windows.Forms.ToolStripButton
Friend WithEvents ToolStripSeparator1 As System.Windows.Forms.ToolStripSeparator
Friend WithEvents tbrRed As System.Windows.Forms.ToolStripButton
Friend WithEvents tbrBlue As System.Windows.Forms.ToolStripButton
Friend WithEvents ToolStripSeparator2 As System.Windows.Forms.ToolStripSeparator
Friend WithEvents tbrUpperCase As System.Windows.Forms.ToolStripButton
Friend WithEvents tbrLowerCase As System.Windows.Forms.ToolStripButton
Friend WithEvents ToolStripSeparator3 As System.Windows.Forms.ToolStripSeparator
Friend WithEvents tbrHelpAbout As System.Windows.Forms.ToolStripButton
Friend WithEvents StatusStrip1 As System.Windows.Forms.StatusStrip
Friend WithEvents sspStatus As System.Windows.Forms.ToolStripStatusLabel
Friend WithEvents txtEdit As System.Windows.Forms.TextBox
End Class
TextBox based Editor
Imports System
Imports System.Data
Imports System.Collections
Imports System.Windows.Forms
Public Class MainClass
Shared Sub Main()
Dim form1 As Form = New TextEditor()
Application.Run(form1)
End Sub
End Class
Public Class TextEditor
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 statusBar As System.Windows.Forms.StatusBar
Friend WithEvents toolbar As System.Windows.Forms.ToolBar
Friend WithEvents toolbarClear As System.Windows.Forms.ToolBarButton
Friend WithEvents toolbarRed As System.Windows.Forms.ToolBarButton
Friend WithEvents toolbarBlue As System.Windows.Forms.ToolBarButton
Friend WithEvents toolbarUppercase As System.Windows.Forms.ToolBarButton
Friend WithEvents toolbarLowercase As System.Windows.Forms.ToolBarButton
Friend WithEvents toolbarHelpAbout As System.Windows.Forms.ToolBarButton
Friend WithEvents imglstToolbar As System.Windows.Forms.ImageList
Friend WithEvents txtEdit As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.ruponents = New System.ruponentModel.Container()
" Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(TextEditor))
Me.statusBar = New System.Windows.Forms.StatusBar()
Me.toolbar = New System.Windows.Forms.ToolBar()
Me.toolbarClear = New System.Windows.Forms.ToolBarButton()
Me.toolbarRed = New System.Windows.Forms.ToolBarButton()
Me.toolbarBlue = New System.Windows.Forms.ToolBarButton()
Me.toolbarUppercase = New System.Windows.Forms.ToolBarButton()
Me.toolbarLowercase = New System.Windows.Forms.ToolBarButton()
Me.toolbarHelpAbout = New System.Windows.Forms.ToolBarButton()
Me.imglstToolbar = New System.Windows.Forms.ImageList(Me.ruponents)
Me.txtEdit = New System.Windows.Forms.TextBox()
Me.SuspendLayout()
"
"statusBar
"
Me.statusBar.Location = New System.Drawing.Point(0, 397)
Me.statusBar.Name = "statusBar"
Me.statusBar.Size = New System.Drawing.Size(584, 16)
Me.statusBar.TabIndex = 2
"
"toolbar
"
Me.toolbar.Buttons.AddRange(New System.Windows.Forms.ToolBarButton() {Me.toolbarClear, Me.toolbarRed, Me.toolbarBlue, Me.toolbarUppercase, Me.toolbarLowercase, Me.toolbarHelpAbout})
Me.toolbar.DropDownArrows = True
Me.toolbar.ImageList = Me.imglstToolbar
Me.toolbar.Name = "toolbar"
Me.toolbar.ShowToolTips = True
Me.toolbar.Size = New System.Drawing.Size(584, 39)
Me.toolbar.TabIndex = 1
"
"toolbarClear
"
Me.toolbarClear.ImageIndex = 4
Me.toolbarClear.Text = "Clear"
Me.toolbarClear.ToolTipText = "Clear the text box"
"
"toolbarRed
"
Me.toolbarRed.ImageIndex = 2
Me.toolbarRed.Text = "Red"
Me.toolbarRed.ToolTipText = "Make the text red"
"
"toolbarBlue
"
Me.toolbarBlue.ImageIndex = 3
Me.toolbarBlue.Text = "Blue"
Me.toolbarBlue.ToolTipText = "Make the text blue"
"
"toolbarUppercase
"
Me.toolbarUppercase.ImageIndex = 0
Me.toolbarUppercase.Text = "Uppercase"
Me.toolbarUppercase.ToolTipText = "Make the text uppercase"
"
"toolbarLowercase
"
Me.toolbarLowercase.ImageIndex = 1
Me.toolbarLowercase.Text = "Lowercase"
Me.toolbarLowercase.ToolTipText = "Make the toolbar lowercase"
"
"toolbarHelpAbout
"
Me.toolbarHelpAbout.ImageIndex = 5
Me.toolbarHelpAbout.Text = "About"
Me.toolbarHelpAbout.ToolTipText = "Display the About box"
"
"imglstToolbar
"
Me.imglstToolbar.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit
Me.imglstToolbar.ImageSize = New System.Drawing.Size(16, 16)
" Me.imglstToolbar.ImageStream = CType(resources.GetObject("imglstToolbar.ImageStream"), System.Windows.Forms.ImageListStreamer)
Me.imglstToolbar.TransparentColor = System.Drawing.Color.Transparent
"
"txtEdit
"
Me.txtEdit.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right)
Me.txtEdit.Location = New System.Drawing.Point(8, 48)
Me.txtEdit.Multiline = True
Me.txtEdit.Name = "txtEdit"
Me.txtEdit.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.txtEdit.Size = New System.Drawing.Size(568, 340)
Me.txtEdit.TabIndex = 1
Me.txtEdit.Text = ""
"
"TextEditor
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(584, 413)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.txtEdit, Me.toolbar, Me.statusBar})
Me.Name = "TextEditor"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
" StatusText - set the text on the status bar...
Public Property StatusText() As String
Get
Return statusBar.Text
End Get
Set(ByVal Value As String)
statusBar.Text = Value
End Set
End Property
" EditText - gets or sets the text that we"re editing...
Public Property EditText() As String
Get
Return txtEdit.Text
End Get
Set(ByVal Value As String)
txtEdit.Text = Value
" clear the selection...
"txtEdit.Select(0, 0)
End Set
End Property
" ClearEditBox ?empties txtEdit...
Public Sub ClearEditBox()
" reset the EditText property...
EditText = ""
" reset the font color
txtEdit.ForeColor = System.Drawing.Color.Black
" reset the status bar...
StatusText = "Text box cleared"
End Sub
Private Sub txtEdit_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtEdit.TextChanged
" reset the status bar...
StatusText = "Ready"
End Sub
Private Sub toolbar_ButtonClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles toolbar.ButtonClick
If e.Button Is toolbarClear Then
ClearEditBox()
End If
If e.Button Is toolbarRed Then
RedText()
End If
If e.Button Is toolbarBlue Then
BlueText()
End If
If e.Button Is toolbarUppercase Then
UppercaseText()
End If
If e.Button Is toolbarLowercase Then
LowercaseText()
End If
If e.Button Is toolbarHelpAbout Then
ShowAboutBox()
End If
End Sub
Public Sub UppercaseText()
EditText = EditText.ToUpper
StatusText = "The text is all uppercase"
End Sub
Public Sub LowercaseText()
EditText = EditText.ToLower
StatusText = "The text is all lowercase"
End Sub
Public Sub RedText()
txtEdit.ForeColor = System.Drawing.Color.Red
StatusText = "The text is red"
End Sub
Public Sub BlueText()
txtEdit.ForeColor = System.Drawing.Color.Blue
StatusText = "The text is blue"
End Sub
Public Sub ShowAboutBox()
MessageBox.Show("About")
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
End Class