-2

I'm trying to create a Red Dot in the middle of the screen for shooting games. but I have a problem. the Form steals the click and now I can't event shoot! so is there any way to make the Form doesn't steal the click? here is what I'm trying to do.

static Form RedDot;
static void Main()
{
    var width=Screen.PrimaryScreen.Bounds.Width;
    var Height = Screen.PrimaryScreen.Bounds.Height;
    RedDot = new Form();
    RedDot.AutoSize = false;
    RedDot.BackColor = Color.Red;
    RedDot.FormBorderStyle = FormBorderStyle.None;
    RedDot.ShowInTaskbar = false;
    RedDot.Size = new Size(3,3);
    RedDot.Location = new Point(width/2, Height/2);
    RedDot.TopMost = true;
    RedDot.Shown += new EventHandler(RedDot_Shown);
    Application.EnableVisualStyles();
    Application .Run(RedDot);
}
static void RedDot_Shown(object sender, EventArgs e)
{
    RedDot.Size = new Size(3,3);
}
urmat abdykerimov
  • 427
  • 1
  • 7
  • 17
Osama Adel
  • 176
  • 1
  • 10
  • If drawing an ellipse (or a rectangle) - instead of a closed shape - on your Form may do, you can set `BackColor = Color.Magenta; TransparencyKey = BackColor;`. Draw the shape in the Paint event (the rectangle is `var rect = new Rectangle(0, 0, ClientSize.Width - 1, ClientSize.Height - 1);`). You can *shoot* through the shape. -- Otherwise, you need a transparent Per-Pixel-Alpha layered Form or a DirectX overlay. Note that `Application.EnableVisualStyles();` must be called before you create any Form (in case you need it, it doesn't appear you do, here). – Jimi Jul 21 '21 at 22:48
  • I did what you said but I still have the same problem. the transparent part is clickable but the red dot that i draw still steals the click and I can't shoot – Osama Adel Jul 21 '21 at 23:05
  • You can click through a rectangle or ellipse if you only draw the border, not a filled shaped (i.e., use `DrawRectangle()`, not `FillRectangle()`). The Pen color can be anything except Magenta. – Jimi Jul 21 '21 at 23:12
  • it seams that it worked 80% . know I can shoot but it some times does not shoot when I press on the borders of the Rectangle that I draw – Osama Adel Jul 21 '21 at 23:35
  • 1
    Of course, the border is *solid*. -- If you don't want to use a per-pixel-alpha Form (like this one: [Windows Form Transparent Background Image](https://stackoverflow.com/a/33531201/7444103) - add `WS_EX_TRANSPARENT` to the styles, the Form becomes *untouchable*) or a DirectX overlay (like this: [GameOverlay.Net - GitHub](https://github.com/michel-pi/GameOverlay.Net)), you could draw direclly on the DC of a screen, using a timer (since you have to redraw it constantly). See the last paragraph [here](https://stackoverflow.com/a/53026765/7444103). – Jimi Jul 21 '21 at 23:48

1 Answers1

0

You can assign an event handler to RedDot form for clicking to call firing logic. Let's say you have click event on main form.

static void Form_Click(object sender, EventArgs e)
{
     // some firing stuff
}

Move the firing logic into a new method.

static void Firing(long x, long y)
{
     // some firing stuff
}
static void Form_Click(object sender, EventArgs e)
{
     Firing(e.somethingX,e.somethingY);
}

So now you can create click event for RedDot form and call Firing method.

static void Main()
{
    //...
    RedDot.Shown += new EventHandler(RedDot_Shown);
    RedDot.Click += RedDot_Click;
    //...
}
static void RedDot_Click(object sender, EventArgs e)
{
     Firing(e.somethingX,e.somethingY);
}
kordiseps
  • 391
  • 3
  • 12