none
Form from a DLL in wrong monitor RRS feed

  • Question

  • Hi,

    so I have this little DLL of mine that act as a notification window. Everything works fine except for one thing I can't figure out.

    When using more than one monitor I want to make to display the notification in the same monitor as the program calling this DLL sub.

    So in my DLL I have this subroutine that display the window/form:

    	Private Sub ShowingTheNotification(msgIcon As InfoIcon, winOwner As Object)
    		_frm.BackColor = GetTheBorderColor(_PanelBorderColor)
    
    		Select Case msgIcon
    			Case InfoIcon.InformationIcon
    				_picInfo.Image = My.Resources.info
    
    			Case InfoIcon.GreenCheckIcon
    				_picInfo.Image = My.Resources.GreenCheck
    
    			Case InfoIcon.WarningIcon
    				_picInfo.Image = My.Resources.warning
    
    			Case InfoIcon.ErrorIcon
    				_picInfo.Image = My.Resources._error
    
    			Case Else
    				_picInfo.Image = My.Resources.info
    		End Select
    
    		FadeOut = False
    		_frm.Show()
    		_frm.BringToFront()
    		_frm.Opacity = 0.0
    		TimerFade.Start()
    	End Sub

    How can I get the caller monitor/screen and set my DLL to display in that same screen?

    ... been googling a lot without any chance.

    Thanks

    mercredi 21 octobre 2020 19:04

Réponses

  • Here is something that you will need to tweak.

    Option Infer On
    
    Public Sub MaximizeToMonitor(ByVal form As Form, ByVal monitorIndex As Integer)
    	Try
    		Dim screen = Screen.AllScreens(monitorIndex)
    		If screen IsNot Nothing Then
    			form.WindowState = FormWindowState.Normal
    			Dim workingArea = screen.WorkingArea
    			form.Left = workingArea.Left + 10
    			form.Top = workingArea.Top + 10
    			form.Width = workingArea.Width + 10
    			form.Height = workingArea.Height + 10
    			form.WindowState = FormWindowState.Maximized
    		End If
    
    	Catch ex As Exception
    		MessageBox.Show($"Monitor does not exists. {Environment.NewLine}{ex.Message}")
    	End Try
    End Sub
    


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marqué comme réponse Alex Cote mardi 27 octobre 2020 19:29
    mercredi 21 octobre 2020 20:55
    Modérateur
  • Thanks for your input.

    Turned out that if the primary window is on the right of the secondary the working area X is negative ! Did not notice that earlier.

    So I simply had to check that if working area X is negative and adjust accordingly:

    				If _ScreenToDisplay.WorkingArea.X < 0 Then
    					_frm.Left = -_ScreenToDisplay.WorkingArea.Width
    				Else
    					_frm.Left = _PanelEdgeOffset
    				End If

    • Marqué comme réponse Alex Cote mardi 27 octobre 2020 19:29
    vendredi 23 octobre 2020 14:15

Toutes les réponses

  • Here is something that you will need to tweak.

    Option Infer On
    
    Public Sub MaximizeToMonitor(ByVal form As Form, ByVal monitorIndex As Integer)
    	Try
    		Dim screen = Screen.AllScreens(monitorIndex)
    		If screen IsNot Nothing Then
    			form.WindowState = FormWindowState.Normal
    			Dim workingArea = screen.WorkingArea
    			form.Left = workingArea.Left + 10
    			form.Top = workingArea.Top + 10
    			form.Width = workingArea.Width + 10
    			form.Height = workingArea.Height + 10
    			form.WindowState = FormWindowState.Maximized
    		End If
    
    	Catch ex As Exception
    		MessageBox.Show($"Monitor does not exists. {Environment.NewLine}{ex.Message}")
    	End Try
    End Sub
    


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marqué comme réponse Alex Cote mardi 27 octobre 2020 19:29
    mercredi 21 octobre 2020 20:55
    Modérateur
  • Hi Karen,

    integrated part of your suggestion, but still do not work.

    In the DLL new part I get the screen from the sender (Me):


    This gives me this message: 

    Then I set the form location like this:

    and during Runtime I can see this:

     Which fit what I expect.

    But for some reason it still displays in the other monitor. I tried to set the position at two different place in the code, but that did not change a thing

    I get this on form shown:


    Any hints?

    jeudi 22 octobre 2020 16:13
  • Hello,

    I don't have time (beings I'm at work) to devote time to setup what you have and test it.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    jeudi 22 octobre 2020 16:37
    Modérateur
  • I totally understand ... thanks 
    jeudi 22 octobre 2020 17:49
  • Hi Alex Cote,

    Thanks for your feedback.

    You can try to set StartPosition parameter as 'FormStartPosition.Manual' inside your SetTheFormPosition method.

        form.StartPosition = FormStartPosition.Manual

    Hope it could be helpful.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    vendredi 23 octobre 2020 06:27
    Modérateur
  • Thanks for your input.

    Turned out that if the primary window is on the right of the secondary the working area X is negative ! Did not notice that earlier.

    So I simply had to check that if working area X is negative and adjust accordingly:

    				If _ScreenToDisplay.WorkingArea.X < 0 Then
    					_frm.Left = -_ScreenToDisplay.WorkingArea.Width
    				Else
    					_frm.Left = _PanelEdgeOffset
    				End If

    • Marqué comme réponse Alex Cote mardi 27 octobre 2020 19:29
    vendredi 23 octobre 2020 14:15
  • Hi Alex Cote,

    If your question has been answered then please click the "Mark as Answer" Link at the bottom of the correct post(s), so that it will help other members to find the solution quickly if they face a similar issue. Thanks.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    lundi 26 octobre 2020 01:58
    Modérateur