vba power point erase all ink - vba

I want to erase all ink on slide show powerpoint with vba.
My first strokes used a black pen. Then I run my code (erase all ink) and I used red pen, but when I used the red pen in a crossed position with the black pen, my first strokes (black color) appears.
mycode :
Sub erase_all_ink ()
ActivePresentation.SlideShowSettings.Run.View.EraseDrawing
end sub
any idea or another code?

Related

Overriding VB.Net TrackBar control Property -- no error, but not working

All,
If a TrackBar control on a Windows form is selected by mouse, the keyboard left/right arrow keys can be used to decrement/increment its value respectively. Unfortunately, selecting the control causes an unsightly focus box to appear around it.
I would like to override the control's ShowFocusCues() Property to hide the focus box but retain the ability to use the keyboard keys. The following code does not throw an error, but also does not return the result I wish to achieve. Please can you help?
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim myTrackBar As CustomTrackBar = New CustomTrackBar
With myTrackBar
.Top = 100
.Left = 100
.Width = 200
.Minimum = 3
.Maximum = 25
.Value = 7
End With
Me.Controls.Add(myTrackBar)
End Sub
End Class
Class CustomTrackBar : Inherits System.Windows.Forms.TrackBar
Protected Overloads Overrides ReadOnly Property ShowFocusCues() As Boolean
Get
Return False
End Get
End Property
End Class
I just would like to preserve keyboard functionality if doing so is straightforward
I don't doubt the way Jimi has suggested in the comments is more correct, but it's really straightforward to put a eg a 300x50 sized trackbar inside an eg 290x40 sized panel, positioned at -5,-5 so the focus box is visually cut off.
Note that I don't guarantee these pixel sizes are exact/correct so they should be regarded as "for illustration of the point purposes only"; I'm on a cellphone and cannot measure the image I created to demo this, but it looks like the focus rect is less than 5 pixels...
In this image the cutoff is more than 5 pixels - I deliberately positioned the trackbar so that part of the slider is cut off to demonstrate that controls inside panels, that overhang the bounds of the panel, have their visual area trimmed:
The form background is blue, the panel grey and the trackbar is yellow
add a panel to the form
set your trackbar background to red temporarily so you can see its bounds
drag the trackbar into the panel then drag it again to the top left corner
use the arrow keys eg 5 times in the up and left directions to push it
size the panel to the bottom right of the trackbar
hold shift and use up/left again to resize the panel down another 5 pixels in each dimension
if you're resizing this trackbar set the anchor properties appropriately on the trackbar and panel
revert the background
If you don't use anchor for resize/don't know how it works, it's simplest to consider it like:
Any edge that is anchored maintains the same number of pixels between that edge and the same edge of the container it is in. Controls try not to resize if they can
This means that anchoring left and right will cause a control to stretch if the window gets wider. Anchoring right only causes the control to slide as the window gets wider

Powerpoint VBA makro moving in slideshow mode w. 2 screens + VBA textfields disabled

My VBA makros in PP works well in slideshow mode on 1 screen, however, disfunctions w. 2 screens.
Makros either move around on slide or input textbox doesn't work (not able to add input)
The slideshow consist of a textbox input box, a commandbutton, and a textbox output box.
When I change settings on the screens (e.g. change reolution, or which screen to be the main screen), I can make it work again.
However, all these change of setting and testing is not be possible when doing presentations for a customer.
Private Sub CommandButton1_Click()
TextBox2 = TextBox1 * 0.025
End Sub
Private Sub TextBox1_Change()
End Sub
Private Sub TextBox2_Change()
End Sub
I expect the macros to be at place on the screen no matter the screen.
OLE and OLE Controls are resolution-dependent. PowerPoint can calculate the control's positions differently when resolution changes or when used on mixed-resolution multi-monitor setups. You could possibly get around this by using a VBA userform for controls instead of placing them on the slide.

Multiple picture box collision using ".Bounds.IntersectsWith"

I have created a subroutine for collision between picture boxes.
I have 3 different colours, each with 10 corresponding picture boxes
(which totals 30 picture boxes).
Ideally I would like it so when the red picture boxes collide with purple or yellow picture boxes, my sub routine executes. Same with purple and yellow.
Here is my code:
Public Sub PurpCollision()
'
For Each PictureBox In PurpList
Collide = False
If purpPoint1.Bounds.IntersectsWith(PictureBox.Bounds) And chkHealth.Checked = False Then
Collide = True
Else
Collide = False
End If
However I am struggling with this section
purpPoint1.Bounds.IntersectsWith(PictureBox.Bounds)`
How can I set it to list 10 picture boxes,
and if they intersect with picture boxes from YellowList or Red List collide is true?

How do I check if a color has a certain amount of red (visual basic 2010)

I'm trying to make an application where it detects if your mouse is on an object that is red. Not 100% red, but red.
currentclr = myBmp.GetPixel(MousePosition.X, MousePosition.Y)
this is what I use to find what color my mouse is on
For example, let's say I hover my mouse over a red object, if I convert it to string, it looks something like this
Color [A=232, R=201, G=15, B=15]
How do I check if the R is greater than 150?
Use:
if (currentclr.R > 150)

Programmatically determine background of image (logos, etc) and make transparent?

I'm attempting to write a solution so that my user's can "watermark" their Images with their Company Logo. I've got the actual watermarking part done and working so now I'm creating the "upload logo" feature so that they can provide me with the Logo they wish to appear watermarked onto their Images.
I'm using VB.NET and this will probably end up in a Web Service that accepts the Logo JPG file, and returns the "altered" Logo. What I need to happen in this Web Service is:
1) Gray-scale the image. Which I have working as well, thanks to this article.
2) Make the background transparent (so the logo looks clean when watermarked onto an image). This is where I'm stuck.
I think for the most part, any logos that are uploaded will have a generic white background but I can't assume that. Is there a way to somehow detect the background of an image or the background colors, so that I may make those colors transparent?
I've downloaded and ran this project from code.google.com, called Transpoint, which is pretty much what I need except I won't be able to have this as a stand-alone app. Also, I think this is written in Python which is foreign to me.
So basically what I need is just a way to determine the background on an Image (if that's even possible?) or even just the background colors so that I may make them transparent. Any help/advice/suggestions would be greatly appreciated!
Thanks,
Lloyd
You could do something like reading the upper-left pixel and assuming that that pixel is representative of the background color, and then iterating through the image and setting the alpha value of each matching pixel (matching by color) to 0.
I can pretty much guarantee you, however, that the result will be awful. For transparency to work properly and look good, the image needs to support partial transparency, such that some pixels are completely transparent whereas some are only partially transparent. Any algorithm that takes a non-transparent image and sets only one color in the image to fully transparent is going to end up with jagged edges.
Most companies I've ever dealt with have versions of their logos done by professional artists, with smooth, partial transparency. You'd be much better off just requiring customers to submit a logo with transparency than trying to make a non-transparent image into a transparent one with code. Sorry, but this just doesn't work.
I think this would actually work (sorry it's just a description):
Assuming the upper-left corner pixel is the image's background color, you could iterate through each pixel in the image and set the alpha to 0 if the pixel color matches the background color (either exactly or within some threshold color distance). This would then leave you with an image with a transparent background but jagged edges when you re-draw it on a different-color background. Also, if the background color is present anywhere inside the image itself, it will be turned transparent, which you don't want.
To fix the latter problem, your algorithm should start scanning each row of the image from left to right, and stop when it reaches a non-background color pixel; at this point it should start on the same row and scan right to left until reaching a non-bg pixel.
To fix the edges, you can just blur the alpha values of the bitmap. Basically, you re-calculate the alpha value of each pixel as the average of 9 pixels (itself and the 8 pixels surrounding it, and just the alpha values - not the rgb values). To prevent sequencing artifacts, you would have a temporary array to store the averaged pixel values, which you would then copy back into the image's alpha values at the end of the process.
Also, there's probably one or more third-party tools that do this (is LEAD Tools still around?).
#MusiGenesis (and anyone else who may be interested) here is what I did to (kind of) solve my problem. I basically followed the first half of your idea. I've created a function that will accept a bitmap, check each pixel against the first pixel at (0,0) - using a threshold of 10 for each RGB color. For each color within that threshold, the pixel is made transparent. Here is my code, which seems to work alright for the few images I've tried it with:
Private Function TransparifyBackground(ByVal bmp As Bitmap) As Bitmap
Dim temp As Color
Dim background As Color = bmp.GetPixel(0, 0) 'top left will be assumed background color
For y As Integer = 0 To bmp.Height - 1
For x As Integer = 0 To bmp.Width - 1
'get the pixel for this position:
temp = bmp.GetPixel(x, y)
If ColorsMatch(background, temp) Then
'Make the Alpha value 50 for each pixel, leaving the other colors
Dim newColor As New Color
newColor = Color.Transparent
bmp.SetPixel(x, y, newColor)
End If
Next
Next
Return bmp
End Function
Private Function ColorsMatch(ByVal background As Color, ByVal temp As Color) As Boolean
Dim nThreshold As Integer = 10
Dim temp_R As Integer = CInt(temp.R)
Dim temp_G As Integer = CInt(temp.G)
Dim temp_B As Integer = CInt(temp.B)
Dim R As Integer = CInt(background.R)
Dim G As Integer = CInt(background.G)
Dim B As Integer = CInt(background.B)
'check the difference of each value against our threshold:
If ((temp_R - R) < nThreshold) AndAlso ((temp_G - G) < nThreshold) AndAlso ((temp_B < B) < nThreshold) Then
Return True
Else
Return False
End If
End Function