Click here to Skip to main content
15,920,688 members
Home / Discussions / C#
   

C#

 
GeneralRe: Services-like platform? Pin
NaNg1524126-Apr-11 21:34
NaNg1524126-Apr-11 21:34 
GeneralRe: Services-like platform? Pin
Justin Helsley27-Apr-11 21:29
Justin Helsley27-Apr-11 21:29 
QuestionFrequency-shifting Auditory Feedback Pin
mehdiattar26-Apr-11 9:51
mehdiattar26-Apr-11 9:51 
AnswerRe: Frequency-shifting Auditory Feedback Pin
Richard MacCutchan26-Apr-11 9:54
mveRichard MacCutchan26-Apr-11 9:54 
GeneralRe: Frequency-shifting Auditory Feedback Pin
AspDotNetDev26-Apr-11 12:59
protectorAspDotNetDev26-Apr-11 12:59 
GeneralRe: Frequency-shifting Auditory Feedback Pin
gavindon26-Apr-11 14:05
gavindon26-Apr-11 14:05 
AnswerRe: Frequency-shifting Auditory Feedback Pin
JP_Rocks26-Apr-11 23:33
JP_Rocks26-Apr-11 23:33 
Questionz-index problem with transparent controls Pin
nessy0026-Apr-11 3:14
nessy0026-Apr-11 3:14 
Hi,

I'm working on an end user card editor desktop aplication. The user can drag and drop controls (text, line, shape) from a toolbox to a design area.To create this controls I created my own controls that inherit from my BaseControl class that inherits from Control class. This controls can have a transparent background, and after googleing during days It works with this code.

[Designer(typeof(BaseControlDesigner))]
public abstract class BaseControl:Control
{
        public BaseControl()
        {                     
            this.DoubleBuffered = false;
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            SetStyle(ControlStyles.Opaque, true);
            this.BackColor = Color.Transparent;                            
        }}

        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle |= 0x20; //WS_EX_TRANSPARENT 
                return cp;
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Rectangle bounds = new Rectangle(0, 0, this.Width - 1, this.Height - 1);

            Color frmColor = this.Parent.BackColor;
            Brush bckColor;
            int alpha = 255;

            alpha = (this.Opacity * 255) / 100;
            

            if (this.drag)
            {
                Color dragBckColor;

                if (BackColor != Color.Transparent)
                {
                    int Rb = BackColor.R * alpha / 255 + frmColor.R * (255 - alpha) / 255;
                    int Gb = BackColor.G * alpha / 255 + frmColor.G * (255 - alpha) / 255;
                    int Bb = BackColor.B * alpha / 255 + frmColor.B * (255 - alpha) / 255;
                    dragBckColor = Color.FromArgb(Rb, Gb, Bb);
                }
                else dragBckColor = frmColor;

                alpha = 255;
                bckColor = new SolidBrush(Color.FromArgb(alpha, dragBckColor));
            }
            else
            {
                bckColor = new SolidBrush(Color.FromArgb(alpha, this.BackColor));
            }

            if (this.BackColor != Color.Transparent | drag)
            {
                g.FillRectangle(bckColor, bounds);
            }
            bckColor.Dispose();
            //base.OnPaint(e);
        }        
    }
}
    internal class BaseControlDesigner : ControlDesigner
    {
        private BaseControl myControl;

        protected override void OnMouseDragMove(int x, int y)
        {
            myControl = (BaseControl)(this.Control);
            myControl.drag = true;
            base.OnMouseDragMove(x, y);
        }

        protected override void OnMouseLeave()
        {
            myControl = (BaseControl)(this.Control);
            myControl.drag = false;
            base.OnMouseLeave();
        }
    }


That part works, controls can have a transparent background but there is another problem, I think with de z index.If I drag three controls, the last one is not on the top, it's the second one that is in the top and the Bring to Front, Send to Back commands does not work properly as well. It works with only two controls, but it doesn´t if I use more than two.

What can I do to get it work?

Thank you for your help.
Be happy!

AnswerRe: z-index problem with transparent controls Pin
Groulien27-Apr-11 0:21
Groulien27-Apr-11 0:21 
QuestionAsync sockets Pin
Haim Nachum26-Apr-11 2:41
Haim Nachum26-Apr-11 2:41 
AnswerRe: Async sockets Pin
David198726-Apr-11 3:19
David198726-Apr-11 3:19 
GeneralRe: Async sockets Pin
Haim Nachum26-Apr-11 5:51
Haim Nachum26-Apr-11 5:51 
GeneralRe: Async sockets Pin
David198726-Apr-11 6:09
David198726-Apr-11 6:09 
AnswerRe: Async sockets Pin
Rick Shaub26-Apr-11 5:49
Rick Shaub26-Apr-11 5:49 
QuestionExcel export problem Pin
vineesh v26-Apr-11 0:22
vineesh v26-Apr-11 0:22 
AnswerRe: Excel export problem Pin
Ravi Sant26-Apr-11 0:33
Ravi Sant26-Apr-11 0:33 
QuestionConverting Multipage Tiff files into PDF files Pin
meeram39525-Apr-11 20:54
meeram39525-Apr-11 20:54 
AnswerRe: Converting Multipage Tiff files into PDF files Pin
Kraeven25-Apr-11 21:43
Kraeven25-Apr-11 21:43 
GeneralRe: Converting Multipage Tiff files into PDF files Pin
meeram39525-Apr-11 22:54
meeram39525-Apr-11 22:54 
GeneralRe: Converting Multipage Tiff files into PDF files Pin
Kraeven25-Apr-11 23:03
Kraeven25-Apr-11 23:03 
QuestionHow to open image without show picturebox style Pin
parsnet4u25-Apr-11 20:52
parsnet4u25-Apr-11 20:52 
AnswerRe: How to open image without show picturebox style Pin
ambarishtv28-Apr-11 5:53
ambarishtv28-Apr-11 5:53 
QuestionHow to Pass the Value of Object Pin
Anubhava Dimri25-Apr-11 20:43
Anubhava Dimri25-Apr-11 20:43 
AnswerRe: How to Pass the Value of Object Pin
meeram39525-Apr-11 21:16
meeram39525-Apr-11 21:16 
AnswerRe: How to Pass the Value of Object Pin
Abhinav S25-Apr-11 21:19
Abhinav S25-Apr-11 21:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.