<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Create custom UI appearance for WinForms RadioButton - part 3</title>
	<atom:link href="http://devblog.antongochev.net/2008/07/09/create-custom-ui-appearance-for-winforms-radiobutton-part-3/feed/" rel="self" type="application/rss+xml" />
	<link>http://devblog.antongochev.net/2008/07/09/create-custom-ui-appearance-for-winforms-radiobutton-part-3/</link>
	<description>Programming is an art...</description>
	<pubDate>Mon, 21 May 2012 05:59:35 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Maulik</title>
		<link>http://devblog.antongochev.net/2008/07/09/create-custom-ui-appearance-for-winforms-radiobutton-part-3/#comment-227</link>
		<dc:creator>Maulik</dc:creator>
		<pubDate>Fri, 06 Mar 2009 07:28:41 +0000</pubDate>
		<guid isPermaLink="false">http://ganton.wordpress.com/?p=42#comment-227</guid>
		<description>Hello Anton,

I used your code and that solved my problem. Great work !!!

Thanks again.</description>
		<content:encoded><![CDATA[<p>Hello Anton,</p>
<p>I used your code and that solved my problem. Great work !!!</p>
<p>Thanks again.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ganton</title>
		<link>http://devblog.antongochev.net/2008/07/09/create-custom-ui-appearance-for-winforms-radiobutton-part-3/#comment-226</link>
		<dc:creator>ganton</dc:creator>
		<pubDate>Thu, 05 Mar 2009 21:54:20 +0000</pubDate>
		<guid isPermaLink="false">http://ganton.wordpress.com/?p=42#comment-226</guid>
		<description>Hi Maulik,

Initially, I extended standard RadioButton in order ust to change its default appearance without controlling the auto size because the base class OnPaint will change all my estimations if AutoSize mode is on. That is why it works only in non AutoSize mode.

I can offer you a simple work around that is not very elegant but it may help you to use the control in AutoSize mode.

You need to override AutoSize property in order to suspend original RadioButton logic when custom appearance is activated and to allow original logic when custom appearance is not activated.

private bool _customAutoSize = false;
public override bool AutoSize
{
	get
	{
		if (!_enableCustomUIAppearance)
		{
			return base.AutoSize;
		}
		return _customAutoSize;
	}
	set
	{
		if (!_enableCustomUIAppearance)
		{
			base.AutoSize = value;
		}
		else if (_customAutoSize != value)
		{
			_customAutoSize = value;
			Invalidate();					
		}
	}
}

Than you can simply extend the OnPaint method adding the code below before calculate offset comment.

if (_customAutoSize)
{
Width = (int)((stringMeasure.Width + Padding.Left + Padding.Right + offset + distance + radioButtonWidthHeight) + 0.5);
Height = (int)((stringMeasure.Height + Padding.Top + Padding.Bottom + offset) + 0.5);
}

Then remove the else statement of calculate offsets and you also should remove OnAutoSizeChanged. Please remove setting of AutoSize in EnableCustomUIAppearance property.

Regards,
Anton</description>
		<content:encoded><![CDATA[<p>Hi Maulik,</p>
<p>Initially, I extended standard RadioButton in order ust to change its default appearance without controlling the auto size because the base class OnPaint will change all my estimations if AutoSize mode is on. That is why it works only in non AutoSize mode.</p>
<p>I can offer you a simple work around that is not very elegant but it may help you to use the control in AutoSize mode.</p>
<p>You need to override AutoSize property in order to suspend original RadioButton logic when custom appearance is activated and to allow original logic when custom appearance is not activated.</p>
<p>private bool _customAutoSize = false;<br />
public override bool AutoSize<br />
{<br />
	get<br />
	{<br />
		if (!_enableCustomUIAppearance)<br />
		{<br />
			return base.AutoSize;<br />
		}<br />
		return _customAutoSize;<br />
	}<br />
	set<br />
	{<br />
		if (!_enableCustomUIAppearance)<br />
		{<br />
			base.AutoSize = value;<br />
		}<br />
		else if (_customAutoSize != value)<br />
		{<br />
			_customAutoSize = value;<br />
			Invalidate();<br />
		}<br />
	}<br />
}</p>
<p>Than you can simply extend the OnPaint method adding the code below before calculate offset comment.</p>
<p>if (_customAutoSize)<br />
{<br />
Width = (int)((stringMeasure.Width + Padding.Left + Padding.Right + offset + distance + radioButtonWidthHeight) + 0.5);<br />
Height = (int)((stringMeasure.Height + Padding.Top + Padding.Bottom + offset) + 0.5);<br />
}</p>
<p>Then remove the else statement of calculate offsets and you also should remove OnAutoSizeChanged. Please remove setting of AutoSize in EnableCustomUIAppearance property.</p>
<p>Regards,<br />
Anton</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Maulik</title>
		<link>http://devblog.antongochev.net/2008/07/09/create-custom-ui-appearance-for-winforms-radiobutton-part-3/#comment-224</link>
		<dc:creator>Maulik</dc:creator>
		<pubDate>Thu, 05 Mar 2009 11:38:28 +0000</pubDate>
		<guid isPermaLink="false">http://ganton.wordpress.com/?p=42#comment-224</guid>
		<description>Hello Anton,

First of all thanks for your nice work. I appreciate your work. 

Now, I found one problem while using radiobutton code. Description is given bellow.

In AutoSize = true mode if you assign radiobutton's Text property to more then 60 characters string. Text is trimmed from right side. Please guide me how to solve this problem ?

To replicate this problem just do some change in above code..
 protected override void OnAutoSizeChanged(EventArgs e)
        {
            if (_enableCustomUIAppearance)
            {
                ////Set AutoSize to false.
                //if (AutoSize)
                //{
                //    AutoSize = false;
                //}
            }
            base.OnAutoSizeChanged(e);
        }
After this just build dll and use it in application. You can see the problem. 

Control is working fine when text is less then 55 characters. I particularly want to set AutoSize = true because in my application i want to generate controls at runtime.

Thanks.</description>
		<content:encoded><![CDATA[<p>Hello Anton,</p>
<p>First of all thanks for your nice work. I appreciate your work. </p>
<p>Now, I found one problem while using radiobutton code. Description is given bellow.</p>
<p>In AutoSize = true mode if you assign radiobutton&#8217;s Text property to more then 60 characters string. Text is trimmed from right side. Please guide me how to solve this problem ?</p>
<p>To replicate this problem just do some change in above code..<br />
 protected override void OnAutoSizeChanged(EventArgs e)<br />
        {<br />
            if (_enableCustomUIAppearance)<br />
            {<br />
                ////Set AutoSize to false.<br />
                //if (AutoSize)<br />
                //{<br />
                //    AutoSize = false;<br />
                //}<br />
            }<br />
            base.OnAutoSizeChanged(e);<br />
        }<br />
After this just build dll and use it in application. You can see the problem. </p>
<p>Control is working fine when text is less then 55 characters. I particularly want to set AutoSize = true because in my application i want to generate controls at runtime.</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: whydzxx</title>
		<link>http://devblog.antongochev.net/2008/07/09/create-custom-ui-appearance-for-winforms-radiobutton-part-3/#comment-130</link>
		<dc:creator>whydzxx</dc:creator>
		<pubDate>Wed, 06 Aug 2008 02:37:19 +0000</pubDate>
		<guid isPermaLink="false">http://ganton.wordpress.com/?p=42#comment-130</guid>
		<description>thank you</description>
		<content:encoded><![CDATA[<p>thank you</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Create custom UI appearance for WinForms controls - part 1 &#187; Anton Gochev&#8217;s Weblog</title>
		<link>http://devblog.antongochev.net/2008/07/09/create-custom-ui-appearance-for-winforms-radiobutton-part-3/#comment-116</link>
		<dc:creator>Create custom UI appearance for WinForms controls - part 1 &#187; Anton Gochev&#8217;s Weblog</dc:creator>
		<pubDate>Thu, 31 Jul 2008 13:10:09 +0000</pubDate>
		<guid isPermaLink="false">http://ganton.wordpress.com/?p=42#comment-116</guid>
		<description>[...] posts in this series: Post 1, Post 2, Post 3, Post 4, Post 5, Post 6, Source [...]</description>
		<content:encoded><![CDATA[<p>[...] posts in this series: Post 1, Post 2, Post 3, Post 4, Post 5, Post 6, Source [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Create custom UI appearance for WinForms CustomButton - part 4 &#187; Anton Gochev&#8217;s Weblog</title>
		<link>http://devblog.antongochev.net/2008/07/09/create-custom-ui-appearance-for-winforms-radiobutton-part-3/#comment-115</link>
		<dc:creator>Create custom UI appearance for WinForms CustomButton - part 4 &#187; Anton Gochev&#8217;s Weblog</dc:creator>
		<pubDate>Thu, 31 Jul 2008 13:07:34 +0000</pubDate>
		<guid isPermaLink="false">http://ganton.wordpress.com/?p=42#comment-115</guid>
		<description>[...] posts in this series: Post 1, Post 2, Post 3, Post 4, Post 5, Post 6, Source [...]</description>
		<content:encoded><![CDATA[<p>[...] posts in this series: Post 1, Post 2, Post 3, Post 4, Post 5, Post 6, Source [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

