Recently in a small program, you need to create a very small borderless window, the height of the window is about 25 pixels, and then create a new normal form, and the following code:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ClickThroughTest
{
public partial class ClickThroughForm : Form
{
public ClickThroughForm()
{
InitializeComponent();
this.FormBorderStyle = FormBorderStyle.FixedSingle;
this.StartPosition = FormStartPosition.Manual;
this.Text = String.Empty;
this.ShowInTaskbar = false;
this.ControlBox = false;
}
public void AdjustSize()
{
Size newSize = new Size(80, 25);
this.Size = newSize;
}
}
}
Strange thing happened, the window size than I specified a lot of, with Spy4win looked, as if the 124*36, rather than I specified 80*25, as shown in the following figure:
Scratching for a long time, and repeatedly check the code, sure that they did not make mistakes in what place, by repeatedly modifying the size value test, found that the size is larger than the 124*36 can be correctly set size, otherwise it will not be displayed correctly.
Helpless under the Google, found that seems to be a bug WinForm, find solutions, no fruit.
About one hours later, when depressed, suddenly found maximunsize and minimumsize two attributes, Demadan, after repeated testing to modify the code as follows:
public void AdjustSize()
{
Size newSize = new Size(80, 25);
this.MaximumSize = this.MinimumSize =
newSize;
this.Size = newSize;
}
Very surprised to find incredibly good, the effect is as follows:
Note: You must set both MaximumSize and minimumsize to resolve this problem, or display errors, minimumsize can be set arbitrarily, such as new Size (1, 1).
Although it is a small problem, but sometimes can be used to share, hehe O (∩_∩) o~
[Update] Finally realize the Quick toolbar, record, hehe. The red box is the small toolbar that corrects the size problem.