VBA Excel: How can I make one form change the position of another form? - forms

I have two forms, frmPE and frmCRE. They are modal.
frmCRE has a button "Edit PE" that will open formPE (instance of frmPE).
If I don't play with the positions, formPE opens centered on top of frmCRE.
I would like to position them side by side so I can see both at once.
When I open frmPE, I can still see frmCRE but not touch it. That's OK.
' This code is in cmdEditPE
Set formPE = New frmPE
Load formPE
If Not formPE.bInitialize(vbFalse) Then Err.Raise glHANDLED_ERROR
Me.Left = 100 ' move frmCRE to the left so I can see it
formPE.Left = Me.Left + Me.Width ' move frmPE to move to the right side of frmCRE (bad)
formPE.Show
I think the problem is that when formPE opens, it uses its default left setting. From within PE, I can see that me.Left = 0 even though it was set before the show.
Is there a way I can use the formPE.bInitialize routine to see that frmCRE is open and find out its LEFT and WIDTH so I can set formPE.Left correctly, or a way I can set it from frmCRE as I was trying to do above?
Thanks
Shari

Use the Activae event of frmPE to move itself, but only if frmCRE is visible.
In frmPE
Private Sub UserForm_Activate()
If frmCRE.Visible Then
Me.Left = frmCRE.Left + frmCRE.Width
End If
End Sub

Related

Prevent Unity GameObject losing focus when Shift-Clicking to add new point in Custom Editor

I am writing a Custom Editor in Unity - at present I can just drag some points around and the editor draws a line between them all.
I have implemented pressing Shift-Click to add a new point, and this works fine - except...
If I press shift, then click , my new point appears.
If I release shift, then release the mouse button, all is well.
If I release the mouse button first though, the game object that was highlighted (and contains all of my points) loses focus - nothing in the hierarchy has focus - so I lose my handles and the editor is no longer active.
Some of the relevant code
if (guiEvent.type == EventType.MouseDown && guiEvent.button == 0 && guiEvent.shift)
{
var pos = GetMousePositionOnXYPlane(mouseRay);
var cp = new ControlPoint(ControlPointType.Flat);
cp.Positions.Add(pos);
level.AddControlPoint(cp);
}
I have tried adding
Selection.activeGameObject = _level.gameObject;
immediately after the adding of the control point, to no avail.
If I use Shift / right-click focus is not lost
If I use just Left Click, focus is not lost.
I'm at a loss what to try next...

LibreOffice macro showing simple TextBox shape

I cannot figure out (or find an example) how to perform the following simple thing in the LibreOffice Calc 6.2:
I have a drawing shape (e.g. a simple rectangle) in a sheet (call it ShapeA) and a textbox shape in another sheet (call it TextboxB). I want to do the following: when I click on the ShapeA, the TextboxB must appear on the screen (without changing the current sheet, maybe in a dialog box) and then be closed with a mouse click.
I guess the macro associated with ShapeA could look something like this:
Sub Main
oDrawPage = ThisComponent.getDrawPage()
oTb = oDrawPage.getByName("TextBoxB")
oTb.show()
End Sub
Could someone advise what I should put into this macro to accomplish the described task?
UPDATE: What I want to accomplish ( in reply to Jim K.).
I have a very cluttered diagram with many shapes. Each shape has some textual information associated with it. There is not enough space on each shape or around it to contain this info. So there is must be a way to display this info about each shape. Also this information should be displayed in a preformatted way (it contains code and other structured info).
My plan is to create a textbox with the relevant information for each diagram shape, place these textboxes in other sheet and have a possibility, when viewing diagram, to click on any shape and view the associated info in the poped up textbox without leaving the diagram, and then close the textbox with a simple action (e.g. by clicking on it).
Does this task sound feasible to be realized with the LO's shapes and macros?
How about this: Put everything on the same sheet but keep the text boxes hidden until needed.
Use the following code adapted from https://ask.libreoffice.org/en/question/93050/how-can-i-hideshow-a-shape-of-my-spreadsheet-using-a-macro/.
Sub ShapeClickedA
ShowHideShape("TextBoxA")
End Sub
Sub ShapeClickedB
ShowHideShape("TextBoxB")
End Sub
Sub ShowHideShape(shapeName As String)
oDrawPage = ThisComponent.getSheets().getByName("Sheet1").getDrawPage()
For iShape = 0 To oDrawPage.Count - 1
oShape = oDrawPage.getByIndex(iShape)
If oShape.Name = shapeName Then
If oShape.Visible Then
oShape.Visible = 0 'Not Visible
Else
oShape.Visible = 1 'Visible
End If
End If
Next iShape
End Sub
If you haven't yet, set the names of the text boxes by right-clicking and choosing Name... Then right click on both ShapeA and TextBoxA and assign the macro ShapeClickedA. Do likewise for other pairs of shapes. The result works like this:
Before anything is clicked.
Click on ShapeA. (To close it again, click on either ShapeA or TextBoxA). ShapeB functions similarly.
It's also possible to display both at the same time.

Swapping Between Forms VBA + Centering on Duel Screens

I am trying to have my Main Menu and Subsequent forms operate together properly. what I'm currently having happen is on the second click of Employee_Form button the form loads back up but then Jumps to the end of QueryClose Sub and closes the form for some reason!
I Have the following code :
This activates when i click the relevant button to load the employee_Form.
Private Sub EmpChecker_Click()
Main.Hide
Employee_Form.Show False
End Sub
This then activates when i close the Employee form.
Private Sub UserForm_QueryClose()
Employee_Form.Hide
Main.Show
End Sub
As i say when i click EmpChecker Button again the form will show up in debug but then jump to the end of the above code and close the form.
Any ideas? I'm a little mythed as to why this happens.#
My Next Question is about centering the forms. We use 4 screens at work attached to one Computer I Have tried all 4 options in properties of each form but each one i use the forms seem to center in the Second Screen. its rather annoying! is there anyway to just get them to load into the default screen that Excel is in!?
Try removing the False argument
Private Sub EmpChecker_Click()
Main.Hide
Employee_Form.Show
End Sub
To center your UserForm, there's no automatic way to do, you need to do using some code.
With UserForm1
.StartUpPosition = 0
.Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
.Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
.Show
End With
To locate your user form in the right screen, you can ask for the current window position.
Hope this helps.

Move FlowLayoutPanel Controls via DragDrop

I have a FlowPanelLayout that can contain several UserControls called DataGridViewFilterSortElement. These controls look kind of like buttons, but different. I want the user to be able to click one of the DataGridViewFilterSortElement controls and drag it to another position (index) in the FlowLayoutPanel.
Is there a way to see the control physically moving as the user drags it to another position? In other words, is there a way to take a "snap shot" of the control that is being dragged (instead of a shadowed box) which would show the actual control moving as the cursor moves? Also, as the control is being dragged I'd like to have the other controls position to shift automatically instead of waiting for the user to drop the drag to see the shifts.
For example, let's say the FlowPanelLayout contains 3 controls and the user wants to drag the first control to the third controls position. So the user clicks and holds the first DataGridViewFilterSortElement, then drags over the second control, which causes the second control to shift to position 1 of 3, then the user drags over the third control, which causes the third control to shift to position 2 of 3, then the user drops the control in position 3. Is this possible? The little code I do have is below.
Here is a short little video that shows what I want to do: http://www.youtube.com/watch?v=YhyTni6KH0Q
Private Sub lblDescription_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown, lblDescription.MouseDown
' if the user left clicks and holds the element begin a DragDrop action
If e.Button = Windows.Forms.MouseButtons.Left Then
Me.DoDragDrop(Me, DragDropEffects.Move)
End If
End Sub
Private Sub SortFlowLayoutPanel_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragOver
e.Effect = DragDropEffects.Move
End Sub
Private Sub SortFlowLayoutPanel_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles SortFlowLayoutPanel.DragDrop
If e.Data.GetData(GetType(DataGridViewFilterSortElement)) IsNot Nothing Then
'Current Position
Dim myIndex As Integer = Me.SortFlowLayoutPanel.Controls.GetChildIndex(CType(e.Data.GetData(GetType(DataGridViewFilterSortElement)), DataGridViewFilterSortElement))
'Dragged to control to location of next picturebox
Dim element As DataGridViewFilterSortElement = CType(e.Data.GetData(GetType(DataGridViewFilterSortElement)), DataGridViewFilterSortElement)
Me.SortFlowLayoutPanel.Controls.SetChildIndex(element, myIndex)
End If
End Sub
Private Sub SortFlowLayoutPanel_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles SortFlowLayoutPanel.DragOver
e.Effect = DragDropEffects.Move
End Sub
This page explains how to do what you want. I tried it, looks pretty good.
http://www.vbdotnetforums.com/gui/45818-flowlayoutpanel-repositioning-object.html

How do I program frames?

Like if i click on a fridge door and it opens, or click on a chest and the top slides off.
Add a ClickDetector inside of it, and add a script that does what you want to do. To open it sideways you can do this:(It might not turn the right way)
for i = 1, 90 do
script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0, math.pi*90/1, 0)
wait()
end
Add a clickdetector, and script it so onclick the parent part moves from one place to another.