473,399 Members | 3,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

drawing in a picturebox

Imports System.Drawing.Graphics

Public Class Form1
Inherits System.Windows.Forms.Form
Dim x1, y1, x2, y2 As Integer
Dim red, black, blue, green, orange As Color
Dim x, y, w, h As Integer
Dim rectangle, freehand As Graphics
Dim line As Graphics
Dim wide, n As Integer
Dim myPen As Pen

#Region " Windows Form Designer generated code "


Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
'prevents the user from making the form smaller than its original size
If Me.Width < 368 Then Me.Width = 368
If Me.Height < 312 Then Me.Height = 312
End Sub

Private Sub BtnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click
Picbox.Image = Nothing 'clears picture box


End Sub

Private Sub Picbox_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Picbox.MouseDown
'gets the co-ordinates of when the mouse button is pressed
x1 = Location.X
y1 = Location.Y


End Sub


Private Sub Picbox_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Picbox.MouseUp
'gets the co-ordinates of when the mouse button is released
x2 = Location.X
y2 = Location.Y


End Sub


Private Sub Btndraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btndraw.Click

Dim mygraphics As Graphics
Dim mycoordinates As Integer
mygraphics = Picbox.CreateGraphics
Dim mywidth As Integer
Dim mycolor As Color
Dim myrectangle As Rectangle
Dim mytool As Graphics
Dim myline As Graphics


' gets the user selected color
If CmbColor.Text.Equals(black) Then
mycolor = black
ElseIf CmbColor.Text.Equals(red) Then
mycolor = red
ElseIf CmbColor.Text.Equals(blue) Then
mycolor = blue
ElseIf CmbColor.Text.Equals(green) Then
mycolor = green
ElseIf CmbColor.Text.Equals(orange) Then
mycolor = orange
End If

' gets the user selected width
If CmbWidth.Text = CStr(1) Then
mywidth = 1
ElseIf CmbWidth.Text = CStr(2) Then
mywidth = 2
ElseIf CmbWidth.Text = CStr(3) Then
mywidth = 3
ElseIf CmbWidth.Text = CStr(4) Then
mywidth = 4
ElseIf CmbWidth.Text = CStr(5) Then
mywidth = 5
End If

'gets the user selected drawing tool
If CmbTool.Text Is line Then
mytool = line
ElseIf CmbTool.Text Is rectangle Then
mytool = rectangle
ElseIf CmbTool.Text Is freehand Then
mytool = freehand
End If


myPen = New Pen(mycolor, mywidth)
' mytool = (myline)

myPen = New Pen(Color:=Color.CadetBlue, Width:=4)
mygraphics.DrawLine(Pen:=myPen, x1:=35, y1:=35, x2:=300, y2:=400)


myrectangle = New Rectangle(x:=30, y:=30, Width:=80, Height:=160)
mygraphics.DrawRectangle(Pen:=myPen, rect:=myrectangle)

End Sub
End Class
Dec 3 '06 #1
1 1760
For some reason my text did not post with the code - so here it is! I am finishing up a class in VB and would like some assistance in a program. I need to do the following: the user needs to select a drawing tool, line color and line width (have these displayed in comboboxes). when they click draw they can draw using the selected items and with the drawing start with mouse down and end with mouse up. I am able to get a drawing in the picture box, but only if I hardocde the information. I cannot get the user selected items to work, and also cannot get the mouse-up and mouse-down to be the points of the drawing. One of the tools has to be frehand drawing - would I use drawsgtring for this?
Thanks for any assistance you may be able to provide.
Dec 3 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Steve Long | last post by:
Hello, (total GDI newbie) I'm having trouble drawing just a simple line to display in a picturebox. I just want a straight, dotdash line. I have two methods, one works and one doesn't (it cause...
1
by: zengou | last post by:
My application have many picturebox objects,when run it ,sometimes i will have a strange error,how to work out ,help me please!(in windows98,the error cause frequently than in windowsxp) ...
2
by: Tyler Foreman | last post by:
Hello, I had an earlier post regarding a strange exception I (thought) I was getting in my windows form. I have since been able to trace the problem to a picturebox control on my form. I can...
13
by: Metallicraft | last post by:
I have a vb6 application. On the main form is a picture box with one or two images and several pieces of text displayed in it. These are created on the fly using gdi32 routines that are all in a...
2
by: kalp suth via DotNetMonster.com | last post by:
I want to create arrows using lines on a picture in the picture box. On clicking the button "btnShowAll", the image is loaded and the lines drawn. "RGSShowAll()" calls "DrawObjs()" which does the...
5
by: Steve Marshall | last post by:
Hi all, I am converting an app which used a picturebox to draw graphs etc onto, then saved them to a file. I can certainly draw things onto a picturbox in VB.NET, but how do I save them to a...
3
by: Chris Saunders | last post by:
I am fairly new to .Net and C# but am familiar with the Win32 API. I wish to set the pixels of the client area of a window one at a time with a specific color. I have so far discovered that...
9
by: davetelling | last post by:
I am not a programmer, I'm an engineer trying to make an interface to a product I'm designing. I have used C# to make a form that interrogates the unit via the serial port and receives the data. I...
5
by: Macias | last post by:
Hi, Please help me, how I can make a line drawing on PictureBox similar to MS paint. I thinking about this: click and hold button, move mouse and relase button. I'm trying useing this...
7
by: winzone | last post by:
I used system.drawing.graphic in C# to draw the Rectangle and Ellipse in PictureBox. In my PC and other my buddy PC show the drawing graphic and color. But my customer PC doesn't show the drawing...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.