473,320 Members | 2,145 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,320 software developers and data experts.

Erase function in need of tune-up

Hey all.

I have a whiteboard type program.

I have 2 picturebox's (needed for their mousemove/mousedown events)

Picture1.Picture = MyPicture

' Here is my hidden picture used to replace (on erase) Picture1
Picture2.Picture = MyPicture
Picture2.Enable = False

Both load the same picture, but one is hidden.

When one draws on Picture1, all is well.
When they erase when they draw, basically it copies the X/Y from
Picture2, and puts it back on Picture1.

I have some code to do this. works well, however it seems to carry alot of
overhead.
Sometimes the program blows out completly when erasing with a large 'brush
size'

Is there a more effecient way of doing this other than the way I am?

The code I have for this is the following:

' ----------------------------------------------------------------
' Start Code
'
' General Declarations
Private Declare Function GetPixel Lib "gdi32" _
(ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Private MyBrushSize As Long

Private Sub Picture1_MouseDown _
(Button As Integer, Shift As Integer, X As Single, Y As Single)

' Right-Click is Erase
If Button = 2 Then
MyBrushSize = 2
If BrushSize(0).Value = True Then MyBrushSize = 3
If BrushSize(1).Value = True Then MyBrushSize = 5
If BrushSize(2).Value = True Then MyBrushSize = 10
Call PenErase(X, Y, MyBrushSize)
End If
End Sub

Private Sub Picture1_MouseMove _
(Button As Integer, Shift As Integer, X As Single, Y As Single)

' Right-Click is Erase
If Button = 2 Then
MyBrushSize = 3
If BrushSize(0).Value = True Then MyBrushSize = 3
If BrushSize(1).Value = True Then MyBrushSize = 5
If BrushSize(2).Value = True Then MyBrushSize = 10
Call PenErase(X, Y, MyBrushSize)
End If
End Sub
Private Sub PenErase(X As Single, Y As Single, Optional width As Long)
Dim MyX As Single, MyY As Single
Dim maxXy As Integer
Dim OldWidth As Long

OldWidth = Picture1.DrawWidth
Picture1.DrawWidth = 1

If width Then
maxXy = width
Else
' I have 3 options for brush sizes
If BrushSize(0).Value = True Then maxXy = 3
If BrushSize(1).Value = True Then maxXy = 5
If BrushSize(2).Value = True Then maxXy = 10
End If

Picture1.PSet (X, Y), GetPixel(Picture2.hdc, X, Y)

For MyY = 1 To maxXy
Picture1.PSet (X, Y + MyY), GetPixel(Picture2.hdc, X, Y + MyY)
Picture1.PSet (X, Y - MyY), GetPixel(Picture2.hdc, X, Y - MyY)

For MyX = 1 To maxXy
Picture1.PSet (X - MyX, Y), GetPixel(Picture2.hdc, X - MyX, Y) '
Picture1.PSet (X - MyX, Y - MyY), GetPixel(Picture2.hdc, X -
MyX, Y - MyY)
Picture1.PSet (X + MyX, Y - MyY), GetPixel(Picture2.hdc, X +
MyX, Y - MyY)
Picture1.PSet (X + MyX, Y), GetPixel(Picture2.hdc, X + MyX, Y)
Picture1.PSet (X + MyX, Y + MyY), GetPixel(Picture2.hdc, X +
MyX, Y + MyY)
Picture1.PSet (X - MyX, Y + MyY), GetPixel(Picture2.hdc, X -
MyX, Y + MyY)
Next MyX

Next MyY

Picture1.DrawWidth = OldWidth
End Sub

' End Code
' ----------------------------------------------------------------

Any help would be appreciated. Thanks :c)


Jul 17 '05 #1
1 2336
To C. Alexander

I wanted to write back to you on this an another of your
postings "Using 2 instances of Line and PSet on same image?"
about a Whiteboard. I think one of our commercial components
"MetaDraw" may really be very helpful to you but your return
address from posting is not valid ( even without NoSpam).
If you are interested please write to me by e-mail with a copy
of this note and I'll send you some informaiton. Really not
Spam but specifically directed to what you are trying to do.

* * Please include a copy of this note with your reply

Jeff Bennett
Je**@Bennet-Tec.Com

Bennet-Tec Information Systems, Inc
50 Jericho Tpk, Jericho, NY 11753
Phone 516 997 5596, Fax - 5597
WWW.Bennet-Tec.Com

RELIABLE Component Software
and Software Development Services
* TList/Pro * ALLText HT/Pro * MetaDraw *

====================== ======================
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: s | last post by:
Here is a snippet of my code: <code> list< MyClass * >outgoing_pool; MyClass* GetWaitingObject(string freq) { MyClass *temp_ptr = NULL; list<MyClass*>::iterator i;
26
by: Pieter Thysebaert | last post by:
Hello, I've got a question conerning erasing key-value pairs from a std::map while iterating over it. According to the STL docs, erasing an element in a map invalidates all iterators pointing...
5
by: Billy Patton | last post by:
I have a polygon loaded into a vector. I need to remove redundant points. Here is an example line segment that shows redundant points a---------b--------c--------d Both b and c are not...
1
by: GGerard | last post by:
Hello I am working with Access 2000 I have two tables joined on a one to many relationship between two fields: Table1:FieldID (one) is joined to Table2:FieldMyID (many) Field Properties...
10
by: Piotr | last post by:
In Effective STL item 9 "Choose carefully among erasing options", it has this example: bool badValue(int x); // returns whether x is 'bad' c.erase ( remove_if(c.begin(), c.end(), badValue),...
8
by: olanglois | last post by:
Hi, I was asking myself to following question. What is better to erase an element from a STL map: calling (option #1) size_type erase(const key_type& k) or calling (option #2)
6
by: catphive.lists | last post by:
Is there a way to call erase(iter) on a list without invalidating the iterator? Can I make a copy of an iterator and then move forward the original without moving the copy? I'm aware of the...
6
by: alon | last post by:
I got the following situation: I have a few lists of integers, and I have an iterator pointing to one of the elements. I don't have a pointer to the list itself ! All I want is to remove the...
3
by: noone | last post by:
string operator()(const bool clean=true) { string rv; MPEGQUEUE::reverse_iterator i=thequeue.rbegin(); MPEGQUEUE::reverse_iterator t=thequeue.rend(); while (i!=thequeue.rend()) { if...
12
by: Philip Mueller | last post by:
Hi, I am using multiple stl::list s of different types. Now I want to write a function list<type>::iterator s_erase(list<typel, list<type>::iterator it) that takes an iterator and deletes...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.