show form problem

G

Guest

Here is the deal, if you have 2 forms, show one after the other, then show again, the second time it shows, it moves the
form window down to location 0,26 then if you do it again its fine (0,0), only on the second refresh? Why

try this code

using System
using System.Drawing
using System.Collections
using System.ComponentModel
using System.Windows.Forms
public class TestForm3 : System.Windows.Forms.For

private System.Windows.Forms.TextBox textBox1
private System.Windows.Forms.TextBox tb

public TestForm3(string t

InitializeComponent()
tb.Text = t


private void InitializeComponent(

this.tb = new System.Windows.Forms.TextBox()
this.textBox1 = new System.Windows.Forms.TextBox()
this.tb.Text = "textBox1"
this.textBox1.Location = new System.Drawing.Point(104, 0)
this.textBox1.Text = "Top"
this.Controls.Add(this.textBox1)
this.Controls.Add(this.tb)
this.Load += new System.EventHandler(this.TestForm3_Load)

private void TestForm3_Load(object sender, System.EventArgs e

this.MaximizeBox = false
this.MinimizeBox = false
this.ControlBox = false
this.FormBorderStyle = FormBorderStyle.None
this.WindowState = FormWindowState.Maximized
this.Menu = null

static void Main()
{
TestForm3 t = new TestForm3("1")
TestForm3 t2 = new TestForm3("2")

//first tim
t.Show()
t.Refresh()
t2.Show()
t2.Refresh()
//second time location move
t.Show()
t.Refresh()
t2.Show()
t2.Refresh()
t2.Hide()
System.Threading.Thread.Sleep(10000)



What gives
 
G

Guest

The main thread doesn't have the time to process all the message windows before it enters in the sleep mode. So force the system to process those messages using Application.DoEvents() before thread sleep. You won't get the error anymore!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top