leblancmeneses

http://www.sitepoint.com/forums/attachment.php attachmentid=47227&d=1170274266
shows a screenshot of my problem:

1) in intial load has transparency - like its supposed to,
2) control looks smeared ; doesn't repaint the full control.
3) working properly because I painted white on top of everything, but need it to be transparent.

couple of things I've tried:

protected override void OnPaint(System.Windows.Forms.PaintEventArgs e){
Graphics gfx = e.Graphics;
Rectangle rect = e.ClipRectangle;
gfx.Clear(Color.Transparent);
gfx.FillRectangle(new SolidBrush(Color.Transparent), rect);


also
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e){
Graphics gfx = e.Graphics;
Rectangle rect = e.ClipRectangle;
//create a brand new image but then nothing shows up.
gfx = Graphics.FromImage(new Bitmap(rect.Width, rect.Height));


if anyone can help me fix the transparency problem it would be much appreciated

reference: http://www.sitepoint.com/forums/showthread.php t=455552





using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Configuration;
using System.Drawing.Imaging;

namespace painlessperformance
{
    public partial class MyTrackBar : System.Windows.Forms.TrackBar
    {
        private TrackerSliderIcon _TrackerSliderIcon;
        public class TrackerSliderIcon
        {
            private RectangleF size = new RectangleF(0, 0, 0, 0);
            private Boolean capture = false;
           
           
            public Boolean Capture
            {
                get { return this.capture; }
                set { this.capture = value; }               
            }

            public Bitmap getIcon
            {
                get
                {
                    //Properties.Settings.Default //settings1.settings
                    //MessageBox.Show(ConfigurationManager.AppSettings["trackbar.slider.icon"]); //app.config

                    Bitmap b = (Bitmap)Bitmap.FromFile(@"C:\Documents and Settings\Administrator\My Documents\projects.net\pedal.jpg", true);
                    this.size = new RectangleF(this.size.X, this.size.Y, b.Width, b.Height);
                    return b;
                }
            }

            public RectangleF Size
            {
                get { return this.size; }
            }

            public Int32 X
            {
                set
                {
                    this.size.X = value - (Int32)(this.size.Width/2);
                }           
            }
            public Int32 Y
            {
                set
                {
                    this.size.Y = value - (Int32)(this.size.Height/2);
                }             
            }

        }

        public MyTrackBar()
        {
            this.SetStyle(ControlStyles.UserPaint|ControlStyles.AllPaintingInWmPaint|ControlStyles.SupportsTransparentBackColor, true);

            // setting the style in order to get
            //// double buffering, userpaint and redraw on resizinig

            this.MouseDown += new MouseEventHandler(OnMouseDownSlider);
            this.MouseUp += new MouseEventHandler(OnMouseUpSlider);
            this.MouseMove += new MouseEventHandler(OnMouseMoveSlider);

            this._TrackerSliderIcon = new TrackerSliderIcon();
        }

        //mouse pressed
        private void OnMouseDownSlider(object sender, MouseEventArgs e)
        {
            if (this._TrackerSliderIcon.Size.Contains(new PointF(e.X, e.Y)))
            {
                if (!this._TrackerSliderIcon.Capture)
                {
                    this._TrackerSliderIcon.Capture = true;
                }
            }
        }
        //mouse released
        private void OnMouseUpSlider(object sender, MouseEventArgs e)
        {
            this._TrackerSliderIcon.Capture = false;
        }
        //mouse moved
        private void OnMouseMoveSlider(object sender, MouseEventArgs e)
        {
            if (this._TrackerSliderIcon.Capture)
            {
                if (this.Orientation == Orientation.Horizontal)
                    this._TrackerSliderIcon.X = e.X;
                else
                    this._TrackerSliderIcon.Y = e.Y;


                this.Invalidate(this.Region, true); //new Rectangle(this.Location, this.Size),
                this.Update();
                base.Refresh();

            }
        }







        #region Transparency
        protected override void OnSizeChanged(EventArgs args)
        {
            this.Invalidate();
            base.OnSizeChanged(args);
        }


        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT
                return cp;
            }
        }


        protected void InvalidateEx()
        {
            if (Parent == null)
                return;

            Rectangle rc = new Rectangle(this.Location, this.Size);
            Parent.Invalidate(rc, true);
        }


        protected override void OnPaintBackground(PaintEventArgs prevent)
        {
            //do not allow the background to be painted
            this.BackColor = Color.Transparent;
        }
        #endregion

















        #region Painting Methods
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {

            Graphics gfx = e.Graphics;
            Rectangle rect = e.ClipRectangle;
            //todo: take into account orientation


            //clear the control area.
            //i've also tried to create a new image    gfx = Graphics.FromImage(new Bitmap(rect.Width, rect.Height));  // doesn't work
            Bitmap bmp = new Bitmap(rect.Width, rect.Height);
            Graphics g = Graphics.FromImage(bmp);
            g.FillRectangle(new SolidBrush(Color.Pink), rect);



            //draw the line
            Pen p = new Pen(Color.FromArgb(255, 0, 0, 0), 1);
            p.Width = 1;
            p.Color = GUIHelper.Utility.FromHexToRGB(255, "626262");
            g.DrawLine(p, new Point(0, rect.Height / 2), new Point(rect.Width, rect.Height / 2));
            p.Dispose();



            //draw the track icon           
            g.DrawImage(
                this._TrackerSliderIcon.getIcon,
                new Rectangle(
                            (Int32)this._TrackerSliderIcon.Size.X,
                            (Int32)((rect.Height / 2) - (this._TrackerSliderIcon.Size.Height / 2)),
                            (Int32)this._TrackerSliderIcon.Size.Width,
                            (Int32)this._TrackerSliderIcon.Size.Height
                )
            );


            g.Dispose();

            ImageAttributes attr = new ImageAttributes();
            attr.SetColorKey(Color.Pink, Color.Pink);
            Rectangle dstRect = new Rectangle(0, 0, bmp.Width, bmp.Height);

            gfx.Clear(Color.Pink);
            gfx.DrawImage(bmp, dstRect, 0, 0, bmp.Width, bmp.Height,
                GraphicsUnit.Pixel, attr);
       
        }
        #endregion


       
    }
}






http://msdn2.microsoft.com/en-us/library/ms172507.aspx#Mtps_DropDownFilterText
http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_20492791.html