I'm facing a weird case in VB6, which is, when I show a form in respect with another OwnerForm, if I did this two/three times for example, when I close all the child forms, suddenly the OwnerForm disappear on background (lose focus and the previous application will be on top), and I will have to click on it on the task bar to show the form again!
A quick sample will be something like that:
Private Sub Command1_Click()
Command1.Enabled = False
Dim frm As New Form1
frm.Show 0, Form1
End Sub
Is there any solution for this?
Thanks.
You're showing the child form on top non-modally, ie, you can have any number of child forms of that type open. When you close them, sometimes the form / app that spawned them will lose focus and disappear behind other applications - as you are experiencing.
You might be able to hide the form being closed (use the _QueryUnload event and cancel the unload), hide, then set the ZOrder on the parent form (to bring it to the front), then carry on unloading the form that is being closed.
Let me know how you get on.
Related
I am working on an old visual basic 6 app, which has just developed an issue, It never used to have.
It is an MDI form application, which has 1 main window which has a menu at the top and status bar at the bottom, along with 2 other status like bars. It also has around 50 Child windows to go within this master frame.
When the user maximizes any child window it seems the window maximizes but does not notice the toolbars at the bottom and it maximizes below them (out of view), so the bottom of the child window does not meet up with the top of the toolbars.
I have done 4 pictures which show it is design time, runtime normal and then maximized, as you can see it hides the buttons.
I have never seen this before
I have tried to code some resizing logic to counteract this in the child Private Sub Form_Resize() event, however, it has no effect at all.
Which leaves me to believe the window resizing when maximizing is dealt with via the windows system itself, or buried deep in vb, where I can not change it.
None of the controls have changed added/deleted on the forms, and I haven't changed any form/control values as far as I remember.
I have also tried bringing the controls to the front, then back etc, no impact
I have tried changing the zindex around in all ways, no impact
Has everyone ever seen this before or have any ideas
Thank You for reading, any help would be greatly appreciated
Thanks
normal working not maxed
maxxed screen showing issue
maxxed even with top menu closed
design time vb6
A pure VB6 solution for the child form:
Private Sub Form_Resize()
If WindowState <> vbMinimized then
Begin
If WindowState = vbMaximized then
WindowState = vbNormal
Top = Me.Parent.Top + Me.Parent.TopToolbar.Height
Height = Me.Parent.Height - Me.Parent.TopToolbar.Height - Me.Parent.BottomToolbar.Height
End
The trick is not to allow maximized mode, and resize the window to fit the remaining space.
The title bar is still at the top of the MDI window, unlike the default maximize behavior.
It has been well over 10 years since I used VB6, please excuse any code imperfections.
I don't have a solution (yet), but I've been facing the same problem with an app of mine. I believe that the issue is caused by the Win-7/Win-10 virtual desktop; the VB6 app thinks it's using the whole screen, but the task bar is on a separate virtual screen, which is on top. I'll post in this thread if I get it solved...
I'm having a strange hang issue with my VB.Net application. When the user clicks an update button, the below is run as a thread to do some long calculations on the data. It disables the control, shows a 'Working...' text box, does the work, re-enables the controls and gets rid of the 'Working...' text box. Occasionaly (I've never reproduced while debugging), the users window freezes and hangs. When it happens CPU usage is 0 so its done with the calculations, but the controls still show as disabled and the 'Working...' text box is still visible, although the window is completely stuck and will not update. This will stay this way indefinitely (users have tried waiting up to 30 minutes). Oddly, I can 'unstick' the window only by clicking the minimize/restore buttons from the right click menu of the window on the task bar. After a short delay the window springs back to life. The minimize/restore of the window itself don't seem to have an effect.
So my question, what am I doing wrong in my below thread?
Dim Thread As New Threading.Thread(AddressOf SubDoPriceUpdateThread)
Thread.Start()
Thread:
Private Sub SubDoPriceUpdateThread()
Dim Loading As New TextBox
Try
CntQuotePriceSummary1.Invoke(New Action(Of Control)(AddressOf CntQuotePriceSummary1.Controls.Add), Loading)
CntQuotePriceSummary1.Invoke(New Action(Sub() CntQuotePriceSummary1.Enabled = False))
Loading.Invoke(New Action(AddressOf Loading.BringToFront))
Loading.Invoke(New Action(Sub() Loading.Text = "Working..."))
'***Long running calculations***
Invoke(New Action(AddressOf FillForm))
Finally
CntQuotePriceSummary1.Invoke(New Action(Of Control)(AddressOf CntQuotePriceSummary1.Controls.Remove), Loading)
CntQuotePriceSummary1.Invoke(New Action(Sub() CntQuotePriceSummary1.Enabled = True))
Loading.Invoke(New Action(AddressOf Loading.Dispose))
End Try
End Sub
Per Hans's comments, its clear that the Loading text box is not created on the UI thread and that's what would've cause the deadlock issue. I've rewritten the code.
Private Sub SubDoPriceUpdateThread()
Dim Loading As TextBox
Invoke(Sub() Loading = New TextBox)
Try
Invoke(Sub()
CntQuotePriceSummary1.Controls.Add(Loading)
CntQuotePriceSummary1.Enabled = False
Loading.BringToFront()
Loading.Text = "Working..."
End Sub)
'***Long running calculations***
Invoke(Sub() FillForm())
Finally
Invoke(Sub()
CntQuotePriceSummary1.Controls.Remove(Loading)
CntQuotePriceSummary1.Enabled = True
Loading.Hide()
Loading.Dispose()
End Sub)
End Try
End Sub
THE SITUATION
I am developing a VB6 application where all i need to do is to sync some files from a server location to the local workstation on a command click. There are two types of operations i am performing, in one m doing a complete sync, in the other i am doing a partial sync. Now when the sync is in progress i am displaying a screen which has a stop button on it. This stop is meant to stop the copying of media if the user wants to do so.
Now, this stop button is only visible when i am performing full sync. There is no option to stop the sync when partial sync is being performed.
The functions performing full sync and partial sync are written in a different class.
THE PROBLEM :
I have implemented all other functions but i having a problem in making this stop button dynamic..i.e. it is visible when full sync is bein called and invisible when partial sync is called.
Hope somebody helps
Thanks in advance
Set the Visible property to False to hide the button.
If I am understanding correctly, since the stop button is on a separate form it is not the case that there are other buttons on top of it- I had similar case myself.
What I can suggest is to check is whether both of the sync buttons are enabling the stop's button visibility when pressed.
I'd do it something like this:
Private sub cmdFullSync_Click()
'run existing code for a full sync
cmdStop.visible = true
end Sub
Private sub cmdPartialSync_Click()
'run existing partial sync code
cmdstop.visible = false
end Sub
Is there a method such that a user can click on the form itself, and in doing so remove focus from whatever object (textbox, combobox, etc) currently has it? Basically, can focus be uniformly removed from everything at once?
Setting the focus to the form itself does not work.
I thought about doing the old "hide a placeholder button behind another object" trick, but I'm really not a fan of that.
Thanks!
In VB6 a PictureBox can get focus, even if it does not contain any control.
In your case you can put a PictureBox with TabStop false, BorderStyle set to 0, TabIndex set to 0 behind every other control but not containing any focusable control and stretch it to ScaleWidth by ScaleHeight at run-time.
You have to put the labels and any windowless control in this background PictureBox too.
This way when the user clicks "on the form" the focus will "go away". With "no focus" Tab key will focus first control (the one with TabIndex set to 1).
When a form is active, something generally HAS to have focus. It sounds like you're just wanting to not "show" that a particular control has focus.
If that's the case, it's going to depend on the controls. Some have properties that control whether or not the specific control "indicates" its focus in some way.
But the built in Windows controls will always show their focus state unless you subclass them
Given this problem. I'd probably put a button on the form , then move it offscreen when the form loads. Make sure it's not a tab stop, but then when you want to hide focus, set focus specifically to the button, make sure the button is STILL in the tab order, even though it's not a tab stop, so the user can press tab while on the button and end up somewhere logical.
Don't have VB handy, but could you simply remove TabStop?
for x = 1 to me.Controls.count
me.Controls(x).TabStop = 0
next
I have a picturebox and a control on a form.
Private Sub cmdButton_Click
PictureBox.setFocus
Exit sub
End sub
The control doesn't change its appearance, nor does the picturebox.
Of course you'll need to add an If-Then clause if you want the control to respond normally sometimes.
We have a VB6 application that uses a non-visible window (form) for DDE communication.
We have some clients reporting that occasionally they can see this window on their desktop.
I did a scan through the code for any visible = true or show's on the form in question, but nothing.
This about all we do with it:
Load frmDDELink
frmDDELink.stuff = stuff
We don't actually explicitly display (or explicitly not display it either).
What could cause a hidden window to be displayed on a user's desktop such that it is visible?
Try and set the location of the form to off-screen.
frmDDELink.ClientLeft = -100
frmDDELink.ClientTop = -100
A misbehaving app on the client's machine could do that. FindWindow() is a notoriously inaccurate API function. On top of that, all VB6 windows have the same class name. Thunder something, iirc. It might be finding your window instead of the one intended, making the wrong window visible.
I like Black Frog's simple hint to set the location off-screen, and nobugz's possible explanation. I would also suggest handling the Form_Activate event and setting the form invisible again.
Private Sub Form_Activate()
'Log something for debugging purposes?'
Me.Visible = False
End Sub
try to set the border into none, or me.visible = false, and set the property not to display in the task bar.