Workaround for form size cannot be modified

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.