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. Capturing mouse movement while transparent

Capturing mouse movement while transparent

Scheduled Pinned Locked Moved C#
csharpgraphicsdockerquestion
3 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.
  • B Offline
    B Offline
    bennyrascal
    wrote on last edited by
    #1

    G'day Have a little program that captures mouse movements and displays the form and relative mouse location on labels on the form in real time. It also allows the form to be dragged while the mouse button is pressed. There is also a rich text box which has text in it. The form's transparency key and the rich text box colour are the same so that the rich text box is transparent. There are buttons which set the rich text box's enable property to either true or false. When the disable button is pressed, the enable property is set to false. This has the effect of allowing the mouse movement to be captured over the rich text box area. When the enable button is pressed, the enable property is set to true. Now, mouse movement is not captured in the rich text box area. Basically, things are working as I expect them to. Want I would like to do is to be able to drag the form while the rich text box is enabled or transparent. I know this can be done as there is a program called "DSCLOCK" which does it. It might be using a normal text box or a label. It doesn't matter to me. Just want a way to allow the area to be moved and still be transparent. Thought about trying to capture the mouse movements at a parent level (Windows). Thought that would let me see all mouse movement and then I could sort out which bits I wanted. Does anyone know how this can be done? Sorry about the size of this but it will be easier to see what i'm doing if you cut and paste this into a new C# project. benny ************************************************************ using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace RichTextBox { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private int mousePressedX, mousePressedY; private System.Windows.Forms.RichTextBox rTxt1; private System.Windows.Forms.Label lblMouseStatus; private System.Windows.Forms.Label lblMouseLocation; private System.Windows.Forms.Button btnEnable; private System.Windows.Forms.Button btnDisable; private System.Windows.Forms.Button btnExit; private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.Label lblFormLocation; private System.Windows.Forms.GroupBox groupBox2; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() {

    H 1 Reply Last reply
    0
    • B bennyrascal

      G'day Have a little program that captures mouse movements and displays the form and relative mouse location on labels on the form in real time. It also allows the form to be dragged while the mouse button is pressed. There is also a rich text box which has text in it. The form's transparency key and the rich text box colour are the same so that the rich text box is transparent. There are buttons which set the rich text box's enable property to either true or false. When the disable button is pressed, the enable property is set to false. This has the effect of allowing the mouse movement to be captured over the rich text box area. When the enable button is pressed, the enable property is set to true. Now, mouse movement is not captured in the rich text box area. Basically, things are working as I expect them to. Want I would like to do is to be able to drag the form while the rich text box is enabled or transparent. I know this can be done as there is a program called "DSCLOCK" which does it. It might be using a normal text box or a label. It doesn't matter to me. Just want a way to allow the area to be moved and still be transparent. Thought about trying to capture the mouse movements at a parent level (Windows). Thought that would let me see all mouse movement and then I could sort out which bits I wanted. Does anyone know how this can be done? Sorry about the size of this but it will be easier to see what i'm doing if you cut and paste this into a new C# project. benny ************************************************************ using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace RichTextBox { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private int mousePressedX, mousePressedY; private System.Windows.Forms.RichTextBox rTxt1; private System.Windows.Forms.Label lblMouseStatus; private System.Windows.Forms.Label lblMouseLocation; private System.Windows.Forms.Button btnEnable; private System.Windows.Forms.Button btnDisable; private System.Windows.Forms.Button btnExit; private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.Label lblFormLocation; private System.Windows.Forms.GroupBox groupBox2; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() {

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Take a look at the Control.Capture property. You could capture the mouse and receive notification messages while another control - or even another application, so make sure you use Control.PointToClient to convert the coordinates relative to your control - has the mouse over it. I don't know anything about DSCLOCK, but I'm guessing it uses system hooks, which is another way to do it, but should be a last resort - especially if this is just necessary in your application. That said, you can use an IMessageFilter which acts as an application hook, passing all messages that get posted to your message pump (queue) through it giving you a chance to process. See the documentation for this interface, as well as the Application.AddMessageFilter method document in the .NET Framework SDK.

      Microsoft MVP, Visual C# My Articles

      B 1 Reply Last reply
      0
      • H Heath Stewart

        Take a look at the Control.Capture property. You could capture the mouse and receive notification messages while another control - or even another application, so make sure you use Control.PointToClient to convert the coordinates relative to your control - has the mouse over it. I don't know anything about DSCLOCK, but I'm guessing it uses system hooks, which is another way to do it, but should be a last resort - especially if this is just necessary in your application. That said, you can use an IMessageFilter which acts as an application hook, passing all messages that get posted to your message pump (queue) through it giving you a chance to process. See the documentation for this interface, as well as the Application.AddMessageFilter method document in the .NET Framework SDK.

        Microsoft MVP, Visual C# My Articles

        B Offline
        B Offline
        bennyrascal
        wrote on last edited by
        #3

        Heath Thanks again. Your comments are sufficient for me to sort this out now. benny

        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