I am creating a custom control in c # winforms. I added ICON to the resource, this icon is then drawn on the control using the following code:
using (Icon oIcon = Properties.Resources.DropDownCustom)
{
Rectangle RectangleIcon = new Rectangle((DropDownRectangle.X + ((DropDownRectangle.Width / 2) - (oIcon.Width / 2))),
(DropDownRectangle.Y + (((DropDownRectangle.Height / 2) - (oIcon.Height / 2)) + 1)),
oIcon.Width,
oIcon.Height);
graphics.DrawIcon(oIcon, RectangleIcon);
}
All this works fine, but I decided to add a parameter to the control properties, to allow the developer to load his own icon, and not use the one that I posted in the resource. I created a private icon variable:
private Icon _DropDownCustom;
changed the "using" line in the above code as follows:
using (Icon oIcon = _DropDownCustom)
and then added the following line to the constructor to set the default value to the value specified in the resources.
_DropDownCustom = Properties.Resources.DropDownCustom;
Then I added the Icon property so that the developer can use his icon:
[Category("Appearance"), DisplayName("IconDropDown")]
public Icon IconDropDownCustom
{
get { return _DropDownCustom; }
set { _DropDownCustom = value; this.Invalidate(); }
}
, , , , ( ), - , , , (, ).
- , ?
.
EDIT:
"Using(){}" :
Icon oIcon = _DropDownCustom;
Rectangle RectangleIcon = new Rectangle((DropDownRectangle.X + ((DropDownRectangle.Width / 2) - (oIcon.Width / 2))),
(DropDownRectangle.Y + (((DropDownRectangle.Height / 2) - (oIcon.Height / 2)) + 1)),
oIcon.Width,
oIcon.Height);
graphics.DrawIcon(oIcon, RectangleIcon);
, , , - - - , ? , "oIcon" Icon, " " ( VB).