msvisual.com Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

prevent losing focus

 
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Syntax
Author Message
CK



Joined: 04 Oct 2007
Posts: 4

PostPosted: Tue Oct 10, 2006 10:09 pm    Post subject: prevent losing focus Reply with quote

Hi,

I am writing an app that has few forms showing at the same time, and one of
them is the data entry form, the rest (7 of them) are just loading pictures
from HD constantly (controlled by timer eg 5 sec interval).
Now I have a problem, everytime each of the display forms timer is fired,
the data entery form loses focus (that particular display form will receive
focus), and soon, it is almost impossible for the data entry to stay on
focus even manually clicking on the form because the timer of the diplay
forms are firing one after another!
Is there a way either force the focus always stay on the data entry form OR
the display forms need not to receive focus and still able to do what they
suppose to do, ie to load pic and display them.
Thanks very much.

CK

Archived from group: microsoft>public>vb>syntax
Back to top
View user's profile Send private message
Karl E. Peterson



Joined: 04 Oct 2007
Posts: 4836

PostPosted: Tue Oct 10, 2006 12:51 pm    Post subject: Re: prevent losing focus Reply with quote

CK wrote:
> I am writing an app that has few forms showing at the same time, and
> one of them is the data entry form, the rest (7 of them) are just
> loading pictures from HD constantly (controlled by timer eg 5 sec
> interval).

First question, why forms? You certainly don't need those for timers. See
http://vb.mvps.org/samples/TimerObj if you're unaware of code-based
alternatives.

> Now I have a problem, everytime each of the display forms timer is
> fired, the data entery form loses focus (that particular display form
> will receive focus),

What Jan said: It's definitely not the Timer that's causing it. More
likely, code that's being executed in reaction to the timer firing is doing
this.

> Is there a way either force the focus always stay on the data entry
> form OR the display forms need not to receive focus and still able to
> do what they suppose to do, ie to load pic and display them.

You need to get into the code, and determine what is actually shifting the
focus. If you want to produce a horrid strobe effect, you could always
manually shift focus back to the main form with code in the other form's
Activate events. But I'd *strongly* suggest you not do that.
--
Working without a .NET?
http://classicvb.org/
Back to top
View user's profile Send private message
CK



Joined: 04 Oct 2007
Posts: 4

PostPosted: Thu Oct 12, 2006 2:22 pm    Post subject: Re: prevent losing focus Reply with quote

Hi Karl and Jan

That is corrent, the timer event execute codes that load graphic files and
display them at 5 sec interval. I should also clarify that, I am writing an
app to display 7 *different* sets of images to 7 different displays via 2
quadro cards, therefore, I figure I need 7 different forms (7 instances of a
form) to do that, with approprite co-ordiantes.
I have tried some of the code-based timer, but I couldn't figure out how to
get it to work if I put multiple timers on that same form. If I put
multiple user defined timer controls, it acts as if there only one timer, I
believe it uses the same timer ID.
Each form has 2 timers:
1: to change the images (run as "slides"
2: to turn on and off the "slides" and a user defined interval

Though I am not doing some kind strobe effect but, I think with the 7 forms
running a set of slide each, I think it is practically some sort of strobe
effect anyway. Any suggestion to resolve this would be greatly appreciated.
Even suggestion of re-work on the entire app!!

Thanks very much

CK.


"Karl E. Peterson" wrote in message
news:%23Q08rPI7GHA.1188@TK2MSFTNGP05.phx.gbl...
> CK wrote:
>> I am writing an app that has few forms showing at the same time, and
>> one of them is the data entry form, the rest (7 of them) are just
>> loading pictures from HD constantly (controlled by timer eg 5 sec
>> interval).
>
> First question, why forms? You certainly don't need those for timers.
> See
> http://vb.mvps.org/samples/TimerObj if you're unaware of code-based
> alternatives.
>
>> Now I have a problem, everytime each of the display forms timer is
>> fired, the data entery form loses focus (that particular display form
>> will receive focus),
>
> What Jan said: It's definitely not the Timer that's causing it. More
> likely, code that's being executed in reaction to the timer firing is
> doing
> this.
>
>> Is there a way either force the focus always stay on the data entry
>> form OR the display forms need not to receive focus and still able to
>> do what they suppose to do, ie to load pic and display them.
>
> You need to get into the code, and determine what is actually shifting the
> focus. If you want to produce a horrid strobe effect, you could always
> manually shift focus back to the main form with code in the other form's
> Activate events. But I'd *strongly* suggest you not do that.
> --
> Working without a .NET?
> http://classicvb.org/
>
>
Back to top
View user's profile Send private message
Jan Hyde



Joined: 04 Oct 2007
Posts: 1211

PostPosted: Thu Oct 12, 2006 1:03 pm    Post subject: Re: prevent losing focus Reply with quote

"CK" 's wild thoughts were released on
Thu, 12 Oct 2006 10:22:51 +0800 bearing the following fruit:

>Hi Karl and Jan
>
>That is corrent, the timer event execute codes that load graphic files and
>display them at 5 sec interval. I should also clarify that, I am writing an
>app to display 7 *different* sets of images to 7 different displays via 2
>quadro cards, therefore, I figure I need 7 different forms (7 instances of a
>form) to do that, with approprite co-ordiantes.
>I have tried some of the code-based timer, but I couldn't figure out how to
>get it to work if I put multiple timers on that same form. If I put
>multiple user defined timer controls, it acts as if there only one timer, I
>believe it uses the same timer ID.
>Each form has 2 timers:
>1: to change the images (run as "slides"
>2: to turn on and off the "slides" and a user defined interval
>
>Though I am not doing some kind strobe effect but, I think with the 7 forms
>running a set of slide each, I think it is practically some sort of strobe
>effect anyway. Any suggestion to resolve this would be greatly appreciated.
>Even suggestion of re-work on the entire app!!
>
>Thanks very much

I'm may be wrong but I think you missed the point. The
timers are not causing this, it's likely that something in
your code is, probably the code that runs when the timer
fires.

J
>CK.
>
>
>"Karl E. Peterson" wrote in message
>news:%23Q08rPI7GHA.1188@TK2MSFTNGP05.phx.gbl...
>> CK wrote:
>>> I am writing an app that has few forms showing at the same time, and
>>> one of them is the data entry form, the rest (7 of them) are just
>>> loading pictures from HD constantly (controlled by timer eg 5 sec
>>> interval).
>>
>> First question, why forms? You certainly don't need those for timers.
>> See
>> http://vb.mvps.org/samples/TimerObj if you're unaware of code-based
>> alternatives.
>>
>>> Now I have a problem, everytime each of the display forms timer is
>>> fired, the data entery form loses focus (that particular display form
>>> will receive focus),
>>
>> What Jan said: It's definitely not the Timer that's causing it. More
>> likely, code that's being executed in reaction to the timer firing is
>> doing
>> this.
>>
>>> Is there a way either force the focus always stay on the data entry
>>> form OR the display forms need not to receive focus and still able to
>>> do what they suppose to do, ie to load pic and display them.
>>
>> You need to get into the code, and determine what is actually shifting the
>> focus. If you want to produce a horrid strobe effect, you could always
>> manually shift focus back to the main form with code in the other form's
>> Activate events. But I'd *strongly* suggest you not do that.
>> --
>> Working without a .NET?
>> http://classicvb.org/
>>
>>
>


Jan Hyde (VB MVP)

--
Legend: The edge of a cliff (Art. Moger)
Back to top
View user's profile Send private message
Larry Serflaten



Joined: 04 Oct 2007
Posts: 2644

PostPosted: Thu Oct 12, 2006 3:08 pm    Post subject: Re: prevent losing focus Reply with quote

"CK" wrote

> I have tried some of the code-based timer, but I couldn't figure out how to
> get it to work if I put multiple timers on that same form. If I put
> multiple user defined timer controls, it acts as if there only one timer, I
> believe it uses the same timer ID.
> Each form has 2 timers:
> 1: to change the images (run as "slides"
> 2: to turn on and off the "slides" and a user defined interval
>
> Though I am not doing some kind strobe effect but, I think with the 7 forms
> running a set of slide each, I think it is practically some sort of strobe
> effect anyway. Any suggestion to resolve this would be greatly appreciated.
> Even suggestion of re-work on the entire app!!

Perhaps you whould have the entry form controls the others?

Here is a short demo you might consider. In a new project,
add a Timer, Textbox, Command button, and a FileListBox
to the form, then add a second form to the project. Paste in
the code below to their respective modules and try it out.

You'll note that the entry from works as you suspect....

LFS

'[Form1 code]
Option Explicit
Private DisplayIndex As Long
Private FileIndex As Long
Private DisplayForms As New Collection

Private Sub Command1_Click()
On Error Resume Next
File1.Path = Text1.Text
If Err.Number Then
MsgBox Err.Description
End If
End Sub

Private Sub Form_Load()
Text1.Move 90, 90, 4000, 270
Text1.Text = "Enter picture directory, press APPLY"
Command1.Move 4200, 60, 900, 360
Command1.Caption = "Apply"
Me.Move 300, 300, 5400, 900
Me.Caption = "Slideshow"
File1.Pattern = "*.bmp;*.gif;*.jpg"
File1.Move -4000, 0, 3000, 3000
Timer1.Interval = 1000
Timer1.Enabled = True

With DisplayForms
Do While .Count < 4
.Add New Form2, "F" & CStr(.Count + 1)
With .Item(.Count)
.Caption = CStr(DisplayForms.Count)
.Tag = "F" & .Caption
.Width = Screen.Width / 4.01
.Height = .Width
.Left = .Caption * .Width - .Width
.Top = Screen.Height - .Height
.Visible = True
End With
Loop
End With
End Sub

Public Sub RemoveForm(ID As String)
DisplayForms.Remove ID
End Sub

Private Sub Form_Unload(Cancel As Integer)
Timer1.Enabled = False
Do While Forms.Count > 1
Unload Forms(Forms.Count - 1)
Loop
End Sub

Private Sub Timer1_Timer()

DisplayIndex = DisplayIndex + 1
If DisplayIndex > DisplayForms.Count Then
DisplayIndex = 1
End If

FileIndex = FileIndex + 1
If FileIndex > File1.ListCount Then
FileIndex = 0
End If

If Len(File1.List(FileIndex)) Then
DisplayForms(DisplayIndex).LoadImage File1.Path & "\" & File1.List(FileIndex)
End If
End Sub




'[Form2 code]
Option Explicit
Private Src As StdPicture
Const BACKGROUND = &H404040

Private Sub Form_Load()
Me.ScaleMode = vbPixels
Me.BackColor = BACKGROUND
End Sub

Private Sub Form_Paint()
If Not Src Is Nothing Then
Src.Render Me.hDC, 0, Me.ScaleHeight, Me.ScaleWidth, -Me.ScaleHeight, 0, 0, Src.Width, Src.Height, ByVal 0&
End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
Form1.RemoveForm Me.Tag
End Sub

Public Sub LoadImage(File As String)
Set Src = LoadPicture(File)
Me.BackColor = BACKGROUND
Me.Refresh
End Sub
Back to top
View user's profile Send private message
CK



Joined: 04 Oct 2007
Posts: 4

PostPosted: Fri Oct 13, 2006 4:12 pm    Post subject: Re: prevent losing focus Reply with quote

Hi Jan,

If I have not misunderstood you comment; you are right with what you said:
when the timer fires, it run some codes (and the codes are loading pictures
one at a time, according to the timer's interval, and I believe that these
codes take the focus away from data entry form). I think I must have put
too much info in my previous post that caused the confusion. Thanks

Here is the code:
Form #1
--------
a data entry form

Form #2
--------
Private Sub tmrSlides_Timer()
On Error Resume Next
Dim pic as Picture

File1.ListIndex = m_lngCounter

Set picSlide= Nothing
picSlide.Cls
Set pic = LoadPicture(m_strPath & "\" & File1.filename)
picSlide.PaintPicture pic, 0, 0, picSlide.Width, picSlide.Height

If File1.ListCount - 1 > m_lngCounter Then
m_lngCounter = m_lngCounter + 1
Else
m_lngCounter = 0
End If
End Sub



CK


"Jan Hyde" wrote in message @4ax.com...
> "CK" 's wild thoughts were released on
> Thu, 12 Oct 2006 10:22:51 +0800 bearing the following fruit:
>
>>Hi Karl and Jan
>>
>>That is corrent, the timer event execute codes that load graphic files and
>>display them at 5 sec interval. I should also clarify that, I am writing
>>an
>>app to display 7 *different* sets of images to 7 different displays via 2
>>quadro cards, therefore, I figure I need 7 different forms (7 instances of
>>a
>>form) to do that, with approprite co-ordiantes.
>>I have tried some of the code-based timer, but I couldn't figure out how
>>to
>>get it to work if I put multiple timers on that same form. If I put
>>multiple user defined timer controls, it acts as if there only one timer,
>>I
>>believe it uses the same timer ID.
>>Each form has 2 timers:
>>1: to change the images (run as "slides"
>>2: to turn on and off the "slides" and a user defined interval
>>
>>Though I am not doing some kind strobe effect but, I think with the 7
>>forms
>>running a set of slide each, I think it is practically some sort of strobe
>>effect anyway. Any suggestion to resolve this would be greatly
>>appreciated.
>>Even suggestion of re-work on the entire app!!
>>
>>Thanks very much
>
> I'm may be wrong but I think you missed the point. The
> timers are not causing this, it's likely that something in
> your code is, probably the code that runs when the timer
> fires.
>
> J
>>CK.
>>
>>
>>"Karl E. Peterson" wrote in message
>>news:%23Q08rPI7GHA.1188@TK2MSFTNGP05.phx.gbl...
>>> CK wrote:
>>>> I am writing an app that has few forms showing at the same time, and
>>>> one of them is the data entry form, the rest (7 of them) are just
>>>> loading pictures from HD constantly (controlled by timer eg 5 sec
>>>> interval).
>>>
>>> First question, why forms? You certainly don't need those for timers.
>>> See
>>> http://vb.mvps.org/samples/TimerObj if you're unaware of code-based
>>> alternatives.
>>>
>>>> Now I have a problem, everytime each of the display forms timer is
>>>> fired, the data entery form loses focus (that particular display form
>>>> will receive focus),
>>>
>>> What Jan said: It's definitely not the Timer that's causing it. More
>>> likely, code that's being executed in reaction to the timer firing is
>>> doing
>>> this.
>>>
>>>> Is there a way either force the focus always stay on the data entry
>>>> form OR the display forms need not to receive focus and still able to
>>>> do what they suppose to do, ie to load pic and display them.
>>>
>>> You need to get into the code, and determine what is actually shifting
>>> the
>>> focus. If you want to produce a horrid strobe effect, you could always
>>> manually shift focus back to the main form with code in the other form's
>>> Activate events. But I'd *strongly* suggest you not do that.
>>> --
>>> Working without a .NET?
>>> http://classicvb.org/
>>>
>>>
>>
>
>
> Jan Hyde (VB MVP)
>
> --
> Legend: The edge of a cliff (Art. Moger)
>
Back to top
View user's profile Send private message
CK



Joined: 04 Oct 2007
Posts: 4

PostPosted: Fri Oct 13, 2006 4:15 pm    Post subject: Re: prevent losing focus Reply with quote

Hi Larry, thanks and will give it a try..

CK

"Larry Serflaten" wrote in message @TK2MSFTNGP05.phx.gbl...
>
> "CK" wrote
>
>> I have tried some of the code-based timer, but I couldn't figure out how
>> to
>> get it to work if I put multiple timers on that same form. If I put
>> multiple user defined timer controls, it acts as if there only one timer,
>> I
>> believe it uses the same timer ID.
>> Each form has 2 timers:
>> 1: to change the images (run as "slides"
>> 2: to turn on and off the "slides" and a user defined interval
>>
>> Though I am not doing some kind strobe effect but, I think with the 7
>> forms
>> running a set of slide each, I think it is practically some sort of
>> strobe
>> effect anyway. Any suggestion to resolve this would be greatly
>> appreciated.
>> Even suggestion of re-work on the entire app!!
>
> Perhaps you whould have the entry form controls the others?
>
> Here is a short demo you might consider. In a new project,
> add a Timer, Textbox, Command button, and a FileListBox
> to the form, then add a second form to the project. Paste in
> the code below to their respective modules and try it out.
>
> You'll note that the entry from works as you suspect....
>
> LFS
>
> '[Form1 code]
> Option Explicit
> Private DisplayIndex As Long
> Private FileIndex As Long
> Private DisplayForms As New Collection
>
> Private Sub Command1_Click()
> On Error Resume Next
> File1.Path = Text1.Text
> If Err.Number Then
> MsgBox Err.Description
> End If
> End Sub
>
> Private Sub Form_Load()
> Text1.Move 90, 90, 4000, 270
> Text1.Text = "Enter picture directory, press APPLY"
> Command1.Move 4200, 60, 900, 360
> Command1.Caption = "Apply"
> Me.Move 300, 300, 5400, 900
> Me.Caption = "Slideshow"
> File1.Pattern = "*.bmp;*.gif;*.jpg"
> File1.Move -4000, 0, 3000, 3000
> Timer1.Interval = 1000
> Timer1.Enabled = True
>
> With DisplayForms
> Do While .Count < 4
> .Add New Form2, "F" & CStr(.Count + 1)
> With .Item(.Count)
> .Caption = CStr(DisplayForms.Count)
> .Tag = "F" & .Caption
> .Width = Screen.Width / 4.01
> .Height = .Width
> .Left = .Caption * .Width - .Width
> .Top = Screen.Height - .Height
> .Visible = True
> End With
> Loop
> End With
> End Sub
>
> Public Sub RemoveForm(ID As String)
> DisplayForms.Remove ID
> End Sub
>
> Private Sub Form_Unload(Cancel As Integer)
> Timer1.Enabled = False
> Do While Forms.Count > 1
> Unload Forms(Forms.Count - 1)
> Loop
> End Sub
>
> Private Sub Timer1_Timer()
>
> DisplayIndex = DisplayIndex + 1
> If DisplayIndex > DisplayForms.Count Then
> DisplayIndex = 1
> End If
>
> FileIndex = FileIndex + 1
> If FileIndex > File1.ListCount Then
> FileIndex = 0
> End If
>
> If Len(File1.List(FileIndex)) Then
> DisplayForms(DisplayIndex).LoadImage File1.Path & "\" &
> File1.List(FileIndex)
> End If
> End Sub
>
>
>
>
> '[Form2 code]
> Option Explicit
> Private Src As StdPicture
> Const BACKGROUND = &H404040
>
> Private Sub Form_Load()
> Me.ScaleMode = vbPixels
> Me.BackColor = BACKGROUND
> End Sub
>
> Private Sub Form_Paint()
> If Not Src Is Nothing Then
> Src.Render Me.hDC, 0, Me.ScaleHeight, Me.ScaleWidth, -Me.ScaleHeight,
> 0, 0, Src.Width, Src.Height, ByVal 0&
> End If
> End Sub
>
> Private Sub Form_Unload(Cancel As Integer)
> Form1.RemoveForm Me.Tag
> End Sub
>
> Public Sub LoadImage(File As String)
> Set Src = LoadPicture(File)
> Me.BackColor = BACKGROUND
> Me.Refresh
> End Sub
>
>
>
>

Back to top
View user's profile Send private message
Display posts from previous:   
Related Topics:
Prevent modifying a textbox using Ctrl-V (paste) This the situation: I have a textbox with its Locked property set to True. The textbox content is impossible to modify using the keyboard; but I discovered that using paste (Ctrl-V) is possible. Any idea why this is possible? Regards.

set focus on controls. hi All, is setting focus on controls during form_load dangerous ? if yes what's the work around it ? TIA -ashish

Keeping Focus on form Hi, I have a little .exe that is called from within a 3rd party app and is populated with info from the current record of this 3rd party app. The problem I have is that the 3rd party app always keeps the focus and my little form ends up on the toolbar. Ho

Called app gaining focus Is there an API call that will make a given window the focus rather than my app loading but being on the status bar at the bottom of the screen?

Prevent a Form from Losing Focus [Maybe]? G'day folks, I have a small ToolWindow form aside my main form, displaying Chr(0 - 255) (a character map). When a user clicks on a character, I want it pasted to the field with the active focus on the main form. The main form has a procedure that detects
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Syntax All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group