Hi
I am have an application that runs in the system tray and creates a messenger type popup.
This all works fine (on my laptop), i have a checkbox that allows the user to view more details which then should resize the popup (form) to an expanded view showing a richtextbox..
I thought i had this cracked on my dev machine, but when testing on another pc with different resolution I cannot get this right????
I have placed the checkbox code below,to see if you anyone can point out where i am going wrong?
Many thanks
private void cb_Details_CheckedChanged(object sender, EventArgs e)
{
if (this.cb_Details.Checked == true)
{
this.Size = this.Size.Height == 614 ? new Size(458, 614) : new Size(458, 614);
// Application.DoEvents();
//X = Screen.GetWorkingArea(this).Width;
//Y = Screen.GetWorkingArea(this).Height;
//this.DesktopLocation = new Point(X - this.Width, Y + this.Height);
//this.Location = new Point(X - this.Width, Y + this.Height);
//this.DesktopLocation = new Point(Screen.PrimaryScreen.Bounds.Width - this.Width, Screen.PrimaryScreen.Bounds.Height - this.Height - 50);
}
else
{
this.Size = this.Size.Height == 149 ? new Size(458, 149) : new Size(458, 149);
//Application.DoEvents();
//X = Screen.GetWorkingArea(this).Width;
//Y = Screen.GetWorkingArea(this).Height;
//this.DesktopLocation = new Point(X - this.Width, Y + this.Height);
//X = Screen.GetWorkingArea(this).Width;
//Y = Screen.GetWorkingArea(this).Height;
//this.Location = new Point(X - this.Width, Y + this.Height);
//this.DesktopLocation = new Point(Screen.PrimaryScreen.Bounds.Width - this.Width, Screen.PrimaryScreen.Bounds.Height - this.Height - 50); this works great on my devmachine....
}
}
All the commented out areas are things i have tried the following works great on dev machine but thats it:
private void cb_Details_CheckedChanged(object sender, EventArgs e)
{
if (this.cb_Details.Checked == true)
{
this.Size = this.Size.Height == 614 ? new Size(458, 614) : new Size(458, 614);
Location = new Point(Screen.PrimaryScreen.Bounds.Width - this.Width, Screen.PrimaryScreen.Bounds.Height - this.Height - 50);
}
else
{
this.Size = this.Size.Height == 149 ? new Size(458, 149) : new Size(458, 149);
Location = new Point(Screen.PrimaryScreen.Bounds.Width - this.Width, Screen.PrimaryScreen.Bounds.Height - this.Height - 50);
}
}
Any assistance with this would be amazing
Thanks in advance

2 answers
OK thanks madhatter, unfortunately this did not address the behaviour i was seeing on client PC's.
The following solution has managed to cure this and it seems to be related to secondary forms.
Main Form Load:
Now if i add a second form for instance an about form the above does not apply and causes the behaviour of positioning the 2nd form to be wrong, I tried various AutoScaleMode options to no avail, what i had to do is on any secondary forms is this:
About Form:
the n_TaskBarHeight is as follows:
This gives the correct height value of the task bar so I can sit the app immediately above.
The following is the working code that implements the form size change via a checkbox:
Not sure if this is a logic problem on my side? but took me quite sometime to get this working, the above items work great on xp,vista,win 7 etc at different resolutions and dpi.
For reference with the above i have the AutoScaleMode set to Inherit.
Hope this goes someway to helping others.
Thanks
answered one year ago by:
482
change the AutoScaleMode on the window from "Font" (or whatever it is) to None.
answered one year ago by:
2309