Click here to Skip to main content
15,881,413 members
Articles / Programming Languages / XML

Brainnet - Introducing a declarative neural network library

Rate me:
Please Sign up or sign in to vote.
4.74/5 (117 votes)
4 Apr 2007CPOL18 min read 400.9K   9.4K   410  
This article is expected to (0) Introduce Brainnet, a declarative neural network library we developed (1) Demonstrate some practical uses neural network programming (2) Give you a fair idea regarding neurons, neural networks and their applications (3) Introduce BrainNet library - an open source
Public Class PatternDraw
    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 picCanvas As System.Windows.Forms.PictureBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.picCanvas = New System.Windows.Forms.PictureBox()
        Me.SuspendLayout()
        '
        'picCanvas
        '
        Me.picCanvas.BackColor = System.Drawing.Color.White
        Me.picCanvas.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.picCanvas.Location = New System.Drawing.Point(9, 8)
        Me.picCanvas.Name = "picCanvas"
        Me.picCanvas.Size = New System.Drawing.Size(160, 160)
        Me.picCanvas.TabIndex = 0
        Me.picCanvas.TabStop = False
        '
        'PatternDraw
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(180, 210)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.picCanvas})
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
        Me.Name = "PatternDraw"
        Me.Text = "Draw Pattern"
        Me.ResumeLayout(False)

    End Sub

#End Region


    Private m_Drawing As Boolean
    Private m_LastX As Integer
    Private m_LastY As Integer

    Private m_Bitmap As Bitmap
    Private m_Graphics As Graphics

    ' Allocate the first Bitmap.
    Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AllocateBitmap()
    End Sub

    ' Make a new Bitmap to draw on.
    Private Sub Form_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
        AllocateBitmap()
    End Sub

    ' Make a new Bitmap to draw on.
    Private Sub AllocateBitmap()
        ' Make the PictureBox fill the form.


        ' Make a new Bitmap.
        m_Bitmap = New Bitmap(picCanvas.Width, picCanvas.Height)

        ' Make a Graphics object to draw on the Bitmap.
        m_Graphics = Graphics.FromImage(m_Bitmap)

        ' Make the PictureBox show the empty Bitmap.
        picCanvas.Image = m_Bitmap
    End Sub

    ' Start scribbling.
    Private Sub picCanvas_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picCanvas.MouseDown
        m_Drawing = True
        m_LastX = e.X
        m_LastY = e.Y
    End Sub

    ' Continue scribbling.
    Private Sub picCanvas_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picCanvas.MouseMove
        If m_Drawing Then
            ' Draw the new line.



            If e.Button = MouseButtons.Left Then
                m_Graphics.FillEllipse(New SolidBrush(Color.Black), e.X - 15, e.Y - 15, 30, 30)
            Else
                m_Graphics.FillEllipse(New SolidBrush(Color.White), e.X - 15, e.Y - 15, 30, 30)
            End If

            ' Display the result.
            picCanvas.Image = m_Bitmap

            ' Save the latest point.
            m_LastX = e.X
            m_LastY = e.Y
        End If
    End Sub

    ' Stop scribbling.
    Private Sub picCanvas_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picCanvas.MouseUp
        m_Drawing = False
    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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
India India
Architect, Developer, Speaker | Wannabe GUT inventor & Data Scientist | Microsoft MVP in C#

Comments and Discussions