by Ahmadreza Atighechi
28. November 2009 21:48
Two days ago a question was asked in StackOverflow.com and I found this question so good to prepare a post. I want to explain this question:
Petr asked: I do not understand why there is Control.padding.all which is int and according to hint there is set as well as get but I cannot set it (Control.Padding.All=5)? I would be grateful for explanation.
For example when you want to set
textBox1.Padding.All = 5;
You will get this compiling error: Cannot modify the return value of 'System.Windows.Forms.TextBoxBase.Padding' because it is not a variable
Following example is an implementation of this error:
public class ARAControl
{
public ARAPadding Padding { get; set; }
}
public struct ARAPadding
{
public int All { get; set; }
}
If you use this you'll get mentioned error:
ARAControl control = new ARAControl();
control.Padding.All = 10;
And why this compiling error happens. It hapens because structure is a value type. By setting this property you first call get Method. "Property Get" will return a copy of ARAPadding, so it is a value type and C# will detect out mistake and prevent compiling.
171b04d3-333a-43e8-86f3-dca922f0b63f|0|.0
Tags: c#
Blog
by Ahmadreza Atighechi
20. November 2009 10:31
I was about to write a simple application deal with screen size in WPF. Previously in windows form applications we could get WorkingArea parameters from System.Windows.Forms.WorkingArea but in WPF application typically we don’t have this assembly (however this assembly could be added to project). In WPF applications screen size could be obtained from System.Windows.SystemParameters. Following code is an example of setting a form right-bottom aligned in screen.
Windows form application:
this.Top = Screen.PrimaryScreen.WorkingArea.Height - this.Height;
this.Left = Screen.PrimaryScreen.WorkingArea.Width - this.Width;
WPF application:
this.Top = System.Windows.SystemParameters.WorkArea.Height - this.Height;
this.Left = System.Windows.SystemParameters.WorkArea.Width - this.Width;
P.S. 2009/11/30: A friend of mine just asked "Is it possible to get all screen size (in multiple screen) in WPF without refering to System.Windows.Forms". As far as I see, It seems it is not possible to get other screens than current workarea unless you Use System.Windows.Forms.
b3349270-dc1a-49c6-a88c-acf1990a781d|0|.0
Tags: wpf