Click here to Skip to main content
15,911,848 members
Home / Discussions / Visual Basic
   

Visual Basic

 
Generalto close a form Pin
ADY00728-Apr-05 5:15
ADY00728-Apr-05 5:15 
GeneralRe: to close a form Pin
Joey Picerno28-Apr-05 7:46
Joey Picerno28-Apr-05 7:46 
GeneralRe: to close a form Pin
ADY00728-Apr-05 8:00
ADY00728-Apr-05 8:00 
GeneralTransparent Form Pin
Joey Picerno28-Apr-05 3:31
Joey Picerno28-Apr-05 3:31 
QuestionHow to fetch database names Pin
Suman Singh28-Apr-05 3:13
professionalSuman Singh28-Apr-05 3:13 
AnswerRe: How to fetch database names Pin
Colin Angus Mackay28-Apr-05 3:55
Colin Angus Mackay28-Apr-05 3:55 
GeneralRe: How to fetch database names Pin
Suman Singh28-Apr-05 20:28
professionalSuman Singh28-Apr-05 20:28 
GeneralFreehand drawing in vb.net Pin
meghadwivedi28-Apr-05 3:09
meghadwivedi28-Apr-05 3:09 
I have been using below code for freehang drawing in vb.net.But it doesn't change the color of new drawn line only.it changes the whole mousepath color, means if i select blue and previous one is red then whole path becomes blue.
But i desperately need screen pen effect like if i select blue then only blue reflect on mousepath and previous path(previously drawn line) color remains same.As like paint previous lines color remain same.

If any one knows plz help me!!!!Smile | :)


Imports System
Imports System.Drawing
Imports System.Windows.Forms


Public Class Form1
'Namespace myPaint

Inherits System.Windows.Forms.Form ' Of course Wink | ;)

Dim mousePath As New System.Drawing.Drawing2D.GraphicsPath() 'declare a new Graphic path to follow the mouse movement

'*** below I declare some values for an Alpha and other user selected variables
'these will be used as I expand this program for a higher level use.

Dim myAlpha As Integer = 100 ' declare a Alpha variable
Dim myUserColor As New Color() 'this is a color the user selects
Dim myPenWidth As Single = 5 'set pen width variable

'**************************************************************



#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 Label1 As System.Windows.Forms.Label
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents Panel1 As System.Windows.Forms.Panel
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.Button4 = New System.Windows.Forms.Button
Me.Panel1 = New System.Windows.Forms.Panel
Me.PictureBox1 = New System.Windows.Forms.PictureBox
Me.Panel1.SuspendLayout()
Me.SuspendLayout()
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(87, 35)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(393, 27)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Below is a Graphics path freehand drawing space"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(488, 112)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 3
Me.Button1.Text = "RED"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(488, 160)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 4
Me.Button2.Text = "BLUE"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(488, 216)
Me.Button3.Name = "Button3"
Me.Button3.TabIndex = 5
Me.Button3.Text = "GREEN"
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(488, 264)
Me.Button4.Name = "Button4"
Me.Button4.TabIndex = 6
Me.Button4.Text = "YELLOW"
'
'Panel1
'
Me.Panel1.BackColor = System.Drawing.Color.Gray
Me.Panel1.Controls.Add(Me.PictureBox1)
Me.Panel1.Location = New System.Drawing.Point(24, 80)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(448, 280)
Me.Panel1.TabIndex = 7
'
'PictureBox1
'
Me.PictureBox1.BackColor = System.Drawing.Color.Transparent
Me.PictureBox1.Location = New System.Drawing.Point(16, 24)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(408, 240)
Me.PictureBox1.TabIndex = 8
Me.PictureBox1.TabStop = False
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.Color.BlanchedAlmond
Me.ClientSize = New System.Drawing.Size(579, 534)
Me.Controls.Add(Me.Panel1)
Me.Controls.Add(Me.Button4)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.Label1)
Me.Name = "Form1"
Me.Text = "Johns' Free Hand Doodle"
Me.Panel1.ResumeLayout(False)
Me.ResumeLayout(False)

End Sub

#End Region



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
myUserColor = (System.Drawing.Color.Red)
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
myUserColor = (System.Drawing.Color.Blue)
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
myUserColor = (System.Drawing.Color.Green)
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
myUserColor = (System.Drawing.Color.Yellow)
End Sub
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseDown

If e.Button = MouseButtons.Left Then ' draw a filled circle if left mouse is down

mousePath.StartFigure() ' The L mouse is down so we need to start a new line in mousePath

End If
End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove

If e.Button = MouseButtons.Left Then ' draw a filled circle if left mouse is down

Try
mousePath.AddLine(e.X, e.Y, e.X, e.Y) 'Add mouse coordiantes to mousePath

Catch
MsgBox("No way, Hose!")
End Try

End If

PictureBox1.Invalidate() 'Repaint the PictureBox using the PictureBox1 Paint event

End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
' Here is where we do the actual painting

Try ' error trapping

'myUserColor = (System.Drawing.Color.Black) 'You can remove this line and add a user selected color to
'change the value of myUserColor

myAlpha = 100 ' This will give the color a Alpha effect, you can set this to 255 if you want a full color

'*********************** NOTE ***********************************************
'The line below set the pen up with the ability to add user selected Alpha, Color and Penwidth
' A simpler, but less flexible solution would be to replace the line with the following code:
'Dim CurrentPen = New Pen(System.Drawing.Color.Black, myPenWidth)
'************ End Note ***************************

Dim CurrentPen = New Pen(Color.FromArgb(myAlpha, myUserColor), myPenWidth) 'Set up the pen

e.Graphics.DrawPath(CurrentPen, mousePath) 'draw the path! Smile | :)

Catch
' MsgBox("Not happening!")
End Try

End Sub






'End Namespace


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

End Sub
End Class
'Form1



Megha
GeneralRe: Freehand drawing in vb.net Pin
Fernando Soto28-Apr-05 8:06
Fernando Soto28-Apr-05 8:06 
GeneralNullable types in vb.net Pin
Anonymous28-Apr-05 1:07
Anonymous28-Apr-05 1:07 
GeneralRe: Nullable types in vb.net Pin
Greeky28-Apr-05 2:43
Greeky28-Apr-05 2:43 
GeneralGet PIDL from file path Pin
Andy H27-Apr-05 23:44
Andy H27-Apr-05 23:44 
General"out-of-paper" error Pin
lmaks27-Apr-05 23:11
lmaks27-Apr-05 23:11 
GeneralRe: &quot;out-of-paper&quot; error Pin
Anonymous28-Apr-05 5:55
Anonymous28-Apr-05 5:55 
GeneralRe: &quot;out-of-paper&quot; error Pin
lmaks2-May-05 4:00
lmaks2-May-05 4:00 
GeneralDatagrid Control Pin
nitin_ion27-Apr-05 22:54
nitin_ion27-Apr-05 22:54 
GeneralVS.2005 no datagridtablestyle Pin
Greeky27-Apr-05 22:44
Greeky27-Apr-05 22:44 
GeneralRe: VS.2005 no datagridtablestyle Pin
Anonymous28-Apr-05 3:20
Anonymous28-Apr-05 3:20 
GeneralReading text from command prompt Pin
johnjsm27-Apr-05 22:31
johnjsm27-Apr-05 22:31 
GeneralRe: Reading text from command prompt Pin
Fernando Soto28-Apr-05 10:37
Fernando Soto28-Apr-05 10:37 
GeneralRe: Reading text from command prompt Pin
Fernando Soto4-May-05 6:23
Fernando Soto4-May-05 6:23 
GeneralProblems with the debugger in VB.Net Pin
Johtrek27-Apr-05 21:54
Johtrek27-Apr-05 21:54 
GeneralRe: Problems with the debugger in VB.Net Pin
Nostra27-Apr-05 22:15
Nostra27-Apr-05 22:15 
GeneralRe: Problems with the debugger in VB.Net Pin
Johtrek27-Apr-05 22:46
Johtrek27-Apr-05 22:46 
GeneralRe: Problems with the debugger in VB.Net Pin
rwestgraham28-Apr-05 7:20
rwestgraham28-Apr-05 7:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.