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?
Related
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
I am working on a personal home inventory database. On one of the forms called Update Location, there is an image of the floor plan of the condo and then on top an image of location flag (pin icon) indicating where the location is in the condo.
For example:
Room: Den
Location: Top of desk
Flag is at point
LeftCoordinate.Value (X) and
TopCoordinate.Value (Y).
I have a toggle button then allows me to click on the map and sets a new X and Y position for the flag based on where I click on the map.
However, when I do this the flag image disappears behind the floor plan image until I click on another part of the form and then it is in the right spot. I am fairly new to VBA (especially in Access). Is there a way I can get the flag image on top?
I have tried searching Google but all the examples tend to be for one image and never an image over another image.
Private Sub Draw_Location_Icon()
Me.Painting = False
LeftStartPoint = 5292 ' 3.675" Left corner of floor plan attachment
TopStartPoint = 837 ' 0.5826" Top corner of floor plan attachment
IconHalfWidth = 180 ' 0.125" Half the icon width
IconFullHeight = 360 ' 0.250" Full height of icon
Me.Location_Icon.Visible = False
If Me.LeftCoordinate.Value > 0 Or Me.TopCoordinate.Value > 0 Then
Location_Icon.Left = LeftStartPoint - IconHalfWidth + Me.LeftCoordinate.Value
Location_Icon.Top = TopStartPoint - IconFullHeight + Me.TopCoordinate.Value
Me.Location_Icon.Visible = True
End If
Me.Painting = True
End Sub
As I stated currently the floor plan image is on top of the flag when I move the location flag but it is fine once I click on another part of the form. I would like the form to refresh with the floor plan on bottom and flag on top.
I am sure I am missing a small item to either set the orders of the image or perhaps I can get the VBA code to "click" somewhere else on the form and make the flag appear on top?
Any help is greatly appreciated.
I am trying to make a review game in PowerPoint 2007. I would like to be able to have two text fields where, in the show, the person controlling the game would then enter a team name in the two text fields. It would then save the data and then, on the next slide, show the team names on opposite sides of the presentation. I would imagine it would take the input from the text field, save it to a variable, and have a label with the text of that label equal to the input of the text field.
Before Reading this
"SlideX" = the Slide that Stores your Values
SlideO = AnySlideNumber
Ok First you want to make 1 slide that is hidden. to change the slide without opening this one you need to use hyperlinks for example, change slides with a Image button with hyperlinks or you could make a Developer Button that changes slide with ActivePresentation.SlideShowWindow.View.GotoSlide (SlideO)
in the one slide that is not hidden that inputs the team names make two labels, that will be editited and name them Like "Team1" and "Team2" or something like that. ok here Double click any of them and you'll get the code for it, just ignore that and paste this
Private Sub Save()
' Change X to The Slide that stores the numbers!
SlideX.SaveValuesIntoText Team1.Caption Team2.Caption
End Sub
after you have done that go a head and Create the Slide that stores the values Eg. the slide where you input your names (p.s. i like your idea) make two Textbox's named "Team1Name" and "Team2Name" with 2 button's (1 = Save, 2 = Nextslide) once you done that also open up thats code and paste this in
Public Function SaveValuesIntoText(Team1 As String, Team2 As String)
Team1Name.Caption = Team1
Team2Name.Caption = Team2
End Function
If done correctly you should of had the values saved into the powerpoint slide, and now you can just simple retrieve them with
Private Sub RetrieveValues()
Team1 = X.Team1Name.Caption
Team2 = X.Team1Name.Caption
Label1.Caption = Team1
Label2.Caption = Team1
End Sub
that should do it. P.s. if you want to retreive the Values Automaticly in the Slide that displays the teams you need to add this Code into it
Public Sub OnSlideShowPageChange(ByVal Wn As SlideShowWindow)
If Wn.View.CurrentShowPosition = 1 Then
RetrieveValues
End If
End Sub
IF THIS DOESNT WORK, i made a syntax error tell me what it is and ill correct it!
After adding a large number (150?) of callouts (simple text boxes in the margin, with no borders) to a Word 2010 .docx file with mirrored odd/even pages, I needed to adjust some text. This shortened the document enough to remove a page, and therefore all the odd pages following the adjustment became even, and the even became odd. The text boxes did not move, and now they all fall off the edge of the paper, where it is difficult even to find them all due to the text outside the bounds of the paper not being shown in the document, let alone to move them to their correct positions in the opposite margin. Moreover, I may need to adjust text again and the problem could recur.
I'm looking for an automated way, using VBA (in which I am decidedly a rank novice, though an expert programmer), to record some macro to say, "Center all existing text boxes in the wide margin, and make the width consistent." Something like,
As a text box, if I find myself on an odd page, make the left edge of the text box 0.5" from the left edge of the page; if I am found on an even page, make the left edge of the text box at the right margin + 0.5". My height should be consistent, and my height can stay what it was already.
I need to know in what units to express the Top and Width values, how to determine if I am on an odd/even page, and how to find all the text boxes.
Can anyone help?
Sub AdjustTextBoxes()
Dim myTextBox As Shape
Dim PageNumber As Integer
For Each myTextBox In ActiveDocument.Shapes
If myTextBox.Type = msoTextBox Then
myTextBox.Select
PageNumber = Selection.Information(wdActiveEndPageNumber)
'Mod returns the remainder (rounded up) of the division.
'No remainder is even. Any remainder is an odd page.
If PageNumber Mod 2 = 1 Then
With myTextBox 'Odd numbered pages
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.Left = InchesToPoints(0.5)
End With
Else
'Because wdRelativeHorizontalPositonPage measures from the left
'edge of the page the positioning for text boxes on even pages
'is not based on the distance from the right margin.
'So below .Left = 8.5" (page width) - (1" (textbox with) + .5" (distance
'from the right edge of the page). The measurement for .left below
'will need to be altered based on the position from the right edge
'of the page and the width of your text boxes and pages.
With myTextBox 'Even numbered pages
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.Left = InchesToPoints(7)
End With
End If
End If
Next
End Sub
I have a word doc with a bunch of ActiveX Control buttons or whatever on it, and each time a button is clicked, a corresponding image needs to be displayed in a popup box.
I have a userform called ImageForm, and this is what I'm doing right now:
Sub Button_Clicked()
ImageForm.Picture = LoadPicture("appropriate_image_path")
ImageForm.Show
End Sub
Each of these images has a width of 8.5 inches, but their heights can vary anywhere from like 3 to 20 inches (they're snippets of a pdf). So I've set the width of the userform to a little more than 8.5 inches, and that looks fine. But I need to be able to scroll vertically through the image in the userform, since some of the images could be taller than a user's monitor.
I'm completely stuck on this. What I've tried so far is adding a frame to the form, then adding an image control inside the form, and setting the "ScrollBars" property of the frame to vertical. Then instead of using "ImageForm.Picture = ..." I use "ImageForm.ImageControl.Picture = ..." But it doesn't work.
Any insight here would be greatly appreciated. Hopefully this question is clear enough, I've only been using VBA for a month or so now. (I miss Java so, so much)
Thanks!
Here is a neat little trick based on one of my posts
The idea is to ensure that the image control is in frame control and the image control doesn't have a border. Also the image control's PictureSizeMode is set to fmPictureSizeModeClip so that we can scroll the image
SNAPSHOT (DESIGN TIME)
SNAPSHOT (RUN TIME)
CODE
Private Sub UserForm_Initialize()
With Frame1
'~~> This will create a vertical scrollbar
.ScrollBars = fmScrollBarsVertical
'~~> Change the values of 2 as Per your requirements
.ScrollHeight = .InsideHeight * 2
.ScrollWidth = .InsideWidth * 9
End With
With Image1
.Picture = LoadPicture("C:\Users\Public\Pictures\Sample Pictures\Desert.jpg")
.BorderStyle = fmBorderStyleNone
.PictureSizeMode = fmPictureSizeModeClip
End With
End Sub