manual toolTip goes under the controls

Feb 4 2009 12:27 AM
hello everybody,
It is the first post of mine,
i am using the form of windows in c# and i want to have a rectange (something like toolTip) that is always available for the user
and every where mouse move the toolTip show him/her something useful , because i used the graphics object i draw the rectange (the tooltip) myself
but there is a problem that is other controls like buttons, text boxes and other things come over my tool tip (my tooltip goes under the controls) i don't know what should i do for this problem
and i even don't know the process of drawing controls and graphics ( i mean i don't know the sequence of drawing )
if someone know anything about it or have any resource at web or ebook or anything else
i would appreciate to know and i thank you in advance
thank you everybody , here is the code where i paint my tooltip:


protected override void OnPaint(PaintEventArgs e)
        {
               
            //
            //BufferedGraphicsContext myContext;
            //myContext = BufferedGraphicsManager.Current;
            //BufferedGraphics myGraphics = myContext.Allocate(this.CreateGraphics(), this.DisplayRectangle);

            //base.OnPaint(e);
            //            myContext.
            Graphics graphicsObject = e.Graphics; //get graphics
            Color myColor = new Color();
            myColor = Color.FromArgb(toolTipTransparency, toolTipRed, toolTipGreen, toolTipBlue);

            //myColor.A = 100;
            //myColor.B = 255;
            //myColor.R = 255;
            //myColor.G = 0;
            SolidBrush myBrush = new SolidBrush(myColor);
            //graphicsObject.FillRectangle(myBrush, MousePosition.X, MousePosition.Y, 50, 50);
            graphicsObject.FillRectangle(myBrush, MousePosition.X, MousePosition.Y, 50, 50);
            myBrush.Color = Color.FromArgb(255, Color.Red);
            Font myFont = new Font(this.Font.FontFamily, 8);//this.Font.Clone();
            graphicsObject.DrawString(MousePosition.X.ToString() + ", " + MousePosition.Y.ToString(), myFont, myBrush, new PointF(MousePosition.X, MousePosition.Y));
            base.OnPaint(e);

        }
===============================================================================
if someone needs whole program here is the whole program :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.IO;
using System.Reflection;
using System.Diagnostics;

namespace firstCSharp
{
   
    public partial class Form1 : Form
    {
        int pictureTransparency = 0;
        int toolTipTransparency;
        int toolTipRed, toolTipGreen, toolTipBlue;
        Bitmap myBitmap;
        //ArrayList pics; //ArrayList needs System.Collections
        public Form1()
        {
            myBitmap = new Bitmap(global::firstCSharp.Properties.Resources.table);
            pictureTransparency = 100;
            toolTipRed = 0;
            toolTipGreen = 255;
            toolTipBlue = 200;
            toolTipTransparency = 100;
           
            InitializeComponent();
            //pics = new ArrayList();
            //this.Size = new Size(1204, 768);
            //here i get the resolution of the current settings for desktop and then adjust the form
            //to be with the size of the screen
            int deskHeight = Screen.PrimaryScreen.Bounds.Height;

            int deskWidth = Screen.PrimaryScreen.Bounds.Width;

            this.Size = new Size(deskWidth, deskHeight);
            // set the size of the frame with the current settings of desktop resolution
            tablePictureBox.BackgroundImage = global::firstCSharp.Properties.Resources.body;
           
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //myTimer.Stop();
         
            trackBarPictureTransparency.Value = pictureTransparency;
            this.DoubleBuffered = true;
            trackBar1.Value = toolTipTransparency;
            trackBarR.Value = toolTipRed;
            trackBarG.Value = toolTipGreen;
            trackBarB.Value = toolTipBlue;
            //this.Size =
           
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 mySecondForm = new Form2();
            mySecondForm.Show();
          
        }

        private void button1_MouseUp(object sender, MouseEventArgs e)
        {
           
        }

        private void button1_MouseMove(object sender, MouseEventArgs e)
        {
            this.button1.Image = global::firstCSharp.Properties.Resources._2t_copy;
            Invalidate();
        }

        private void button1_MouseLeave(object sender, EventArgs e)
        {
            this.button1.Image = global::firstCSharp.Properties.Resources._2_copy;
        }

        private void toolTip1_Popup(object sender, PopupEventArgs e)
        {
           
        }

        private void button2_MouseLeave(object sender, EventArgs e)
        {
            button2.Image = global::firstCSharp.Properties.Resources._1;
        }

        private void button2_MouseMove(object sender, MouseEventArgs e)
        {
            button2.Image = global::firstCSharp.Properties.Resources._1t;
            Invalidate();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string myString;
            myString = textBox1.Text;
            if (myString == "")
                myString = "http://www.yahoo.com";
           
           
            System.Uri  myURi = new Uri(myString,System.UriKind.Absolute);
            webBrowser1.Url = myURi;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
               
            //
            //BufferedGraphicsContext myContext;
            //myContext = BufferedGraphicsManager.Current;
            //BufferedGraphics myGraphics = myContext.Allocate(this.CreateGraphics(), this.DisplayRectangle);

            //base.OnPaint(e);
            //            myContext.
            Graphics graphicsObject = e.Graphics; //get graphics
            Color myColor = new Color();
            myColor = Color.FromArgb(toolTipTransparency, toolTipRed, toolTipGreen, toolTipBlue);

            //myColor.A = 100;
            //myColor.B = 255;
            //myColor.R = 255;
            //myColor.G = 0;
            SolidBrush myBrush = new SolidBrush(myColor);
            //graphicsObject.FillRectangle(myBrush, MousePosition.X, MousePosition.Y, 50, 50);
            graphicsObject.FillRectangle(myBrush, MousePosition.X, MousePosition.Y, 50, 50);
            myBrush.Color = Color.FromArgb(255, Color.Red);
            Font myFont = new Font(this.Font.FontFamily, 8);//this.Font.Clone();
            graphicsObject.DrawString(MousePosition.X.ToString() + ", " + MousePosition.Y.ToString(), myFont, myBrush, new PointF(MousePosition.X, MousePosition.Y));
            base.OnPaint(e);

        }
        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            //PaintEventArgs ee = new PaintEventArgs(this.gra);
            //this.OnPaint() //trigger the onPaint event
            Rectangle myRect = new Rectangle(MousePosition.X - 50, MousePosition.Y - 50 , 90, 90);
            Invalidate();//refresh the form
        }

        private void Form1_Validated(object sender, EventArgs e)
        {
           
        }

        private void Form1_Validating(object sender, CancelEventArgs e)
        {
           
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
           

        }

        private void textBox1_MouseMove(object sender, MouseEventArgs e)
        {
            Invalidate();
        }

        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            toolTipTransparency = trackBar1.Value;

        }

        private void trackBarR_Scroll(object sender, EventArgs e)
        {
            toolTipRed = trackBarR.Value;
        }

        private void trackBarG_Scroll(object sender, EventArgs e)
        {
            toolTipGreen = trackBarG.Value;
        }

        private void trackBarB_Scroll(object sender, EventArgs e)
        {
            toolTipBlue = trackBarB.Value;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            colorDialog1.ShowDialog();
            toolTipRed = colorDialog1.Color.R;
            toolTipGreen = colorDialog1.Color.G;
            toolTipBlue = colorDialog1.Color.B;
        }

        private void colorDialog1_HelpRequest(object sender, EventArgs e)
        {

        }

        private void trackBarPictureTransparency_Scroll(object sender, EventArgs e)
        {
           
            //tablePictureBox.
        }
        public static bool a = false;
        private void trackBarPictureTransparency_MouseUp(object sender, MouseEventArgs e)
        {
           
            pictureTransparency = trackBarPictureTransparency.Value;
            Color myColor = new Color();
           
            //myTimer.Start();

            clockLabel.Text = clockLabel.Text.ToString() + "From Now: " + DateTime.Now.Second.ToString() + ":" + DateTime.Now.Millisecond.ToString();
            for (int i = 0; i < myBitmap.Width; i++)
                for (int j = 0; j < myBitmap.Height; j++)
                {
                   
                    myColor = myBitmap.GetPixel(i, j);
                    int r = myColor.R;
                    int g = myColor.G;
                    int b = myColor.B;
                    myColor = Color.FromArgb(pictureTransparency, r, g, b);
                    myBitmap.SetPixel(i, j, myColor);
                    Image myImage;
                   
                }
            //if(a)
            //    MessageBox.Show("Here", "before loading");
            clockLabel.Text = clockLabel.Text.ToString() + "  till Now" + DateTime.Now.Second.ToString() + ":" + DateTime.Now.Millisecond.ToString();
            //myTimer.Stop();
            a = !a;
            //Color myColor = Color.FromArgb(pictureTransparency, Color.Gold);
            tablePictureBox.WaitOnLoad = false;
            //myBitmap.MakeTransparent();
            tablePictureBox.Image = myBitmap;
           


           
        }
        public static long  myClock = 0;
        private void myTimer_Tick(object sender, EventArgs e)
        {
            //myTimer.
            myClock++;
            //clockLabel.Text = clockLabel.Text.ToString() + "#: " + myClock.ToString();
            //MessageBox.Show(myClock.ToString(), "nothing");
        }
    }
}