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(By Val sender As Object, ByVal e As System.EventArg s) 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.EventArg s) Handles BtnClear.Click
Picbox.Image = Nothing 'clears picture box
End Sub
Private Sub Picbox_MouseDow n(ByVal sender As Object, ByVal e As System.Windows. Forms.MouseEven tArgs) Handles Picbox.MouseDow n
'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.MouseEven tArgs) 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(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Btndraw.Click
Dim mygraphics As Graphics
Dim mycoordinates As Integer
mygraphics = Picbox.CreateGr aphics
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.E quals(black) Then
mycolor = black
ElseIf CmbColor.Text.E quals(red) Then
mycolor = red
ElseIf CmbColor.Text.E quals(blue) Then
mycolor = blue
ElseIf CmbColor.Text.E quals(green) Then
mycolor = green
ElseIf CmbColor.Text.E quals(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:=Colo r.CadetBlue, Width:=4)
mygraphics.Draw Line(Pen:=myPen , x1:=35, y1:=35, x2:=300, y2:=400)
myrectangle = New Rectangle(x:=30 , y:=30, Width:=80, Height:=160)
mygraphics.Draw Rectangle(Pen:= myPen, rect:=myrectang le)
End Sub
End Class
1 1775
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 an exception to be
thrown):
This one works but it's not the results I want.
private void CreateImage1()
{
|
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)
System.InvalidOperationExceptionSystem.InvalidOperationException: The object is currently in use elsewhere.
at System.Drawing.Image.get_Width()
at System.Drawing.Image.get_Size()
at System.Windows.Forms.PictureBox.GetPreferredSize()
at...
|
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 reproduce the exception consistently, but
it seems to be timing dependent. Here is what happens:
I have a subform that I open, load an image from a file
into my PictureBox, take some user input, then I hide the
|
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 referenced, custom dll. I call
a PrintImage routine in the dll and pass it only the the
Picturebox.hdc from the main form. The dll's print routine
draws to the hdc and it shows up in the picturebox
perfectly.
I would like to do a similar thing...
|
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 actual drawing work.
But after displaying all the arrows in a flick, the arrows disappers.
I have debugged and came to know that the "Paint" event of the picturebox is refreshing the image, so the work done on the CreateGraphics created object is...
| |
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 file? I've looked at Bitmap objects,
which support saving, but can't see a way to grab what I have drawn and make
a bitmap from it, or whatever. Anybody done this?
Thanks for any suggestions
|
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 System.Drawing.Bitmap
has a SetPixel() method but I can't seem to find out how to have the bitmap
displayed. I would actually like to have the pixels appear as I set them.
Regards
Chris Saunders
|
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 want to be able to draw
lines in a picturebox based upon certain data points I have received. I
dragged a picturebox from the toolbar onto my form, but after having gone
through the help files, looking online and trying a variety of things, I...
|
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 g.DrawLine(..), but I have a lot of line.
In C++ is a parameter XORPUT, but in C# I can't find it.
|
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 graphic. In my customer PC, i already installed .net Frame Work 2.0 (SP1). I don't know why missing? I write code like this...
Pen penMi = Pens.Blue;
void DrawAllMi(Graphics g)
{
g.DrawRectangle(penMi, x1 - 4, y1 - 4, 8, 8);
...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |