Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / August 2005

Tip: Looking for answers? Try searching our database.

Flicker Problems when Drawing a Custom Radio Button

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
joshuaphillips@comcast.net - 11 Aug 2005 22:57 GMT
Hi All,

I have created a radio button that uses images instead of the silly
"circle" for a touch-screen kiosk application where users will have to
use their large fingers to select radio buttons.  For some reason,
however, I can not get the damn thing to stop flickering!  Would
anybody (with past experience in this) be able to look at my code and
see what they think?  It would be greatly appreciated!

This is what I've got..

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace System.Windows.Forms
{
    /// <summary>
    /// Summary description for UserControl1.
    /// </summary>
    public class KioskRadioButton : RadioButton
    {
        public Image ImageSelected
        {
            get
            {
                return myImageSelected;
            }
            set
            {
                myImageSelected = value;
            }
        }
        private Image myImageSelected;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public KioskRadioButton()
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.DoubleBuffer, true);
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Component Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            components = new System.ComponentModel.Container();
            this.Paint += new PaintEventHandler(MyRadioButton_Paint);
        }
        #endregion

        private void MyRadioButton_Paint(object sender, PaintEventArgs e)
        {
            if (this.Checked)
            {
                e.Graphics.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
                e.Graphics.Clear(this.BackColor);
                e.Graphics.DrawString(this.Text, this.Font, new
SolidBrush(this.ForeColor), this.Image.Width + 5,
e.ClipRectangle.Height/2 - this.Font.Height/2);
                e.Graphics.DrawImage(this.ImageSelected, 0,
e.ClipRectangle.Height/2 - this.ImageSelected.Height/2);
            }
            else
            {
                e.Graphics.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
                e.Graphics.Clear(this.BackColor);
                e.Graphics.DrawString(this.Text, this.Font, new
SolidBrush(this.ForeColor), this.Image.Width + 5,
e.ClipRectangle.Height/2 - this.Font.Height/2);
                e.Graphics.DrawImage(this.Image, 0, e.ClipRectangle.Height/2 -
this.Image.Height/2);
               
            }
        }
    }
}

Thank you!!
SharpCoderMP - 12 Aug 2005 10:17 GMT
i'm not sure but this probably has something to do with putting your
control's painting inside other container. i didn't have time to check
your code in details but i had similar problem when i was trying to put
my own user drawn control inside panel. despite setting double buffering
it flickered too. but when i put it outside as a control droping it just
on a form with visual designer all worked well. maybe if container
doesn't want to double buffer you wont be able to force it to do so. i
didn't had time to check why this was happening. maybe someone wise will
clear this up :)  but until then i'll sugest extending your code a bit
and instead inheriting from RadioButton inherit from Control and create
your control from scrach. this will give you more control over your
custom radio button. infact you have almost everything you need so this
shouldn't take too much time.

> Hi All,
>
[quoted text clipped - 105 lines]
>
> Thank you!!
joshuaphillips@comcast.net - 12 Aug 2005 18:37 GMT
i actually figured it out.  the main problem was that because i was
inheriting from Windows' RadioButton, I was actually using the base
class' OnMouseDown method.  Unfortunately, inside MS's OnMouseDown, the
control "highlights" the radio button, which was causing the flicker.
So i just had to override that method and it stopped the flickering.
thank you for your help though. =)

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.