C# Floating Form

Asked

Viewed 93 times

1

Good, I’m making a program where I need a floating form that accompanies the mouse cursor while it’s inside a button, so far I have this:

private void portaSwitchUpLink_MouseEnter(object sender, EventArgs e, string idPorta)
    {
        DataSet ds = _db.consulta("portaSwitchUpLink", "select s.id from equipamentos_rede.switchs_switchs ss inner join equipamentos_rede.portas_switch ps on ss.final_porta_id = ps.id inner join equipamentos_rede.switchs s on ps.switchs_id=s.id where ss.inicial_porta_id='" + idPorta + "' and ss.eliminado!=true");
        DataTable dt = ds.Tables[0];
        string idSwitch = dt.Rows[0][0].ToString();
        try
        {
            frmSwitchs = new desenhaSwitchs(_db, idSwitch,idPorta);
            frmSwitchs.FormBorderStyle = FormBorderStyle.None;
            frmSwitchs.Visible = true;
        }
        catch (Exception){}
    }

    private void portaSwitchUpLink_MouseMove(object sender, MouseEventArgs e)
    {
        if (frmSwitchs != null)
            if (frmSwitchs.Visible)
                frmSwitchs.Location = new Point(Cursor.Position.X + 1, Cursor.Position.Y + 1);
    }

    private void portaSwitchUpLink_MouseLeave(object sender, EventArgs e)
    {
        if (frmSwitchs != null)
            frmSwitchs.Visible = false;
    }

However, when I walk to the bottom right corner, the cursor enters the form and conflicts, I have thought about changing the position of the form, but it would not look so good. Someone has an idea?

1 answer

0


I decided by adding 10 pixels to the mouse position:

private void portaSwitchUpLink_MouseEnter(object sender, EventArgs e, string idPorta)
    {
        DataSet ds = _db.consulta("portaSwitchUpLink", "select s.id from equipamentos_rede.switchs_switchs ss inner join equipamentos_rede.portas_switch ps on ss.final_porta_id = ps.id inner join equipamentos_rede.switchs s on ps.switchs_id=s.id where ss.inicial_porta_id='" + idPorta + "' and ss.eliminado!=true");
        DataTable dt = ds.Tables[0];
        string idSwitch = dt.Rows[0][0].ToString();
        try
        {
            frmSwitchs = new desenhaSwitchs(_db, idSwitch,idPorta);
            frmSwitchs.FormBorderStyle = FormBorderStyle.None;
            frmSwitchs.Visible = true;
        }
        catch (Exception){}
    }

    private void portaSwitchUpLink_MouseMove(object sender, MouseEventArgs e)
    {
        if (frmSwitchs != null)
            if (frmSwitchs.Visible)
                frmSwitchs.Location = new Point(Cursor.Position.X + 1, Cursor.Position.Y + 1);
    }

    private void portaSwitchUpLink_MouseLeave(object sender, EventArgs e)
    {
        if (frmSwitchs != null)
            frmSwitchs.Visible = false;
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.