Click here to Skip to main content
15,900,511 members
Home / Discussions / Windows Forms
   

Windows Forms

 
QuestionDoes Cross-threading effect non-UI objects? Pin
TheRedEye3-Jul-08 22:51
TheRedEye3-Jul-08 22:51 
AnswerRe: Does Cross-threading effect non-UI objects? Pin
Christian Graus4-Jul-08 0:41
protectorChristian Graus4-Jul-08 0:41 
AnswerRe: Does Cross-threading effect non-UI objects? Pin
Mycroft Holmes6-Jul-08 21:47
professionalMycroft Holmes6-Jul-08 21:47 
Questionsubscript and superscript like H20 Pin
kannanmani3-Jul-08 20:28
kannanmani3-Jul-08 20:28 
RantRe: subscript and superscript like H20 Pin
Smithers-Jones4-Jul-08 7:51
Smithers-Jones4-Jul-08 7:51 
QuestionFiltering in DataGridView Pin
marekS0823-Jul-08 20:08
marekS0823-Jul-08 20:08 
AnswerRe: Filtering in DataGridView Pin
Mycroft Holmes6-Jul-08 21:50
professionalMycroft Holmes6-Jul-08 21:50 
QuestionScreen Refresh is too slow Pin
Devan_Monroe3-Jul-08 7:55
Devan_Monroe3-Jul-08 7:55 
I am looking for help on how to speed up VB.NET (or C#) screen refresh speed.

I am in charge of writing a newer fancier user interface in .NET for an older legacy program. Because this needs to run on slow legacy machines I did a performance test and discovered the screen refresh speeds of VB6 is faster then .NET. WTF | :WTF:

To do a head to head comparison I put together equivalent VB6 and VB.NET programs, each with a maximized form and 48 labels. Clicking on any label changes the background color of all the labels on the form. In VB6 there is barely a flicker as the colors change across the entire form all at once. In VB.NET you can see the color change moving across the form like a wave. To really see the problem it is best to try the following code on a slower machine (1GHz etc.)

In VB6 create a project MyProject and add a form MyForm with the following properties
Caption = "Screen Refresh test VB6"
BackColor = Black
WindowState = Maximized


On that form add a label MyLabel with the following properties:
Index = 0
Caption = "Hello World"
BackColor = Cyan


In the form add the following code:
Option Explicit

Const ROWS  As Integer = 8
Const COLS  As Integer = 6
Const PAD   As Integer = 75   ' 5 pixels at 15 twips per pixel

Private colors(0 To 2) As Long
Private color As Integer

Private Sub Form_Load()
   Dim index As Integer
   
   colors(0) = vbCyan
   colors(1) = vbYellow
   colors(2) = vbGreen
   
   For index = 1 To ROWS * COLS - 1
      Call Load(MyLabel(index))
      MyLabel(index).Caption = MyLabel(index).Caption & " " & CStr(index)
      MyLabel(index).Visible = True
   Next index
   MyLabel(0).Caption = MyLabel(0).Caption & " 0"
End Sub

Private Sub Form_Resize()
   Dim width   As Single
   Dim height  As Single
   Dim row     As Integer
   Dim col     As Integer
   Dim index   As Integer
   
   width = (Me.width - 60 - PAD * (COLS + 1)) \ COLS
   height = (Me.height - 450 - PAD * (ROWS + 1)) \ ROWS
   
   For col = 0 To COLS - 1
      For row = 0 To ROWS - 1
         index = col * ROWS + row
         Call MyLabel(index).Move(PAD + col * (width + PAD), PAD + row * (height + PAD), width, height)
      Next row
   Next col
End Sub

Private Sub MyLabel_Click(index As Integer)
   color = (color + 1) Mod 3
   
   For index = 0 To ROWS * COLS - 1
      MyLabel(index).BackColor = colors(color)
   Next index
End Sub


The VB.NET program is virtually identical. Just create a windows project and past in the following code. This code defines a form and is self sufficient. It does not need the auto generated form code.
Public Class MyForm
   Inherits System.Windows.Forms.Form

   Private Const _ROWS As Integer = 8
   Private Const _COLS As Integer = 6
   Private Const _PAD As Integer = 5
   Private _myLabel(_ROWS * _COLS - 1) As System.Windows.Forms.Label

   Private _colors() As System.Drawing.Color = {Color.Cyan, Color.Magenta, Color.Yellow}
   Private _color As Integer

   Public Sub New()
      Me.SuspendLayout()

      For index As Integer = 0 To _ROWS * _COLS - 1

         Me._myLabel(index) = New System.Windows.Forms.Label
         Me._myLabel(index).BackColor = System.Drawing.Color.Cyan
         Me._myLabel(index).Name = "MyLabel" & CStr(index)
         Me._myLabel(index).TabIndex = index
         Me._myLabel(index).Text = "Hello World " & CStr(index)
         Me._myLabel(index).TextAlign = System.Drawing.ContentAlignment.MiddleCenter

         AddHandler Me._myLabel(index).Click, AddressOf MyLabel_Click

         Me.Controls.Add(Me._myLabel(index))
      Next

      Me.ClientSize = New System.Drawing.Size(292, 273)
      Me.StartPosition = FormStartPosition.CenterScreen
      Me.WindowState = FormWindowState.Maximized
      Me.BackColor = Color.Black
      Me.Name = "MyForm"
      Me.Text = "Screen Refresh Test VB.NET"

      Me.ResumeLayout(False)

   End Sub

   Private Sub MyForm_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
      Dim resize As System.Drawing.Size = _
         New System.Drawing.Size _
            ( _
               (Me.ClientRectangle.Width - (_PAD * _COLS + 1)) \ _COLS, _
               (Me.ClientRectangle.Height - (_PAD * _ROWS + 1)) \ _ROWS _
            )

      Me.SuspendLayout()

      For col As Integer = 0 To _COLS - 1
         For row As Integer = 0 To _ROWS - 1
            With Me._myLabel(col * _ROWS + row)
               .Size = resize
               .Location = New System.Drawing.Point(_PAD + col * (.Width + _PAD), _PAD + row * (.Height + _PAD))
            End With
         Next
      Next

      Me.ResumeLayout()
   End Sub

   Private Sub MyLabel_Click(ByVal sender As Object, ByVal e As System.EventArgs)
      _color = (_color + 1) Mod _colors.Length
      For index As Integer = 0 To _ROWS * _COLS - 1
         Me._myLabel(index).BackColor = _colors(_color)
      Next
   End Sub
End Class


Any help or ideas would be appreciated. If there is a known solution please point me in the right direction.
AnswerRe: Screen Refresh is too slow Pin
led mike3-Jul-08 8:13
led mike3-Jul-08 8:13 
GeneralRe: Screen Refresh is too slow Pin
Devan_Monroe3-Jul-08 9:08
Devan_Monroe3-Jul-08 9:08 
GeneralRe: Screen Refresh is too slow Pin
led mike3-Jul-08 9:41
led mike3-Jul-08 9:41 
AnswerRe: Screen Refresh is too slow Pin
Pete O'Hanlon3-Jul-08 10:25
mvePete O'Hanlon3-Jul-08 10:25 
GeneralRe: Screen Refresh is too slow Pin
Devan_Monroe3-Jul-08 10:40
Devan_Monroe3-Jul-08 10:40 
AnswerRe: Screen Refresh is too slow Pin
Devan_Monroe8-Jul-08 3:26
Devan_Monroe8-Jul-08 3:26 
QuestionAssign Generic List to multiple ListViews Pin
Member 38758502-Jul-08 21:40
Member 38758502-Jul-08 21:40 
AnswerRe: Assign Generic List to multiple ListViews Pin
led mike3-Jul-08 6:29
led mike3-Jul-08 6:29 
Questionsubscript and superscript like H20 Pin
kannanmani2-Jul-08 19:24
kannanmani2-Jul-08 19:24 
AnswerRe: subscript and superscript like H20 Pin
Paul Conrad2-Jul-08 20:24
professionalPaul Conrad2-Jul-08 20:24 
AnswerRe: subscript and superscript like H20 Pin
Pete O'Hanlon3-Jul-08 10:23
mvePete O'Hanlon3-Jul-08 10:23 
AnswerRe: subscript and superscript like H20 Pin
Luc Pattyn4-Jul-08 15:27
sitebuilderLuc Pattyn4-Jul-08 15:27 
QuestionHow to prevent open/save dialog boxes in WebBrowser control Pin
Joe Woodbury2-Jul-08 12:52
professionalJoe Woodbury2-Jul-08 12:52 
QuestionClosing Form by MouseClick somewhere Pin
MichaelCoder2-Jul-08 12:07
MichaelCoder2-Jul-08 12:07 
AnswerRe: Closing Form by MouseClick somewhere Pin
Ajay.k_Singh3-Jul-08 4:51
Ajay.k_Singh3-Jul-08 4:51 
GeneralRe: Closing Form by MouseClick somewhere Pin
MichaelCoder3-Jul-08 10:20
MichaelCoder3-Jul-08 10:20 
QuestionArray of Controls Pin
CoolAL2-Jul-08 4:29
CoolAL2-Jul-08 4:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.