Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 125
  • Last Modified:

Paint/Redraw window while dragging

How do I get a window (form) to redraw as it's being dragged?  The form in question is set to always be on top.  This is a class that  inherits "Form".   Here the code that sets the style and exstyle for the window:

 
Protected Overrides ReadOnly Property CreateParams As System.Windows.Forms.CreateParams
        Get

            Const WS_SIZEBOX As Integer = &H40000
            Const WS_EX_TOOLWINDOW As Integer = &H80
            Const WS_EX_NOACTIVATE As Integer = &H8000000
            Const WS_EX_TOPMOST As Integer = &H8

            Dim params As CreateParams = MyBase.CreateParams
            params.Style = params.Style And (Not WS_SIZEBOX)
            params.ExStyle = params.ExStyle Or WS_EX_NOACTIVATE Or WS_EX_TOOLWINDOW Or WS_EX_TOPMOST
            Return params

        End Get
    End Property
0
HLRosenberger
Asked:
HLRosenberger
  • 10
  • 6
1 Solution
 
AndyAinscowCommented:
I've created a new project.  On the default form I've added one button.  I've inserted another form into the project.
Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim f As Form2 = New Form2()
        f.Show()
    End Sub
End Class

Open in new window


Public Class Form2
    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub


    Protected Overrides ReadOnly Property CreateParams As System.Windows.Forms.CreateParams
        Get

            Const WS_SIZEBOX As Integer = &H40000
            Const WS_EX_TOOLWINDOW As Integer = &H80
            Const WS_EX_NOACTIVATE As Integer = &H8000000
            Const WS_EX_TOPMOST As Integer = &H8

            Dim params As CreateParams = MyBase.CreateParams
            params.Style = params.Style And (Not WS_SIZEBOX)
            params.ExStyle = params.ExStyle Or WS_EX_NOACTIVATE Or WS_EX_TOOLWINDOW Or WS_EX_TOPMOST
            Return params

        End Get
    End Property
End Class

Open in new window


When dragging the second form it redraws.  (I put a listbox with some items in it just so there would be something there.)

Please check yourself on your PC that the above does work as you want.

I guess you have changed something you aren't telling us about thinking it isn't important, unfortunately it is the critical missing link.
0
 
AndyAinscowCommented:
ps.  I did check with a breakpoint that the CreateParams code is being run.  It is.
0
 
HLRosenbergerAuthor Commented:
I created that project and it does work fine as far as painting.    Looking at my code now....
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
HLRosenbergerAuthor Commented:
my form has controls on it.  Maybe that comes into play?  Here's the designer code:



 Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(NumericKeypad))
        Me.Panel1 = New System.Windows.Forms.Panel()
        Me.panelUndock = New System.Windows.Forms.Panel()
        Me.labelUndock = New System.Windows.Forms.Label()
        Me.TableLayoutPanel1 = New System.Windows.Forms.TableLayoutPanel()
        Me.btnLeft = New System.Windows.Forms.Button()
        Me.btnDown = New System.Windows.Forms.Button()
        Me.btnBackspace = New System.Windows.Forms.Button()
        Me.btn7 = New System.Windows.Forms.Button()
        Me.btn8 = New System.Windows.Forms.Button()
        Me.btn9 = New System.Windows.Forms.Button()
        Me.btn5 = New System.Windows.Forms.Button()
        Me.btn6 = New System.Windows.Forms.Button()
        Me.btn1 = New System.Windows.Forms.Button()
        Me.btn2 = New System.Windows.Forms.Button()
        Me.btn3 = New System.Windows.Forms.Button()
        Me.btn0 = New System.Windows.Forms.Button()
        Me.btnDecimal = New System.Windows.Forms.Button()
        Me.btn4 = New System.Windows.Forms.Button()
        Me.btnUp = New System.Windows.Forms.Button()
        Me.btnRight = New System.Windows.Forms.Button()
        Me.Panel1.SuspendLayout()
        Me.panelUndock.SuspendLayout()
        Me.TableLayoutPanel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'Panel1
        '
        Me.Panel1.Controls.Add(Me.panelUndock)
        Me.Panel1.Controls.Add(Me.TableLayoutPanel1)
        Me.Panel1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.Panel1.Location = New System.Drawing.Point(0, 0)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(248, 181)
        Me.Panel1.TabIndex = 2
        '
        'panelUndock
        '
        Me.panelUndock.BackColor = System.Drawing.SystemColors.ActiveCaption
        Me.panelUndock.Controls.Add(Me.labelUndock)
        Me.panelUndock.Dock = System.Windows.Forms.DockStyle.Fill
        Me.panelUndock.Location = New System.Drawing.Point(0, 157)
        Me.panelUndock.Name = "panelUndock"
        Me.panelUndock.Size = New System.Drawing.Size(248, 24)
        Me.panelUndock.TabIndex = 3
        '
        'labelUndock
        '
        Me.labelUndock.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.labelUndock.Dock = System.Windows.Forms.DockStyle.Fill
        Me.labelUndock.Location = New System.Drawing.Point(0, 0)
        Me.labelUndock.Name = "labelUndock"
        Me.labelUndock.Size = New System.Drawing.Size(248, 24)
        Me.labelUndock.TabIndex = 0
        Me.labelUndock.Text = "Numpad"
        Me.labelUndock.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'TableLayoutPanel1
        '
        Me.TableLayoutPanel1.ColumnCount = 4
        Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25.0!))
        Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25.0!))
        Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25.0!))
        Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25.0!))
        Me.TableLayoutPanel1.Controls.Add(Me.btnLeft, 3, 2)
        Me.TableLayoutPanel1.Controls.Add(Me.btnDown, 3, 1)
        Me.TableLayoutPanel1.Controls.Add(Me.btnBackspace, 0, 3)
        Me.TableLayoutPanel1.Controls.Add(Me.btn7, 0, 0)
        Me.TableLayoutPanel1.Controls.Add(Me.btn8, 1, 0)
        Me.TableLayoutPanel1.Controls.Add(Me.btn9, 2, 0)
        Me.TableLayoutPanel1.Controls.Add(Me.btn5, 1, 1)
        Me.TableLayoutPanel1.Controls.Add(Me.btn6, 2, 1)
        Me.TableLayoutPanel1.Controls.Add(Me.btn1, 0, 2)
        Me.TableLayoutPanel1.Controls.Add(Me.btn2, 1, 2)
        Me.TableLayoutPanel1.Controls.Add(Me.btn3, 2, 2)
        Me.TableLayoutPanel1.Controls.Add(Me.btn0, 0, 3)
        Me.TableLayoutPanel1.Controls.Add(Me.btnDecimal, 1, 3)
        Me.TableLayoutPanel1.Controls.Add(Me.btn4, 0, 1)
        Me.TableLayoutPanel1.Controls.Add(Me.btnUp, 3, 0)
        Me.TableLayoutPanel1.Controls.Add(Me.btnRight, 3, 3)
        Me.TableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Top
        Me.TableLayoutPanel1.Location = New System.Drawing.Point(0, 0)
        Me.TableLayoutPanel1.Name = "TableLayoutPanel1"
        Me.TableLayoutPanel1.RowCount = 4
        Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 25.0!))
        Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 25.0!))
        Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 25.0!))
        Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 25.0!))
        Me.TableLayoutPanel1.Size = New System.Drawing.Size(248, 157)
        Me.TableLayoutPanel1.TabIndex = 2
        '
        'btnLeft
        '
        Me.btnLeft.BackgroundImage = CType(resources.GetObject("btnLeft.BackgroundImage"), System.Drawing.Image)
        Me.btnLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center
        Me.btnLeft.Dock = System.Windows.Forms.DockStyle.Top
        Me.btnLeft.Location = New System.Drawing.Point(196, 81)
        Me.btnLeft.Margin = New System.Windows.Forms.Padding(10, 3, 3, 3)
        Me.btnLeft.Name = "btnLeft"
        Me.btnLeft.Size = New System.Drawing.Size(49, 33)
        Me.btnLeft.TabIndex = 16
        Me.btnLeft.UseVisualStyleBackColor = True
        '
        'btnDown
        '
        Me.btnDown.BackgroundImage = CType(resources.GetObject("btnDown.BackgroundImage"), System.Drawing.Image)
        Me.btnDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch
        Me.btnDown.Dock = System.Windows.Forms.DockStyle.Fill
        Me.btnDown.Location = New System.Drawing.Point(196, 42)
        Me.btnDown.Margin = New System.Windows.Forms.Padding(10, 3, 3, 3)
        Me.btnDown.Name = "btnDown"
        Me.btnDown.Size = New System.Drawing.Size(49, 33)
        Me.btnDown.TabIndex = 15
        Me.btnDown.UseVisualStyleBackColor = True
        '
        'btnBackspace
        '
        Me.btnBackspace.Dock = System.Windows.Forms.DockStyle.Fill
        Me.btnBackspace.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnBackspace.Location = New System.Drawing.Point(3, 120)
        Me.btnBackspace.Name = "btnBackspace"
        Me.btnBackspace.Size = New System.Drawing.Size(56, 34)
        Me.btnBackspace.TabIndex = 5
        Me.btnBackspace.Text = "Back"
        Me.btnBackspace.UseVisualStyleBackColor = True
        '
        'btn7
        '
        Me.btn7.Dock = System.Windows.Forms.DockStyle.Fill
        Me.btn7.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btn7.Location = New System.Drawing.Point(3, 3)
        Me.btn7.Name = "btn7"
        Me.btn7.Size = New System.Drawing.Size(56, 33)
        Me.btn7.TabIndex = 2
        Me.btn7.Text = "7"
        Me.btn7.UseVisualStyleBackColor = True
        '
        'btn8
        '
        Me.btn8.Dock = System.Windows.Forms.DockStyle.Fill
        Me.btn8.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btn8.Location = New System.Drawing.Point(65, 3)
        Me.btn8.Name = "btn8"
        Me.btn8.Size = New System.Drawing.Size(56, 33)
        Me.btn8.TabIndex = 3
        Me.btn8.Text = "8"
        Me.btn8.UseVisualStyleBackColor = True
        '
        'btn9
        '
        Me.btn9.Dock = System.Windows.Forms.DockStyle.Fill
        Me.btn9.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btn9.Location = New System.Drawing.Point(127, 3)
        Me.btn9.Name = "btn9"
        Me.btn9.Size = New System.Drawing.Size(56, 33)
        Me.btn9.TabIndex = 6
        Me.btn9.Text = "9"
        Me.btn9.UseVisualStyleBackColor = True
        '
        'btn5
        '
        Me.btn5.Dock = System.Windows.Forms.DockStyle.Fill
        Me.btn5.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btn5.Location = New System.Drawing.Point(65, 42)
        Me.btn5.Name = "btn5"
        Me.btn5.Size = New System.Drawing.Size(56, 33)
        Me.btn5.TabIndex = 8
        Me.btn5.Text = "5"
        Me.btn5.UseVisualStyleBackColor = True
        '
        'btn6
        '
        Me.btn6.Dock = System.Windows.Forms.DockStyle.Fill
        Me.btn6.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btn6.Location = New System.Drawing.Point(127, 42)
        Me.btn6.Name = "btn6"
        Me.btn6.Size = New System.Drawing.Size(56, 33)
        Me.btn6.TabIndex = 9
        Me.btn6.Text = "6"
        Me.btn6.UseVisualStyleBackColor = True
        '
        'btn1
        '
        Me.btn1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.btn1.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btn1.Location = New System.Drawing.Point(3, 81)
        Me.btn1.Name = "btn1"
        Me.btn1.Size = New System.Drawing.Size(56, 33)
        Me.btn1.TabIndex = 10
        Me.btn1.Text = "1"
        Me.btn1.UseVisualStyleBackColor = True
        '
        'btn2
        '
        Me.btn2.Dock = System.Windows.Forms.DockStyle.Fill
        Me.btn2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btn2.Location = New System.Drawing.Point(65, 81)
        Me.btn2.Name = "btn2"
        Me.btn2.Size = New System.Drawing.Size(56, 33)
        Me.btn2.TabIndex = 11
        Me.btn2.Text = "2"
        Me.btn2.UseVisualStyleBackColor = True
        '
        'btn3
        '
        Me.btn3.Dock = System.Windows.Forms.DockStyle.Fill
        Me.btn3.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btn3.Location = New System.Drawing.Point(127, 81)
        Me.btn3.Name = "btn3"
        Me.btn3.Size = New System.Drawing.Size(56, 33)
        Me.btn3.TabIndex = 12
        Me.btn3.Text = "3"
        Me.btn3.UseVisualStyleBackColor = True
        '
        'btn0
        '
        Me.btn0.Dock = System.Windows.Forms.DockStyle.Fill
        Me.btn0.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btn0.Location = New System.Drawing.Point(65, 120)
        Me.btn0.Name = "btn0"
        Me.btn0.Size = New System.Drawing.Size(56, 34)
        Me.btn0.TabIndex = 4
        Me.btn0.Text = "0"
        Me.btn0.UseVisualStyleBackColor = True
        '
        'btnDecimal
        '
        Me.btnDecimal.Dock = System.Windows.Forms.DockStyle.Fill
        Me.btnDecimal.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnDecimal.Location = New System.Drawing.Point(127, 120)
        Me.btnDecimal.Name = "btnDecimal"
        Me.btnDecimal.Size = New System.Drawing.Size(56, 34)
        Me.btnDecimal.TabIndex = 13
        Me.btnDecimal.Text = "."
        Me.btnDecimal.UseVisualStyleBackColor = True
        '
        'btn4
        '
        Me.btn4.Dock = System.Windows.Forms.DockStyle.Fill
        Me.btn4.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btn4.Location = New System.Drawing.Point(3, 42)
        Me.btn4.Name = "btn4"
        Me.btn4.Size = New System.Drawing.Size(56, 33)
        Me.btn4.TabIndex = 7
        Me.btn4.Text = "4"
        Me.btn4.UseVisualStyleBackColor = True
        '
        'btnUp
        '
        Me.btnUp.BackgroundImage = CType(resources.GetObject("btnUp.BackgroundImage"), System.Drawing.Image)
        Me.btnUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch
        Me.btnUp.Dock = System.Windows.Forms.DockStyle.Fill
        Me.btnUp.Location = New System.Drawing.Point(196, 3)
        Me.btnUp.Margin = New System.Windows.Forms.Padding(10, 3, 3, 3)
        Me.btnUp.Name = "btnUp"
        Me.btnUp.Size = New System.Drawing.Size(49, 33)
        Me.btnUp.TabIndex = 14
        Me.btnUp.UseVisualStyleBackColor = True
        '
        'btnRight
        '
        Me.btnRight.BackgroundImage = CType(resources.GetObject("btnRight.BackgroundImage"), System.Drawing.Image)
        Me.btnRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center
        Me.btnRight.Dock = System.Windows.Forms.DockStyle.Fill
        Me.btnRight.Location = New System.Drawing.Point(196, 120)
        Me.btnRight.Margin = New System.Windows.Forms.Padding(10, 3, 3, 3)
        Me.btnRight.Name = "btnRight"
        Me.btnRight.Size = New System.Drawing.Size(49, 34)
        Me.btnRight.TabIndex = 17
        Me.btnRight.UseVisualStyleBackColor = True
        '
        'NumericKeypad
        '
        Me.ClientSize = New System.Drawing.Size(248, 181)
        Me.Controls.Add(Me.Panel1)
        Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "NumericKeypad"
        Me.Panel1.ResumeLayout(False)
        Me.panelUndock.ResumeLayout(False)
        Me.TableLayoutPanel1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub
0
 
HLRosenbergerAuthor Commented:
if I comment out all code related to the controls, then the form paints fine.
0
 
AndyAinscowCommented:
OK.  
First make a copy of the project.
Second try some butchery - remove something, recompile and try dragging.  Keep repeating until the proper drawing behavior comes back.
Third assuming removal of something makes a change put the original project back into place (keep a copy) and try just removing that thing.

The above is to try and see if one particular thing is giving problems.
0
 
AndyAinscowCommented:
>>if I comment out all code related to the controls, then the form paints fine.
OK, something gives problems.  Try to find what.
0
 
HLRosenbergerAuthor Commented:
if I eliminate the WS_EX_NOACTIVATE, then all seems to work.  However, I need WS_EX_NOACTIVATE.  My little app is a Numeric-only Keypad.  I can have it take focus away from any other app.
0
 
HLRosenbergerAuthor Commented:
So, it must the combination of  using WS_EX_NOACTIVATE, with controls on the form.  You example does not have any controls, other than that single button.
0
 
AndyAinscowCommented:
The example does have the WS_EX_NOACTIVATE extended style and a control (button) on the form.
Please try removing your controls stepwise as I suggested - something is causing a problem and you need to find out which control.
0
 
HLRosenbergerAuthor Commented:
Got it.  ok.
0
 
HLRosenbergerAuthor Commented:
ah, I think I figured it out.   In your example, you have two forms - one form shows the other.   In my project, I only have one form and it's the startup form.  

if I take your simple project and make the startup form the one that has the custom CreateParams property, I now get the same painting issue.  Could you please try this as well?
0
 
AndyAinscowCommented:
Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim f As Form2 = New Form2()
        f.Show()
    End Sub


    Protected Overrides ReadOnly Property CreateParams As System.Windows.Forms.CreateParams
        Get

            Const WS_SIZEBOX As Integer = &H40000
            Const WS_EX_TOOLWINDOW As Integer = &H80
            Const WS_EX_NOACTIVATE As Integer = &H8000000
            Const WS_EX_TOPMOST As Integer = &H8

            Dim params As CreateParams = MyBase.CreateParams
            params.Style = params.Style And (Not WS_SIZEBOX)
            params.ExStyle = params.ExStyle Or WS_EX_NOACTIVATE Or WS_EX_TOOLWINDOW Or WS_EX_TOPMOST
            Return params

        End Get
    End Property

End Class

Open in new window


Nope - still paints OK when dragging even as the startup form
0
 
HLRosenbergerAuthor Commented:
then I'm at a loss to explain.   I've created a brand new project.  Added two forms, one being the custom form with CreateParams, the other being the default startup form with a button.    If I show the custom form after clicking the button on the startup form, all is OK.   if I make the custom form the startup form, it does not paint while dragging.  

Please note this:  you have to create an EXE to show this issue, or minimize Visual Studio while the custom form is shown.  Then as you drag across the desktop, it does not paint while dragging
0
 
HLRosenbergerAuthor Commented:
0
 
HLRosenbergerAuthor Commented:
thanks for all your help/
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 10
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now