Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. opacity problem

opacity problem

Scheduled Pinned Locked Moved C#
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Try
    wrote on last edited by
    #1

    Hi All, I am using C#. I have a empty Form. When i move mouse on the Form, i am displaying the x and y position of mouse using DrawString() method. Graphics grx = e.Graphics; string xy = "X: " + cursorPos.X.ToString() + "\nY: " + cursorPos.Y.ToString(); grx.DrawString(xy, font, brush, cursorPos.X, cursorPos.Y); The above code snippet is in Paint event. Hence the x and y values move along with cursor. My problem, When i change the opacity of Form from 100% to 10%, the Form becomes transparent. Even x and y values (displayed using DrawString) becomes transparent (faint). I want the x and y values to be displayed clearly even if Form is transparent. How can i achieve it? Thanks in advance.

    M 1 Reply Last reply
    0
    • T Try

      Hi All, I am using C#. I have a empty Form. When i move mouse on the Form, i am displaying the x and y position of mouse using DrawString() method. Graphics grx = e.Graphics; string xy = "X: " + cursorPos.X.ToString() + "\nY: " + cursorPos.Y.ToString(); grx.DrawString(xy, font, brush, cursorPos.X, cursorPos.Y); The above code snippet is in Paint event. Hence the x and y values move along with cursor. My problem, When i change the opacity of Form from 100% to 10%, the Form becomes transparent. Even x and y values (displayed using DrawString) becomes transparent (faint). I want the x and y values to be displayed clearly even if Form is transparent. How can i achieve it? Thanks in advance.

      M Offline
      M Offline
      musefan
      wrote on last edited by
      #2

      Hmmm not sure if will work but try the following... Set the backcolor of your form to a color not used for you text, the set the tranparencykey to match. then put a panel on your form with backcolor as Transparent. then do your paint code to the panels Paint Event. hopefully it will work EDIT: just tested and works fine, just need to set the FormBorderStyle to None

      Life goes very fast. Tomorrow, today is already yesterday.

      T 1 Reply Last reply
      0
      • M musefan

        Hmmm not sure if will work but try the following... Set the backcolor of your form to a color not used for you text, the set the tranparencykey to match. then put a panel on your form with backcolor as Transparent. then do your paint code to the panels Paint Event. hopefully it will work EDIT: just tested and works fine, just need to set the FormBorderStyle to None

        Life goes very fast. Tomorrow, today is already yesterday.

        T Offline
        T Offline
        Try
        wrote on last edited by
        #3

        Thank you very much for your help, but i am not getting the result. Will you please elaborate? Have you set panel dock to fill?

        M 1 Reply Last reply
        0
        • T Try

          Thank you very much for your help, but i am not getting the result. Will you please elaborate? Have you set panel dock to fill?

          M Offline
          M Offline
          musefan
          wrote on last edited by
          #4

          ok this is all i did... the form contains only one panel, simply drag and dropped to design, set

          Panel1.BackColor = Color.Transparent;

          and double clicked Paint event handler, thats all i did to the panel

          public Form1()
          {
          InitializeComponent();
          //i set these in design mode but have put here to show you the code
          this.BackColor = Color.Red;
          this.TransparencyKey = Color.Red;
          this.FormBorderStyle = FormBorderStyle.None;

          }

          void Panel1Paint(object sender, PaintEventArgs e)
          {
          e.Graphics.DrawString("SOME TEXT", Label.DefaultFont, Brushes.Blue, 0, 0);
          }

          when the form loads all i can see is "SOME TEXT" in blue on my screen

          Life goes very fast. Tomorrow, today is already yesterday.

          T 1 Reply Last reply
          0
          • M musefan

            ok this is all i did... the form contains only one panel, simply drag and dropped to design, set

            Panel1.BackColor = Color.Transparent;

            and double clicked Paint event handler, thats all i did to the panel

            public Form1()
            {
            InitializeComponent();
            //i set these in design mode but have put here to show you the code
            this.BackColor = Color.Red;
            this.TransparencyKey = Color.Red;
            this.FormBorderStyle = FormBorderStyle.None;

            }

            void Panel1Paint(object sender, PaintEventArgs e)
            {
            e.Graphics.DrawString("SOME TEXT", Label.DefaultFont, Brushes.Blue, 0, 0);
            }

            when the form loads all i can see is "SOME TEXT" in blue on my screen

            Life goes very fast. Tomorrow, today is already yesterday.

            T Offline
            T Offline
            Try
            wrote on last edited by
            #5

            Thank you. Thanks a lot for your time and support. I am grateful to you.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups