My problem today is that my windows form application has one second or more of black before displaying full screen. That make it not smooth when restoring the windows or change from minimize state to maximize. Even when the application contains only some control on the screen only.
I have tried to disable / comment out all of the source code that related to the resize related events of windows. But that doesn't resolve the issue.
After all, I thought that the solution must be that we can catch the event when user begin to maximize the windows and temporary suspend the layout redraw, then when the application comes to maximized state, we will allow it to resume the layout. Therefore, the last source code of the application will be somehow like the following.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TestMaximizeWindows
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
protected override void WndProc(ref Message m)
{
var msg = '\x112';
const int minimize = '\xf020';
const int maximize = '\xf030';
const int restore = '\xf120';
if (m.Msg == msg)
{
Console.WriteLine(m.ToString());
var param = m.WParam.ToInt32();
switch (param)
{
case minimize:
// handle minimize
break;
case maximize:
// handle maximize
this.SuspendLayout();
break;
case restore:
// handle restore
this.SuspendLayout();
break;
}
}
base.WndProc(ref m);
}
private void Form1_SizeChanged(object sender, EventArgs e)
{
this.ResumeLayout();
}
}
}
There are two other events that you can use in this WinProc method
private const Int32 WM_SIZE = 0x0005; private const Int32 WM_SIZING = 0x0214;
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.