I have a form that displays a tablelayout panel on a 2nd monitor screen. A form that allows you to control the "look" of the form including the postion of the tablelayout control is on the main screen. The tablelayout panel automatically refreshes by use of a timer.
(side note: I use Application Scoped Settings and I am able to write and store the Application Scoped settings across user using a custom xml routine.)
I have no code in the click event except now I added a write to a log command.
When I shut down the program and restart, the program correctly loads the correct tablelayout position. However, if I single click on the form (on the 2nd screen) the tablelayout panel unexpectedly moves. I have a client machine where I first noticed the error. The client machine also has 2 monitors. I was unable to reproduce the error on my dev machine but as soon as I introduced a 2nd monitor I noticed the error. On my machine both x and y of the tlp location get offset by 6 unexpectly when I click. I don't think this is consistent to the movement on the client machine.
Admittingly, I am an amateur programmer when it comes to VB and VS.net and I don't really know how to use their debugging features which is why I have all these messy writelog statements.
Here is my code from the second form.... (I know its a bit hairy)Here is the snapshot from the log which shows the unexpected change:Code:Public Class form2 ' Public t As New System.Timers.Timer(2000) Dim curPage As Integer = 0 Dim numPages As Integer = 0 Dim pkgCnt As Integer Private Sub form2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click frm1.WriteLog("form2 clicked: " & Me.TableLayoutPanel1.Location.ToString) End Sub Private Sub form2_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.DoubleClick ' note: I have commented out this sub and it appears to have no effect on the error If isAdmin Then If Me.WindowState = FormWindowState.Maximized Then Me.WindowState = FormWindowState.Normal Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable frm1.btnFormSize.Text = "Set Display Control On" Else Me.WindowState = FormWindowState.Maximized Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None frm1.btnFormSize.Text = "Set Display Control Off" End If End If End Sub Private Sub form2_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing saveDisplayPosition() frm2 = Nothing End Sub Private Sub form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Control.CheckForIllegalCrossThreadCalls = False loadImage() initTable() frm1.WriteLog("form2 loaded: " & Me.TableLayoutPanel1.Location.ToString) AddHandler t.Tick, AddressOf TimerFired End Sub Public Sub initTable() Dim x As Int16 For x = 0 To 19 Dim label1 As New Label With label1 .Text = "" ' .TextAlign = ContentAlignment.MiddleCenter .Font = My.Settings.myFont .ForeColor = My.Settings.myForeColor .BackColor = My.Settings.myBackColor .AutoSize = True End With Me.TableLayoutPanel1.Controls.Add(label1) Next frm1.WriteLog("inittable end: " & Me.TableLayoutPanel1.Location.ToString) End Sub Public Sub loadImage() Try frm2.PictureBox1.Image = Image.FromFile(My.Settings.myImgFile) Catch ex As Exception Debug.WriteLine("default image used") End Try frm1.WriteLog("loadImg end: " & Me.TableLayoutPanel1.Location.ToString) End Sub Public Sub startTimer() t.Enabled = True End Sub Public Sub stopTimer() t.Enabled = False End Sub Public Sub TimerFired(ByVal sender As Object, _ ByVal e As System.EventArgs) frm1.WriteLog("timerfired start: " & Me.TableLayoutPanel1.Location.ToString) pkgCnt = frm1.lstApts.CheckedItems.Count Dim d As Decimal = (pkgCnt / 20) numPages = Decimal.Truncate(d) If pkgCnt Mod 20 = 0 And pkgCnt > 0 Then numPages = numPages - 1 End If Dim row As Integer = 0 Dim col As Integer = 0 Dim curlabel As Label Dim sourceIndex As Integer = 0 Dim sourceArray(pkgCnt - 1) As Object frm1.lstApts.CheckedItems.CopyTo(sourceArray, 0) 'special sort Me.Cursor = Cursors.WaitCursor If (sourceArray.Length - 1 > 0) Then 'sort alphabetically QuickSort(sourceArray, 0, sourceArray.Length - 1) End If Me.Cursor = Cursors.Default ' Me.TableLayoutPanel1.Controls.Clear() sourceIndex = (curPage * 20) For row = 0 To 3 For col = 0 To 4 curLabel = New Label curLabel = Me.TableLayoutPanel1.GetControlFromPosition(col, row) With curLabel If sourceIndex >= sourceArray.Length Then Text = " " Else .Text = sourceArray(sourceIndex) ' .TextAlign = ContentAlignment.MiddleCenter .Font = My.Settings.myFont .ForeColor = My.Settings.myForeColor .BackColor = My.Settings.myBackColor End If End With frm1.WriteLog("timerfired loop: " & Me.TableLayoutPanel1.Location.ToString) sourceIndex = sourceIndex + 1 Next Next If curPage >= numPages Then curPage = 0 Else curPage = curPage + 1 End If sourceIndex = 0 frm1.WriteLog("timerfired end: " & Me.TableLayoutPanel1.Location.ToString) End Sub ' Quicksort stuff removed Public Sub saveDisplayPosition() Dim x, y As Integer If isAdmin Then ' save form location y = Me.Location.Y x = Me.Location.X Dim pointStr As String = x & ", " & y frm1.ChangeMyAppScopedSetting("myDisplayLoc", pointStr) 'save image location y = Me.PictureBox1.Location.Y x = Me.PictureBox1.Location.X pointStr = x & ", " & y frm1.ChangeMyAppScopedSetting("myImgLoc", pointStr) 'save table location y = Me.TableLayoutPanel1.Location.Y x = Me.TableLayoutPanel1.Location.X pointStr = x & ", " & y frm1.ChangeMyAppScopedSetting("myLocation", pointStr) frm1.WriteLog("saved location sdp: " & Me.TableLayoutPanel1.Location.ToString) ' save displays window state Dim wsStr As String = Me.WindowState.ToString frm1.ChangeMyAppScopedSetting("myDisplayWinState", wsStr) ' save borderstyle Dim brdrStr As String = Me.FormBorderStyle.ToString frm1.ChangeMyAppScopedSetting("myDisplayBorder", brdrStr) End If End Sub End Class
I know this bug might be a pain to help with but any tips would be greatly appreciated because I have been stuck with this bug for quite some time. Thanks in advance.Code:2007-12-30 13:01:18 inittable end: {X=251,Y=-27} 2007-12-30 13:01:18 form2 loaded: {X=251,Y=-27} 2007-12-30 13:01:18 loaded location: {X=176,Y=262} ' this was the saved app setting correctly loaded 2007-12-30 13:01:22 timerfired end: {X=176,Y=262} 2007-12-30 13:01:24 form2 clicked: {X=170,Y=256} ' this is the unexpected change 2007-12-30 13:01:24 timerfired start: {X=170,Y=256}


Reply With Quote
