I did one program that draws a line with two squares at the ends and I can just click and extend each ends. It works ok but I need to move the whole line. Would anyone knows how?
Private Const gs As Integer = 34
Private Const hw As Integer = 6
Private Const hhw As Integer = hw \ 2
Private bf As Bitmap
Private drag As Integer = -1
Private pts() As Point
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
ReDim pts(1)
pts(0).X = 50 : pts(0).Y = 50
pts(1).X = 250 : pts(1).Y = 50
For i As Integer = 0 To UBound(pts)
SnapToGrid(pts( i).X, pts(i).Y)
Next
End Sub
Private Sub Draw(ByVal Gr As Graphics)
Gr.DrawImage(bf , 0, 0)
Gr.DrawPolygon( Pens.Black, pts)
Dim rect() As Rectangle
ReDim rect(UBound(pts ))
For i As Integer = 0 To UBound(pts)
rect(i).X = pts(i).X - hhw
rect(i).Y = pts(i).Y - hhw
rect(i).Width = hw
rect(i).Height = hw
Next
Gr.FillRectangl es(Brushes.Beig e, rect)
Gr.DrawRectangl es(Pens.Black, rect)
End Sub
Private Sub pic_MouseDown(B yVal sender As Object, ByVal e As System.Windows. Forms.MouseEven tArgs) Handles pic.MouseDown
For i As Integer = 0 To UBound(pts)
If Abs(pts(i).X - e.X) < hhw And Abs(pts(i).Y - e.Y) < hhw Then
drag = i
pic.Cursor = Cursors.Hand
Exit For
End If
Next
End Sub
Private Sub pic_MouseMove(B yVal sender As Object, ByVal e As System.Windows. Forms.MouseEven tArgs) Handles pic.MouseMove
If drag = -1 Then Exit Sub
pts(drag).X = e.X
pts(drag).Y = e.Y
SnapToGrid(pts( drag).X, pts(drag).Y)
Draw(pic.Create Graphics)
End Sub
Private Sub pic_MouseUp(ByV al sender As Object, ByVal e As System.Windows. Forms.MouseEven tArgs) Handles pic.MouseUp
drag = -1
pic.Cursor = Cursors.Default
End Sub
Private Sub pic_Paint(ByVal sender As Object, ByVal e As System.Windows. Forms.PaintEven tArgs) Handles pic.Paint
Draw(e.Graphics )
End Sub
Private Sub SnapToGrid(ByRe f x As Integer, ByRef y As Integer)
x = gs * CInt(x / gs)
y = gs * CInt(y / gs)
End Sub
Private Sub DrawGrid(ByVal bm As Bitmap)
For x As Integer = 0 To pic.Width - 1 Step gs
For y As Integer = 0 To pic.Height - 1 Step gs
bm.SetPixel(x, y, Color.Black)
Next
Next
End Sub
Private Sub pic_Resize(ByVa l sender As Object, ByVal e As System.EventArg s) Handles pic.Resize
bf = New Bitmap(pic.Widt h, pic.Height)
Dim Gr As Graphics = Graphics.FromIm age(bf)
Gr.Clear(pic.Ba ckColor)
For x As Integer = 0 To pic.Width - 1 Step gs
For y As Integer = 0 To pic.Height - 1 Step gs
bf.SetPixel(x, y, Color.Black)
Next
Next
End Sub
0 1382 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Dennis |
last post by:
Hello,
Ive to draw a line on a picture i used this code:
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
x1 = z.X
y1 = z.Y
lbl3 = "x1: " & x1
lbl4 = "y1: " & y1
|
by: John |
last post by:
I created a number of pictureboxes in a panel, and want to draw lines in
those pictureboxes but I cannot. Please see the following code and make
corrections.
Thanks.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Panel1.AutoScroll = True
Panel1.Width = 200
Panel1.Height = 200
|
by: Ed Bitzer |
last post by:
Can draw a line on my form with a button click event but cannot upon the
Load event when I wish. No more line object so used the following:
Dim bit As Bitmap = New Bitmap(Me.Width, Me.Height)
Dim g As Graphics = Graphics.FromImage(bit)
Dim myPen As Pen = New Pen(Color.Blue, 1)
Me.CreateGraphics.DrawLine(myPen, 0, 5, Me.Width, 5)
Appreciate some help.
Ed
|
by: Mattbooty |
last post by:
Hello,
Not sure if anyone else has seen this bug, but I have a form where
the entire form is covered with a picturebox. The picturebox has a
mouseup event. I also have an open file dialog for loading images into
the picturebox. If you double click the file you want to open in the
open file dialog, it somehow interperets one of the clicks as a mouseup
on the picturebox and fires the mouseup event for the picturebox. How
can I get...
|
by: wxnut |
last post by:
In VB 2005 I have six seperately named picture boxes (arranged in a table
layout control) in which I plot different X/Y data lines. I would like to be
able to right-click on a specific picture box (say, plot #3) and select a
different line color for that one plot.
How can I figure out which of the six plots is the one in question when
right-clicking on it? I can easily change the line color using the context
menu control, but I don't...
| |
by: Alejandro |
last post by:
Hi,
I Have a form with Collection of 52 picturebox.
Public cl As New Collection
Private m_Bitmap As Bitmap
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
|
by: Ben3eeE |
last post by:
Im having trouble making a Paint.exe straight line draw.
You know the one where you point out where to start then hold down the
mouse button and release it to finish the drawing. My problem is that
if i move the mouse back the line should move back with it and if i
spin the mouse the line should spin and dont draw anything before i release
the button.
im using Microsoft visual stuido.net 2003
|
by: Overseer |
last post by:
What is the best way to draw graphics like Task Manager's Performance
Graphic??
|
by: Niu Kun |
last post by:
Dear all,
I'm planning to draw some overlapped pictures on a tabpage.
I use PictureBox control. And the picture seems well at first.
But when I try to draw a PictureBox on the other.
The transparent part of the PictureBox seems to have the same colour
with the tabpage background.
And the PictureBox under it is covered by that.
The covered part is never seen again.
Can I simply solve the problem with existing simple control?
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |