admin管理员组

文章数量:1206196

I'm trying to make a function that has the user drag the program around from a specific spot in the window. I have the drag function coded into the program, but I can't find a way to set where the drag should happen from in the window.

I'm fairly new to coding and I would apricate it if any answers could dumb it down a tad.

Right now I'm trying to make a panel transparent, but still able to interact with the mouse, but adding transparency just makes the panel unable to interact. The panel also cuts out the rest of my window, when I want the panels behind the transparent panel to be visible.

private bool _dragging = false;
private Point _start_point = new Point(0, 0);

private bool veiwSettings = false;

public Form1()
{
    InitializeComponent();
    this.BackColor = Color.LimeGreen;
    this.TransparencyKey = Color.LimeGreen;
    this.TopMost = true;

    panel1.BackColor = Color.FromArgb(0, 1, 1, 1);

    pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
    pictureBox1.Image = new Bitmap("EverythingElse\\Pictures\\space.png");

    groupBox1.Visible = false;
}

private int Count = 0;
List<string> paths = new List<string>
{
    "Ash.jfif","Bed.png","space.png"
};
private void button1_Click(object sender, EventArgs e)
{
    pictureBox1.Image = new Bitmap("EverythingElse\\Pictures\\" + paths[Count]);
    Count++;
    if (Count >= paths.Count) Count = 0;
}
private void Exit_Click(object sender, EventArgs e)
{
    Application.Exit();
}

private void panel1_MouseDown(object sender, MouseEventArgs e)
{
    _dragging = true;
    _start_point = new Point(e.X, e.Y);

}

private void panel1_MouseMove(object sender, MouseEventArgs e)
{
    if (_dragging)
    {
        Point p = PointToScreen(e.Location);
        Location = new Point(p.X - this._start_point.X, p.Y - this._start_point.Y);
    }
}

private void panel1_MouseUp(object sender, MouseEventArgs e)
{
    _dragging = false;
}

private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
        veiwSettings = !veiwSettings;
    }
    if (veiwSettings == true)
    {
        groupBox1.Visible = true;
    }
    else
    {
        groupBox1.Visible = false;
    }
}

Would it be easier to try to continue to make the panel transparent, or would something else work better?

本文标签: winformsHow to make a functioning transparent button in cStack Overflow