|
Imports System.Configuration
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.ComponentModel.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 NotifyIcon1 As System.Windows.Forms.NotifyIcon
Friend WithEvents ExitButton As System.Windows.Forms.Button
Friend WithEvents RichTextBox1 As System.Windows.Forms.RichTextBox
Friend WithEvents SendButton As System.Windows.Forms.Button
Friend WithEvents HideButton As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
Me.NotifyIcon1 = New System.Windows.Forms.NotifyIcon(Me.components)
Me.SendButton = New System.Windows.Forms.Button()
Me.ExitButton = New System.Windows.Forms.Button()
Me.RichTextBox1 = New System.Windows.Forms.RichTextBox()
Me.HideButton = New System.Windows.Forms.Button()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.SuspendLayout()
'
'NotifyIcon1
'
Me.NotifyIcon1.Icon = CType(resources.GetObject("NotifyIcon1.Icon"), System.Drawing.Icon)
Me.NotifyIcon1.Text = "Weblog Client"
Me.NotifyIcon1.Visible = True
'
'SendButton
'
Me.SendButton.Anchor = (System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left)
Me.SendButton.Location = New System.Drawing.Point(8, 267)
Me.SendButton.Name = "SendButton"
Me.SendButton.Size = New System.Drawing.Size(120, 23)
Me.SendButton.TabIndex = 2
Me.SendButton.Text = "Send to Weblog >>"
'
'ExitButton
'
Me.ExitButton.Anchor = (System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right)
Me.ExitButton.Location = New System.Drawing.Point(410, 267)
Me.ExitButton.Name = "ExitButton"
Me.ExitButton.TabIndex = 4
Me.ExitButton.Text = "Exit"
'
'RichTextBox1
'
Me.RichTextBox1.Anchor = (System.Windows.Forms.AnchorStyles.Left Or System.Windows.Forms.AnchorStyles.Right)
Me.RichTextBox1.Font = New System.Drawing.Font("Georgia", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.RichTextBox1.Location = New System.Drawing.Point(0, 56)
Me.RichTextBox1.Name = "RichTextBox1"
Me.RichTextBox1.Size = New System.Drawing.Size(490, 208)
Me.RichTextBox1.TabIndex = 1
Me.RichTextBox1.Text = ""
'
'HideButton
'
Me.HideButton.Anchor = (System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right)
Me.HideButton.Location = New System.Drawing.Point(322, 267)
Me.HideButton.Name = "HideButton"
Me.HideButton.TabIndex = 3
Me.HideButton.Text = "Hide"
'
'Label1
'
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(100, 16)
Me.Label1.TabIndex = 5
Me.Label1.Text = "Title:"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(0, 40)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(100, 16)
Me.Label2.TabIndex = 6
Me.Label2.Text = "Body:"
'
'TextBox1
'
Me.TextBox1.Anchor = ((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right)
Me.TextBox1.Location = New System.Drawing.Point(0, 16)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(488, 20)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = ""
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(490, 296)
Me.ControlBox = False
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox1, Me.Label2, Me.Label1, Me.RichTextBox1, Me.ExitButton, Me.SendButton, Me.HideButton})
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Form1"
Me.ShowInTaskbar = False
Me.Text = "Weblog Client"
Me.ResumeLayout(False)
End Sub
#End Region
Private bHidden As Boolean
Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
Me.Dispose()
End Sub
Private Sub Send_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendButton.Click
'set the hourglass cursor
Cursor.Current = Cursors.WaitCursor
'Send message to the Weblog via SOAP/Webservice
Dim wsWeblog As New Weblog.Weblog()
'get password from the config file (weblogclient.exe.config)
Dim password As String = ConfigurationSettings.AppSettings("password")
If password Is Nothing Then
ConfigError("password")
End If
'this is our SOAP Header class
Dim authentication As New Weblog.AuthHeader()
authentication.password = password
wsWeblog.AuthHeaderValue = authentication
'get the Web Service URL from the config file
Dim URL As String = ConfigurationSettings.AppSettings("wsPostURL")
If URL Is Nothing Then
ConfigError("URL")
End If
'set the correct URL for the Web Service
wsWeblog.Url = URL
'send HTML converted text to the weblog webservice
wsWeblog.PostMessage(TextBox1.Text, RichTextBoxUtil.ConvertToHTML(RichTextBox1))
WindowState = FormWindowState.Minimized
HideMe()
'clear out the textboxes
Me.RichTextBox1.Clear()
Me.TextBox1.Clear()
'set normal cursor again
NormalCursor()
End Sub
Private Sub ConfigError(ByVal Setting As String)
MessageBox.Show("The " & Setting & " setting in the config file is missing. Make sure you have the config file WeblogClient.exe.config in the working directory.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
NormalCursor()
Me.Dispose()
Exit Sub
End Sub
Private Sub NormalCursor()
'set the cursor back to normal
Cursor.Current = Cursors.Arrow
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'clear message window
Me.RichTextBox1.Text = ""
'bHidden = True
End Sub
Private Sub HideMe()
Me.Hide()
bHidden = True
End Sub
Private Sub ShowMe()
Me.Show()
Me.Activate()
Me.WindowState = FormWindowState.Normal
bHidden = False
Me.TextBox1.Focus()
End Sub
'when user clicks the tray icon, bring the dialog up and down
Private Sub NotifyIcon1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDown
If bHidden Then
ShowMe()
Else
HideMe()
End If
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
NotifyIcon1.Dispose()
End Sub
Private Sub HideButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HideButton.Click
HideMe()
End Sub
End Class
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Johan started coding a long time ago on a ZX Spectrum and the Z80 processor. His parents were rather sceptical about him sitting up all night coding and playing Manic Miner but they don't regret buying that computer now, since it turned out pretty good in the end.
Johan is now working as a Systems Architect and jump between a number of different platforms and computer languages every day. He wouldn’t cope if it weren’t for IntelliSense and code completion...