I am writing a programme to be used internaly within our company and have come across the problem below:
How can you get a Child form to centre on the screen when using the MDI parent maximised form as the backgroung
In the MDI child screen, create a Form_Initialize function like this:
Private Sub Form_Initialize()
Me.Left = (MDIForm1.ScaleWidth - Me.Width) / 2
Me.Top = (MDIForm1.ScaleHeight - Me.Height) / 2
End Sub
Of course, you'll need to substitute the name of your MDI form where you see MDIForm1 in the code above.
From Microsoft:
"The initial size and placement of MDI child forms are controlled by the Microsoft Windows operating environment unless you specifically set them in the Load event procedure."
From the parent:
Private Sub MDIForm_Load()
CenterChildForm MDIForm1, Form1
End Sub
Sub CenterChildForm(Parent As Form, Child As Form)
If Parent.WindowState = 1 Then Exit Sub 'The Parent is minimized, centering is invalid.
Child.Top = (Parent.ScaleHeight - Child.Height) / 2
Child.Left = (Parent.ScaleWidth - Child.Width) / 2
End Sub
From the Child:
Private Sub Form_Load()
Me.Left = (MDIForm1.ScaleWidth - Me.Width) / 2
Me.Top = (MDIForm1.ScaleHeight - Me.Height) / 2
End Sub
Select from the properties in the IDE on the bottom right the WINDOWS PROPERTY - CENTER PARENT. It may be named something a little difference but is in the drop down with CENTER SCREEN
EDIT: I think it is WINDOWS POSITION - CENTER PARENT
As an addition to the above use the me.Move [left], [top], [width], [height] method
it is quicker and performs the positioning in a single action.
Related
From Windows Vista, although some windows are not resizable, but the borders are bold. Is there a way to make bold window borders(unresizable) in VB6?
Your Form's BorderStyle property dictates if the window will be resizable or not. You can chose between the following:
0 - None (no border)
1 - Fixed Single
2 - Sizable
3 - Fixed Dialog
4 - Fixed ToolWindow
5 - Sizable ToolWindow
As far as the visual appearance of the window in Vista, the resizing behavior shouldn't be affected.
Edit
If you want to prevent the form from resizing while keeping the resizable border style, you can override the Height and Width in the Form_Resize event:
Private Sub Form_Resize()
Me.Width = m_lngOriginalWidth
Me.Height = m_lngOriginalHeight
End Sub
You will need to store the original Height and Width at some point. You can do this in Form_Load or declare constants to store the original values:
Dim m_lngOriginalWidth As Long
Dim m_lngOriginalHeight As Long
Private Sub Form_Load()
m_lngOriginalWidth = Me.Width
m_lngOriginalHeight = Me.Height
End Sub
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am making video lessons using MS PowerPoint.
Unfortunately, my productivity is greatly reduced by the fact that during a slideshow, it takes:
4 clicks to change from a red pen to a blue highlighter
Then, changing to a green pen takes a further 4 clicks.
This is becoming a nuisance as these 3 second bursts of inactivity have to be tediously video edited to make lessons engaging.
Keyboard shortcuts (Ctrl-I and Ctrl-P) are only useful if I use only one colour each for the pen and highlighter, and merely switch between the two.
I wanted to know if anything exists to permanently display a colour palette at the bottom of each slide.
I know this is possible, because I have used OfficeOne InkTools which works fine on PowerPoint 2013, but it does not have all the features I would like.
I have experience coding, and am willing to make this feature myself if I was walked through which Objects I needed to modify etc.
Thanks in adavance.
If you wanted to have some kind of dynamically visible/hidden interactive toolbar during your slideshow like the one above, you could add a form to your project with as many buttons as you require colours and call a Sub to open that form when you click on an object on the slide (visible or not). To do this, add a shape to your slide (or master) and set it's mouse click action to run this macro in a standard module:
Sub ChangePenColour()
frmChangePenColour.Show
End Sub
Then create a form called frmChangePenColour and add 7 buttons to it called btn1 to btn6 and btnCancel.
Then add this code to the form:
' =======================================================
' Pen Colour Demo by YOUpresent
' Visit http://youpresent.co.uk for more PowerPoint stuff
' =======================================================
Option Explicit
Private Sub btn1_Click()
ChangePointerColor btn1.BackColor
Unload Me
End Sub
Private Sub btn2_Click()
ChangePointerColor btn2.BackColor
Unload Me
End Sub
Private Sub btn3_Click()
ChangePointerColor btn3.BackColor
Unload Me
End Sub
Private Sub btn4_Click()
ChangePointerColor btn4.BackColor
Unload Me
End Sub
Private Sub btn5_Click()
ChangePointerColor btn5.BackColor
Unload Me
End Sub
Private Sub btn6_Click()
ChangePointerColor btn6.BackColor
Unload Me
End Sub
Private Sub UserForm_Activate()
CentreForm Me
End Sub
Private Sub UserForm_Initialize()
With SlideShowWindows(1).View.Slide.Design.SlideMaster.Theme
btn1.BackColor = .ThemeColorScheme(msoThemeAccent1).RGB
btn2.BackColor = .ThemeColorScheme(msoThemeAccent2).RGB
btn3.BackColor = .ThemeColorScheme(msoThemeAccent3).RGB
btn4.BackColor = .ThemeColorScheme(msoThemeAccent4).RGB
btn5.BackColor = .ThemeColorScheme(msoThemeAccent5).RGB
btn6.BackColor = .ThemeColorScheme(msoThemeAccent6).RGB
End With
End Sub
Sub ChangePointerColor(lRGB As Long)
With SlideShowWindows(1).View
.PointerColor = lRGB
.PointerType = ppSlideShowPointerPen
End With
End Sub
Private Sub btnCancel_Click()
Unload Me
End Sub
' Centres a form wrt the PowerPoint application window
Public Sub CentreForm(thisForm As Object)
On Error Resume Next
' Position in the centre of the PowerPoint window
With thisForm
.Left = Application.Left + ((Application.Width / 2) - (.Width / 2))
.Top = Application.Top + ((Application.Height / 2) - (.Height / 2))
End With
If Err Then Debug.Print Err & Err.Description & " in CentreForm"
On Error GoTo 0
End Sub
Now when you run the slide show, you can click on your chosen active shape to open the colour picker and start annotating in that colour.
Then if you want that toolbar to appear automatically when the slide show starts and not disappear when a colour is clicked, you could addd this sub:
Sub OnSlideShowPageChange(ByVal Wn As SlideShowWindow)
frmChangePenColour.Show
End Sub
And change the form's ShowModal property to false.
You'll probably want to tweak the UI logic but this should be enough to get you going.
A couple of thoughts:
You can add a couple of VBA routines to your file, something like these (adjust the RGB values as you wish):
Sub Blue()
With SlideShowWindows(1).View.PointerColor
.RGB = RGB(0, 0, 255)
End With
End Sub
Sub Red()
With SlideShowWindows(1).View.PointerColor
.RGB = RGB(255, 0, 0)
End With
End Sub
Add more as needed for other colors.
Then draw a couple rectangles or other shape on the slide (or master) and assign each rectangle an action setting of RUN MACRO: Blue (or red or whatever).
You can make these transparent so it's not obvious to anyone viewing the presentation that there any shapes there.
Press Ctrl+A to change the pointer to an arrow (so you can click on things), click the shape for the color you want, then press Ctrl+P to turn the cursor back to a pen so you can draw ... in the selected color.
==================
Another totally different approach would be to add the annotations in advance on two different slides and transition between them or on one slide and animate them on as needed.
I've created a program that is fully functional and I have sent it to some clients. Some of them have really old computers with really low resolution and they can't access it easily since the form and the controls are oversized for them. Is there an easy way for me to make it to automatically resize both form and controls according to the resolution?
As I've said in the title, this is for Visual Basic 6.0. Thanks to all of you in advance.
You can store size and location of each control on the form, and move or resize controls according to your needs.
In the code below, I use "TabIndex" property as unique id for each control (I can't remember in my old VB6 memory if that's the right thing to do...).
I store the size of the form, and the size and location of each control in the Form_Load event.
Private lWidth As Long
Private lHeight As Long
Private Enum ePROPERTY
ep_Top = 0
ep_Left = 1
ep_Width = 2
ep_Height = 3
End Enum
Private aControlSize() As Long
Private Sub Form_Load()
Dim ctlTmp As Control
lWidth = Me.Width
lHeight = Me.Height
ReDim aControlSize(3, Form1.Controls.Count)
For Each ctlTmp In Form1.Controls
aControlSize(ctlTmp.TabIndex, ep_Top) = ctlTmp.Top
aControlSize(ctlTmp.TabIndex, ep_Left) = ctlTmp.Left
aControlSize(ctlTmp.TabIndex, ep_Width) = ctlTmp.Width
aControlSize(ctlTmp.TabIndex, ep_Height) = ctlTmp.Height
Next
End Sub
Then each time the form is resized (Form_resize event), you'll have to move or resize each control.
Some of them need to be anchored to the right or to the bottom (or both). Some need to be resized and moved. Others don't need nothing.
Private Sub Form_Resize()
Dim ctlTmp As Control
For Each ctlTmp In Form1.Controls
Select Case LCase$(ctlTmp.Name)
Case "text1"
' Text1 is anchored to the left and right borders of the form :
ctlTmp.Width = Me.Width - (lWidth - aControlSize(ctlTmp.TabIndex, ep_Width))
Case "command1"
' Command1 is anchored to the right border of the form :
ctlTmp.Left = aControlSize(ctlTmp.TabIndex, ep_Left) - (lWidth - Me.Width)
Case "check1"
' check1 is anchored to the bottom border of the form :
ctlTmp.Top = aControlSize(ctlTmp.TabIndex, ep_Top) - (lHeight - Me.Height)
End Select
Next
End Sub
Form loaded :
Form Resized :
Please be advised that my code is largely perfectible...
There's probably a more elegant solution that goes through overload each Control and to add properties/methods like the existing ones in dotnet.
I'm looking to have my excel sheet with a split in it (vertically) ensuring a set of controls stay on the left of the screen for easy access. Currently Im using this code to select and move to a cell, based on a list of headings I have in the A column.
Option Explicit
Dim trimProcess() As String
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim i As Integer
If Not Intersect(ActiveCell, Range("A6:A1000")) Is Nothing Then
If ActiveCell.Value <> "" Then
For i = 0 To UBound(trimProcess)
If ActiveCell.Value = trimProcess(i) Then
Cells(4, 4 * (i + 1)).Select
Cells(4, 4 * (i + 1)).Activate
End If
Next
End If
End If
End Sub
This works fine for what I need, but it only works in the active split view IE if I click a cell in A in the left split, it moves the left split view. I want it so that the changes only the right view, but cant find the code to do so. Is this possible?
i have written some Macros for Visio. Now I copied these to a Stencil called Macros.vss
How can I call my Macros now?
It all depends on what the macros do and how you'd like to call them. I'm going to assume they're simply macros that will execute something within the active Visio page.
By default in Visio VBA, any public subs with no arguments get added to the Visio Tools->Macros menu, in a folder named by the document holding the macros (in this case Macros) and then separated into folders by module name. If you're the only person using the macros then you probably don't need to do anything else.
However, since you put them in a vss file I'll assume you'd like to distribute them to other people.
There's something funny (and by funny I mean irritating) about Visio and how toolbars and buttons work, when added programmatically. Unfortunately, when you create a toolbar using the UIObject and Toolbar and ToolbarItem classes, Visio is going to assume the code you're calling resides in the active drawing, and cannot be in a stencil. So I can give you a little guidance on using those classes, but basically it consists of distributing a .vst template along with your .vss files, with just a single required sub in the .vst file.
So, instead of using a custom toolbar, you can attach code to shape masters in your .vss file that execute the code when they get dropped on a drawing document (using CALLTHIS and the EventDrop event in the shapesheet). With this method I just have a sub that gets called using callthis that takes a shape object as an argument, executes some code, then deletes the shape (if I don't want it around anymore).
And lastly, you can manipulate the Visio UI programmatically to add a toolbar and buttons for your macros. Below is some sample code, basically the way I do it with a solution I developed. As I mentioned above, the most important part of using this method is to have a document template (.vst) that holds a sub (with the below code it must be named RunStencilMacro) that takes a string as an argument. This string should be the "DocumentName.ModuleName.SubName". This sub must take the DocumentName out of the string, and get a Document object handle to that document. Then it must do ExecuteLine on that document with the ModuleName.SubName portion. You'll have to step through the code and figure some things out, but once you get the hang of what's going on it should make sense.
I'm not sure of any other ways to execute the macros interactively with VBA. I think exe and COM addons may not have this issue with toolbars...
Private Sub ExampleUI()
Dim UI As Visio.UIObject
Dim ToolbarSet As Visio.ToolbarSet
Dim Toolbars As Visio.Toolbars
Dim Toolbar As Visio.Toolbar
Dim ToolbarItems As Visio.ToolbarItems
Dim ToolbarItem As Visio.ToolbarItem
Dim TotalToolBars As Integer
Dim Toolbarpos As Integer
Const ToolbarName = "My Toolbar"
' Get the UIObject object for the toolbars.
If Visio.Application.CustomToolbars Is Nothing Then
If Visio.ActiveDocument.CustomToolbars Is Nothing Then
Set UI = Visio.Application.BuiltInToolbars(0)
Else
Set UI = Visio.ActiveDocument.CustomToolbars
End If
Else
Set UI = Visio.Application.CustomToolbars
End If
Set ToolbarSet = UI.ToolbarSets.ItemAtID(visUIObjSetDrawing)
' Delete toolbar if it exists already
TotalToolBars = ToolbarSet.Toolbars.Count
For i = 1 To TotalToolBars
Set Toolbar = ToolbarSet.Toolbars.Item(i - 1)
If Toolbar.Caption = ToolbarName Then
Toolbar.Visible = False
Toolbar.Delete
Exit For
End If
Next
' create toolbar
Set Toolbar = ToolbarSet.Toolbars.Add
Toolbar.Caption = ToolbarName
Dim IconPos As Long ' counter to determine where to put a button in the toolbar
IconPos = IconPos + 1
Dim IconFunction As String
IconFunction = """Macros.Module1.SubName"""
Set ToolbarItem = Toolbar.ToolbarItems.AddAt(IconPos)
With ToolbarItem
.AddOnName = "RunStencilMacro """ & IconFunction & """"
.Caption = "Button 1"
.CntrlType = Visio.visCtrlTypeBUTTON
.Enabled = True
.state = Visio.visButtonUp
.Style = Visio.visButtonIcon
.Visible = True
.IconFileName ("16x16IconFullFilePath.ico")
End With
' Now establish the position of this toolbar
With Toolbar
.Position = visBarTop 'Top overall docking area
.Left = 0 'Puts it x pixels from the left
.RowIndex = 13
.Protection = visBarNoCustomize
Toolbar.Enabled = True
.Visible = True
End With
Visio.Application.SetCustomToolbars UI
Visio.ActiveDocument.SetCustomToolbars UI
End Sub