Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Interface and Graphics > Rubberband like feature in a picture box


Reply
 
Thread Tools Display Modes
  #1  
Old 03-08-2005, 01:33 AM
NEOLLE's Avatar
NEOLLE NEOLLE is offline
fully realized avatar

Super Moderator
* Expert *
 
Join Date: Jun 2004
Location: Davao Philippines
Posts: 2,295
Smile Rubberband like feature in a picture box


Hello Guys,
Im want to create a line by clicking two points on a picturebox. I would like to obtain a rubberbanding feature where a line is drawn tailing the mouse pointer after the first point is selected and until the second point is selected.

There are several lines already drawn in my picturebox. I saved the attributes of these lines via UDT.

My first move in obtaining this rubberbanding feature is I used the CLS method and loop through all the items in my UDT and draw them one by one during MouseMove event.

This works nicely, but the picture box flickers a lot while the loop is on going.

Is there a better way of obtaining a rubberband like feature without the flicker?
Is there a picture box property like a Redraw = False which eliminates flicker?

Thanks!
Reply With Quote
  #2  
Old 03-08-2005, 04:26 AM
the-copy the-copy is offline
Regular
 
Join Date: Mar 2004
Posts: 50
Default

I am using this and it's not flickering.

Let's say that firstx is the first x-point and firsty is the y-point, and line contains wiether or not your going to draw the line

Code:
Dim line as Boolean Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) line = True firstx = X firsty = Y End Sub Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If line = True Then Picture1.Cls Picture1.Line (firstx, firsty)-(X,Y) End Sub Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) If line = True Then Picture1.Cls Picture1.Line (firstx, firsty)-(X,Y) line = False End Sub

Picture1.AutoRedraw = True


I dosen't know if that would help you but i hope so. GLHF
Reply With Quote
  #3  
Old 03-08-2005, 04:57 AM
BillSoo's Avatar
BillSoo BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

A simpler way would be to just draw your rubber band box using the NOT XOR operation. This eliminates the need to cls your picturebox since the NOT XOR operation can be used to erase the old box.
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder

Last edited by BillSoo; 03-08-2005 at 05:11 AM.
Reply With Quote
  #4  
Old 03-08-2005, 05:11 AM
BillSoo's Avatar
BillSoo BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

Here is some example code with a picturebox on a form:
Code:
Option Explicit Dim StartX As Single Dim StartY As Single Dim LastX As Single Dim LastY As Single Dim oldMode As Integer Private Sub Form_Load() Dim i As Integer Dim mx As Integer Dim my As Integer Picture1.ScaleMode = vbPixels Picture1.AutoRedraw = True mx = Picture1.ScaleWidth my = Picture1.ScaleHeight For i = 1 To 30 Picture1.Line (Rnd() * mx, Rnd() * my)-(Rnd() * mx, Rnd() * my) Next i End Sub Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) StartX = X LastX = X StartY = Y LastY = Y oldMode = Picture1.DrawMode Picture1.DrawMode = 10 'not xor pen Picture1.Line (StartX, StartY)-(LastX, LastY) End Sub Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button Then Picture1.Line (StartX, StartY)-(LastX, LastY) LastX = X LastY = Y Picture1.Line (StartX, StartY)-(LastX, LastY) End If End Sub Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Picture1.Line (StartX, StartY)-(LastX, LastY) Picture1.DrawMode = oldMode End Sub
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->